akhauriyash/Code-Regression huggingface dataset:
// SeeAlso: https://atcoder.jp/contests/abc118/tasks/abc118_c

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll N;
set<ll> A;


ll dfs(set<ll> a) {
    auto minimum = *a.begin();
    if (a.size()==1) {
        return minimum;
    }  
    set<ll> b;
    b.insert(minimum);
    for(auto it = a.begin(); it != a.end();it++) {
        ll ap = *it%minimum;
        if (ap>0) {
            b.insert(ap);
        }
    }
    return dfs(b);
}

int main() {
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        A.insert(a);
    }

    ll ans =  dfs(A);
    print(ans);
    return 0;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,c=0,a,b;
    cin>>n>>a>>b;
    for(i=a; i<=b; i++)
    {
        if(i%n==0)
        {
            c=1;
           // cout<<i<<endl;
            break;
        }

    }
    if(c==1)
        cout<<"OK"<<endl;
    else
cout<<"NG"<<endl;

}


Measured memory_bytes: 3624
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def f(a,b):
    if a == 0:
        return 0,1
    if b == 0:
        return 1,0
    f = math.gcd(a,b)
    return a//f, b//f

N = I()
A,B = LIR(N,2)

beki = [1]*(N+1)
for i in range(1,N+1):
    beki[i] = beki[i-1]*2
    beki[i] %= mod


dplus = defaultdict(int)
dplus2 = defaultdict(int)
dminus = defaultdict(int)
dminus2 = defaultdict(int)
dzeros = defaultdict(int)

zero = 0
both_zero = 0
for i in range(N):
    if A[i] == 0 and B[i] == 0:
        both_zero += 1
    elif A[i] == 0 or B[i] == 0:
        a,b = f(abs(A[i]),abs(B[i]))
        dzeros[(a,b)] += 1
    else:
        if A[i]*B[i] > 0:
            a,b = f(abs(A[i]),abs(B[i]))
            dplus[(a,b)] += 1
            dplus2[(a,b)] += 1
        else:
            a,b = f(abs(A[i]),abs(B[i]))
            dminus[(b,a)] += 1
            dminus2[(b,a)] += 1

ans = 1
count = 0

for k in dplus.keys():
    if dminus[k]:
        temp = beki[dplus[k]] + beki[dminus[k]] - 1
        ans *= temp
        ans %= mod
    else:
        count += dplus[k]

for k in dminus2.keys():
    if dplus2[k]:
        continue
    else:
        count += dminus2[k]

temp = beki[dzeros[(0,1)]] + beki[dzeros[(1,0)]] -1
ans *= temp
ans %= mod

ans *= beki[count]
ans -= 1
ans += both_zero
ans %= mod
print(ans)

Measured memory_bytes: 209860
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] x = new int[n + 2];
			for (int i = 1; i <= n; i++) {
				x[i] = in.nextInt();
			}

			long sum = 0;
			for (int i = 0; i + 1 < x.length; i++) {
				sum += Math.abs(x[i] - x[i + 1]);
			}

			for (int i = 1; i <= n; i++) {
				long cur = sum;
				cur -= Math.abs(x[i] - x[i + 1]);
				cur -= Math.abs(x[i] - x[i - 1]);
				cur += Math.abs(x[i + 1] - x[i - 1]);
				out.println(cur);
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 46464
#include <stdio.h>

void bomb(char surface[8][9], int x, int y) {
	int start, end, i;

	surface[y][x] = '0';

	start = (x-3 > 0) ? (x-3) : 0;
	end = (x+4 < 8) ? (x+4) : 8;
	for (i = start; i < end; i++) {
		if (surface[y][i] == '1')
			bomb(surface, i, y);
	}

	start = (y-3 > 0) ? (y-3) : 0;
	end = (y+4 < 8) ? (y+4) : 8;
	for (i = start; i < end; i++) {
		if (surface[i][x] == '1')
			bomb(surface, x, i);
	}
}

int main(void) {
	int N, n, i, x, y;
	char surface[8][9];

	scanf(" %d ", &N);
	for (n = 1; n <= N; n++) {
		for (i = 0; i < 8; i++) {
			scanf(" %s ", surface[i]);
		}
		scanf(" %d %d ", &x, &y);

		bomb(surface, x-1, y-1);

		printf("Data %d:\n", n);
		for (i = 0; i < 8; i++) {
			puts(surface[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include<stdio.h>
int main(){
  
  int i,j,k,v,N;
  int a[1000];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<N;i++){
    if(i==N-1){
      printf("%d\n",a[i]);
    }
    else{
      printf("%d ",a[i]);
    }
  }
  for(i=1;i<N;i++){
    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
      a[j+1]=v;
    }
    for(k=0;k<N;k++){    
      if(k==N-1){
	printf("%d\n",a[k]);
      }
      else{
	printf("%d ",a[k]);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2140
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll n,x,i,j;
    cin>>n;
    set<ll>st;
    for( i=0; i<n; i++)
    {
        cin>>x;
        st.insert(x);
    }
    if(st.size()==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}





Measured memory_bytes: 12964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

string s;
int cA,cX;
bool flg;
int main() {
    cin >> s;
    int n = s.size();

    ll ans = 0;
    int i=0;
    while(i<n) {
        if(s[i]=='A') cA++;
        else if (i+1<n && s[i]=='B' && s[i+1]=='C') {
            i++;
            ans += cA;
        } 
        else cA = 0;
        i++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >>h[i];

    int count=1;
    int high=h[0];
    for(int i=1;i<n;i++){
        if(h[i]>=h[i-1] && h[i]>=high){
            count++;
            high=h[i];
        }
    }

    cout << count;



}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int  main(){
	int n;
	cin>>n;
	long long ans[2]={1,1};
	for(int i=0;i<n;i++){
		long long t,a;
		cin>>t>>a;
		long long tmp;
		tmp=(ans[0]/t+((ans[0]%t)!=0));
		tmp=max(tmp,ans[1]/a+((ans[1]%a)!=0));
		ans[0]=tmp*t;
		ans[1]=tmp*a;
	}
	cout<<ans[0]+ans[1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    char c;

    cin >> c;

    switch (c) {
        case 'a':
            cout << "vowel" << endl;
            break;
        case 'e':
            cout << "vowel" << endl;
            break;
        case 'i':
            cout << "vowel" << endl;
            break;
        case 'o':
            cout << "vowel" << endl;
            break;
        case 'u':
            cout << "vowel" << endl;
            break;
        default:
            cout << "consonant" << endl;
            break;
    }

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

def main():
    a, b = map(int, input().split())
    ans = 'Positive'

    if a <= 0 and b >= 0:
        ans = 'Zero'
    elif b < 0:
        if (b - a) % 2 == 0:
            ans = 'Negative'

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9068
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K;
string s;
int main() {
	cin >> s;
	REP(i, SZ(s)) {
		REP(j, SZ(s)) {
			if (i == j) continue;
			if (s[i] == s[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;
}


Measured memory_bytes: 3580
import time

def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K*x)%(10**9+7)
        x = (x*x)%(10**9+7)
        n //= 2

    return (K*x)%(10**9+7)

L=input()
N=len(L)


bit=[]
for i in range(0,N):
    if L[N-1-i]=='1':
        bit.append(i+1)

dp=[0 for i in range(0,100001)]

m=bit[0]
if m!=1:
    dp[m]=(2+3**(m-1))%(10**9+7)
else:
    dp[m]=3
time0=time.time()
for i in range(1,len(bit)):
    s=bit[i]
    t=bit[i-1]
    dp[s]=(2*dp[t]+pow_k(3,s-1))
time1=time.time()
print(dp[N]%(10**9+7))

Measured memory_bytes: 660464
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    ll ans = (ll)(n-2)*(n-2);
    int nx = n-1;
    int ny = n-1;
    vector<int> ix(n-1, -1);
    vector<int> iy(n-1, -1);
    rep(qi, q) {
        int id, x;
        cin >> id >> x;
        x--;
        if (id==1) {
            if (x<ny) {
                for (int i=x; i<ny; i++) {
                    iy[i] = nx;
                }
            }
            ans -= iy[x] - 1;
            chmin(ny, x);
        }
        if (id==2) {
            if (x<nx) {
                for (int i=x; i<nx; i++) {
                    ix[i] = ny;
                }
            }
            ans -= ix[x] - 1;
            chmin(nx, x);
        }
    }
    
    
    pr(ans);
    return 0;
}


Measured memory_bytes: 4744
#pragma optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1e18)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=3005;
ld dp[N][N];
ld p[N];
ll n;

ld fun(ll pos,ll cnt)
{
    if(pos==n){
        if(cnt>n/2)return 1;
        return 0;
    }
    
    if(dp[pos][cnt]!=-1)return dp[pos][cnt];
    return dp[pos][cnt]=fun(pos+1,cnt+1)*p[pos]+fun(pos+1,cnt)*(1-p[pos]);
}

void solve()
{
   cin>>n;
   rep(i,n)cin>>p[i];
   rep(i,N)
   {
       rep(j,N)
       {
           dp[i][j]=-1;
       }
   }
   ld x=fun(0,0);
   cout<<fixed<<sp(10)<<x<<"\n";
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


Measured memory_bytes: 145060
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    while(true){
        int n; cin >> n; if(n ==0 ) break;
        int sum = 0; int cou = 0;
        vi v(n,INF);
        rep(i,n){cin >> v[i];}

        sort(v.begin(),v.begin()+n);
        v.erase(v.begin());
        v.erase(v.end()-1);
        rep(i,n-2){
            sum+=v[i]; cou++;
        }
        cout << sum /cou << endl;
    }
}

Measured memory_bytes: 3032
/**
 *      ABC 79 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-03 02:48:47
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int D = N % 10; N /= 10;
    int C = N % 10; N /= 10;
    int B = N % 10; N /= 10;
    int A = N % 10;

    if (A + B + C + D == 7){
        cout << A << '+' << B << '+' << C << '+' << D << '=' << 7 << endl;
    }
    else if (A + B + C - D == 7){
        cout << A << '+' << B << '+' << C << '-' << D << '=' << 7 << endl;
    }
    else if (A + B - C + D == 7){
        cout << A << '+' << B << '-' << C << '+' << D << '=' << 7 << endl;
    }
    else if (A - B + C + D == 7){
        cout << A << '-' << B << '+' << C << '+' << D << '=' << 7 << endl;
    }
    else if (A + B - C - D == 7){
        cout << A << '+' << B << '-' << C << '-' << D << '=' << 7 << endl;
    }
    else if (A - B + C - D == 7){
        cout << A << '-' << B << '+' << C << '-' << D << '=' << 7 << endl;
    }
    else if (A - B - C + D == 7){
        cout << A << '-' << B << '-' << C << '+' << D << '=' << 7 << endl;
    }
    else if (A - B - C - D == 7){
        cout << A << '-' << B << '-' << C << '-' << D << '=' << 7 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    res = 0
    for i in range(len(S) // 2):
      if S[i] != S[-(i+1)]:
        res += 1
    print(res)


main()


Measured memory_bytes: 3568
import bisect

def main():
    s = input()
    t = input()
    s_set = set(list(s))
    s_dict = {}
    s_len = len(s)
    t_list = list(t)
    t_set = set(t_list)
    c = -1
    ans = []
    ans_append = ans.append
    for i in s_set:
        s_dict[i] = []
    for i in range(s_len):
        s_dict[s[i]].append(i)
    if len(t_set) == len(t_set & s_set):
        for i in t_list:
            idxs = s_dict[i]
            if idxs[-1] <= c:
                c = idxs[0]
                ans_append(c)
            else:
                c = idxs[bisect.bisect(idxs,c)]
                ans_append(c)
        count = 0
        for i in range(len(ans)-1):
            if ans[i] >= ans[i+1]:
                count += 1
        print(s_len*count + ans[-1] + 1)
    else:
        print(-1)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9444
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, Y = list(map(str, sys.stdin.buffer.readline().decode().split()))
    print('>' if X>Y else '=' if X==Y else '<')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>

using namespace std;

int n, k;
vector<int> x, y, c;

double distance(double px, double py) {
  vector<double> dis(n);
  for (int i = 0; i < n; ++i) {
    dis[i] = c[i] * hypot(px - x[i], py - y[i]);
  }
  nth_element(dis.begin(), dis.begin() + k - 1, dis.end());
  return dis[k - 1];
}

double distance_lb(double px, double py, double r) {
  vector<double> dis(n);
  for (int i = 0; i < n; ++i) {
    dis[i] = c[i] * hypot(max(abs(px - x[i]) - r, 0.0), max(abs(py - y[i]) - r, 0.0));
  }
  nth_element(dis.begin(), dis.begin() + k - 1, dis.end());
  return dis[k - 1];
}

int main() {
  cin >> n >> k;
  x.resize(n);
  y.resize(n);
  c.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> c[i];
  }
  queue<tuple<double, double, double>> que;
  double res = 1e9;
  que.emplace(0, 0, 1000);
  while (!que.empty()) {
    double px, py, r;
    tie(px, py, r) = que.front();
    que.pop();
    double lb = distance_lb(px, py, r);
    if (res - lb > 5e-7 * max(1.0, lb)) {
      res = min(res, distance(px, py));
      for (double dx : {-0.5, 0.5}) {
        for (double dy : {-0.5, 0.5}) {
          que.emplace(px + dx * r, py + dy * r, r / 2);
        }
      }
    }
  }
  cout << fixed << setprecision(15) << res << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)


int main() {
  ios::sync_with_stdio(false);  cin.tie(nullptr);
  int n; string s;
  cin >> n >> s;
  vector<bool> cor(n, false);

  bool flag = true;
  while(flag){
    flag = false;
    rep(i, n){
      //cout << "cor[" << i << "]:" << cor[i] << ln;
      if(cor[i]) continue;
      if(s[i] == '('){
        for(int j=i+1; j<n; j++){
          if(cor[j]) continue;
          if(s[j] == ')'){
            //cout << "@i:" << i << " j:" << j << ln;
            cor[i] = true; cor[j] = true; flag = true;
            break;
          }
        }
      } else{
        for(int j=i-1; j>=0; j--){
          if(cor[j]) continue;
          if(s[j] == '('){
            cor[i] = true; cor[j] = true; flag = true;
            break;
          }
        }
      }
    }
  }

  int left = 0, right = 0;
  rep(i, n){
    if(!cor[i]){
      if(s[i] == '(') right++;
      else left++;
    }
  }
  rep(i, left) cout << '(';
  cout << s;
  rep(i, right) cout << ')';
  cout << ln;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(H==0 && W==0) break;
		for(int i = 1;i <= H;i++){
			for(int j = 1;j <= W;j++){
				if(i==1||i==H||j==1||j==W){
					System.out.print("#");
				}else{
					System.out.print(".");
				}
			}
			System.out.println();
		}
		System.out.println();
		}
	}
}

Measured memory_bytes: 34508
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    vll a(2), b(2);
    cin >> a[0] >> a[1] >> b[0] >> b[1];
    ll ans = a[0] * b[0];
    if(a[0] <= 0 && a[1] >= 0) a.push_back(0);
    if(b[0] <= 0 && b[1] >= 0) b.push_back(0);
    for(auto i : a) for(auto j : b) chmax(ans, i * j);
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3652
#include <iostream>

int main()
{
	int W, a, b;
	std::cin >> W >> a >> b;

	int A, B;
	A = std::min( a, b );
	B = std::max( a, b );
	
	std::cout << std::max( B - ( A + W ), 0 ) << std::endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
    # 入力
    st = input()

    # if len(st) < 4:
    #     print(0)
    #     return

    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく
    mod_res_dic = {0: [0]}
    tmp_mod_val = 0
    r_st = ''.join(list(reversed(st)))
    cnt = 0
    for i in range(len(r_st)):
        target_st = r_st[i:i+1]
        # mod_res = ((10 ** i) * int(target_st) + tmp_mod_val) % 2019
        tmp_mod_val += int(target_st)*pow(10, i, 2019)
        tmp_mod_val %= 2019
        ls = mod_res_dic.setdefault(tmp_mod_val, [])
        ls.append(i-1)
        if len(ls) > 1:
            cnt += len(ls)-1
        # tmp_mod_val = mod_res

    # print(mod_res_dic)
    # modが同じペアのものについて、iからj文字目までを2019で割り切れるので、その組み合わせを計算
    # cnt = 0
    # for v in mod_res_dic.values():
    #     comb = len(v)
    #     if comb < 2:
    #         continue
    #     cnt += (comb * (comb - 1)) / 2

    print(int(cnt))


main()


Measured memory_bytes: 17852
#define d for(x=0;x<N;x++){for(y=0;y<N;y++
c,m[10][10],x,N;main(y){for(;scanf("%d",&N),N;){d)m[x][y]=(x+y)*(x-~y)/2-~(x+y&1?x:y);}printf("Case %d:\n",++c);d)printf("%3d",x+y<N?m[x][y]:N*N+1-m[N+~x][N+~y]);puts("");}}div(0);}

Measured memory_bytes: 620
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main() {
     string str;
     int q;
     cin >> str >> q;
     for (int i = 0; i < q; i++) {
         string cmd, repStr;
         int from, to;
         cin >> cmd >> from >> to;

         if (cmd == "print") {
             cout << str.substr(from, to - from + 1) << endl;
         }
         if (cmd == "replace") {
             cin >> repStr;
             str.replace(from, to - from + 1, repStr); 
         }
         if (cmd == "reverse") {
             string reverseStr = "";;
             for (int j = from; j <= to; j++) {
                reverseStr.insert(0, str.substr(j, 1));
             }
             str.replace(from, to - from + 1, reverseStr); 
         }
     }
}

Measured memory_bytes: 1236
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1010000
ll MOD=1e9+7;
vector<vec> G;
int g[1010][1010];
vec visited;
vec ans;
bool dfs(int x,int s,int t){
    if(x==s&&t)return 1;
    if(visited[x]){
        return 0;
    }
    visited[x]=1;
    for(auto e:G[x]){
        if(dfs(e,s,1)){
            ans.pb(x);
            return 1;
        }
    }
    return 0;
}
int main(){
    int n=in();
    vector<int> a;
    vec ans(n+1);
    rep(i,n){
        a.pb(in());
        ans[a[i]]=i+1;
    }
    rep2(i,1,n){
        cout<<ans[i]<<" ";
    }
    
}

Measured memory_bytes: 1784
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String c1=sc.next();
    String c2=sc.next();
    char ca[]=new char[3];
    char cb[]=new char[3];
    for (int i=0;i<3;i++) {
      ca[i]=c1.charAt(i);
      cb[i]=c2.charAt(i);
    }

    if (ca[0]==cb[2]&&ca[1]==cb[1]&&ca[2]==cb[0]) {
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

ll n, m, v, p;
vector<ll> a;

bool check(int pos){
	vector<ll> b;
	const ll val = a[pos];

	rep(i, n) {
		if(i == pos) continue;
		b.push_back(a[i]);
	}

	const ll thr = val + m;
	ll over = 0LL;

	rep(i, n - 1) {
		if(b[i] > thr) {
			over++;
		}
	}
	
	ll total = 1LL * m * (v - 1);
	rep(i, n - 1) {
		if(i < p - 1) {
			total -= m;
		} else {
			total -= max(0LL, min(val + m - b[i], m));
		}
	}

	return (over <= p - 1) and (total <= 0);
}

int main(void){
	cin >> n >> m >> v >> p;

	rep(i, n) {
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	sort(rbegin(a), rend(a));

	int low = 0, high = n;

	while(high - low > 1) {
		const int mid = (low + high) / 2;
		if(check(mid))
			low = mid;
		else
			high = mid;
	}
	
	cout << high << endl;
	return 0;
}

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

int main(){
  int a,b,c;
  
    cin>>a>>b>>c;
 int d[120],e[120],max;
  
 for (int i =0;i<c;i++){
      d[i] = a+i;
     e[i] = b-c+1+i;
 }
  for(int i =0;i<c;i++){
    cout << d[i] << endl;
    
    if(d[i] >=b ){
      return 0;
    }
    if(d[i] == e[0]-1){
      max = d[i];
      break;
  }
  }
  for(int j =0;j<c;j++){
    if((e[j] >= a) && (e[j] >= max) ){
  
    cout << e[j] <<endl;
  
    }
       }
       
       }
    
   


Measured memory_bytes: 256
//package abc121_B;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		
		int[] b = new int[m];
		for (int i = 0; i < m; i++) b[i] = sc.nextInt();
		
		int ans = 0;
		
		for (int i = 0; i < n; i++) {
			int tmp = 0;
			for (int j = 0; j < m; j++) {
				int a = sc.nextInt();
				tmp += a * b[j];
			}
			if (tmp + c > 0) ans++;
		}
		
		System.out.println(ans);
	}

}

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    int n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9)
       cout<<"hon\n";
    else if(n==0 || n==1 || n==6 || n==8)
        cout<<"pon\n";
    else 
        cout<<"bon\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

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

int main()
{
    int n,q,b,m,e;
    cin>>n;
    vector<int>a;
    REP(i,n){int x;cin>>x;a.push_back(x);}
    a.erase(unique(a.begin(),a.end()),a.end());
    REP(i,a.size())
    {
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
}


Measured memory_bytes: 3464
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static int minium_win(char input[], int start, int end){
		if(input[start] != '[' || input[end] != ']'){
			return Integer.MIN_VALUE;
		}
		
		int c_lv = 0;
		int c_start = -1;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int pos = start + 1; pos < end; pos++){
			if(input[pos] == '['){
				if(c_lv == 0){
					c_start = pos;
				}
				
				c_lv++;
			}else if(input[pos] == ']'){
				c_lv--;
				
				if(c_lv == 0){
					if(input[c_start + 1] == '[' && input[pos - 1] == ']'){
						list.add(minium_win(input, c_start, pos));
					}else{
						int num = 0;
						for(int keta = c_start + 1; keta < pos; keta++){
							num *= 10;
							num += input[keta] - '0';
						}
						
						list.add(num / 2 + 1);
					}
					
				}
			}
		}
		
		Collections.sort(list);
		//System.out.println(list);
		
		int ret = 0;
		for(int i = 0; i < list.size() / 2 + 1; i++){
			ret += list.get(i);
		}
		
		return ret;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int N = sc.nextInt();
		
		for(int tt = 0; tt < N; tt++){
			char[] input = sc.next().toCharArray();
			
			//System.out.println(Arrays.toString(input));
			
			System.out.println(minium_win(input, 0, input.length - 1));
		}
	}
}

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=a*b;;i--){
        if(a%i==0 && b%i==0){
            k--;
        }
        if(k==0){
            cout<<i<<endl;
            return 0;
        }
        
    }

    return 0;
}

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

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

inline void Main() {
  // code
  int n,k;
  cin>>n>>k;

  double r = 0;

  rep(i, n) {
    int c = 0;
    while((i+1)*pow(2,c) < k) c++;
    r += 1 / (n * pow(2, c));
  }

  cout << r << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    for(int i=0; i<3; i++)
        cin>>a[i];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    for(int i=0; i<3; i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,a[MAXN],l[MAXN],r[MAXN];
int sta[MAXN],top;
int64 ans = 0;
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    for(int i = 1 ; i <= N ; ++i) {
        while(top && a[sta[top]] > a[i]) --top;
        l[i] = sta[top] + 1;
        sta[++top] = i;
    }
    top = 0;sta[0] = N + 1;
    for(int i = N ; i >= 1 ; --i) {
        while(top && a[sta[top]] > a[i]) --top;
        r[i] = sta[top] - 1;
        sta[++top] = i;
    }
    for(int i = 1 ; i <= N ; ++i) {
        ans += 1LL * (i - l[i] + 1) * (r[i] - i + 1) * a[i];
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 3328
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int N, K;
    string S;
    cin >> N >> S >> K;

    char s = S[K - 1];
    REP(i, N)
    {
        if (S[i] != s)
            S[i] = '*';
    }

    cout << S << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << n / 3 << endl;
}

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


int main() {
  int a, b, x;
  cin >> a >> b >> x;
  string ans = "NO";
  if((a+b)>=x && a <= x) ans = "YES"; 
  cout << ans << endl;
  return 0;
  
}

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

A,B=[],[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)

A.sort()
B.sort()

I=~-N//2
print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

vector<ll> tree;
vector<ll> g(100001,-1);

int dfs(ll v,ll const z,vector<unordered_set<ll>> &f){
    tree[z]++;
    g[v] = z;
    for(auto i:f[v]) if(g[i]==-1) dfs(i,z,f);
    return 0;
}

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

    ll n,m,k;
    cin >> n >> m >> k;
    vector<unordered_set<ll>> f(n+1),b(n+1);
    ll x,y,z=0;
    rep(i,m){
        cin >> x >> y;
        f[x].insert(y);
        f[y].insert(x);
    }
    rep(i,k){
        cin >> x >> y;
        b[x].insert(y);
        b[y].insert(x);
    }
    rep(i,n){
        if(g[i+1]!=-1) goto NEXT;
        tree.push_back(0);
        dfs(i+1,z,f);
        z++;
        NEXT:
        continue;
    }
    ll ans;
    rep(i,n){
        ans = tree[g[i+1]]-1;
        for(auto j:f[i+1]) if(g[i+1]==g[j]) ans--;
        for(auto j:b[i+1]) if(g[i+1]==g[j]) ans--;
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 33792
#include<iostream>
using namespace std;
typedef long long ll;

ll a[51],p[51];

ll f(int n,ll x){
	if(n==0) return x<=0?0:1;
	if(x<=1+a[n-1]) return f(n-1,x-1);
	else return p[n-1]+1+f(n-1,x-2-a[n-1]);
}

int main(){
	int n;
	ll x;
	cin >> n >> x;
	a[0]=1,p[0]=1;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]*2+3;
		p[i]=p[i-1]*2+1;
	}
	cout << f(n,x) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    long[] A = new long[N+1];
    long[] B = new long[N];
    
    for (int i = 0; i <= N; i++) {
      A[i] = sc.nextInt();
    }

    for (int i = 0; i < N; i++) {
      B[i] = sc.nextInt();
    }

    sc.close();

    long count = 0;

    long A_ = A[N];

    for (int i = N-1; 0 <= i; i--){

      A_ = A[i] + A_;

      if (A_ <= B[i]) {

        count = count + A_;
      
        A_ = 0;
     
      } else {
      
        count = count + B[i];
      
        if ((A_ - B[i]) < A[i]){
      
          A_ = A_ - B[i];
      
        } else {
      
          A_ = A[i];
      
        }

      }
    }

    System.out.println(count);
 
  }

}

Measured memory_bytes: 92328
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

const int maxn=1e5+5;

int n,a[maxn];

int main()
{
	int ans=1, s=0;
	
	scanf("%d",&n);
	fo(i,1,n)
	{
		scanf("%d",&a[i]);
		if (i==1) continue;
		
		if (a[i]<a[i-1]) s|=1;
			else if (a[i]>a[i-1]) s|=2;
		if (s==3)
		{
			ans++;
			s=0;
		}
	}
	
	printf("%d\n",ans);
}

Measured memory_bytes: 512
package main

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

func main() {
	var (
		In = ReadLineInt()
		N  = In[0]
		K  = In[1]
	)

	//(K*(K-1))^n-1
	fmt.Println(K * int(math.Pow(float64(K-1), float64(N-1))))
}

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

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    ll a[n];
    rep(0,i,n){
        cin>>a[i];
    }
    ll ans=1e9;
    rep(1,i,101){
        ll sum=0;
        rep(0,j,n){
            sum+=(a[j]-i)*(a[j]-i);
        }
        ans=min(sum,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
ll power(ll a,ll b)
{ll result=1;
while(b>0)
{if(b%2==1)
 result*=a;
 a*=a;
 b/=2;
}
return result;
}
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n,count=0;
cin>>n;
while(n--)
{int x,y;
 cin>>x>>y;
 if(x==y)
 count++;
 else if(count==3)
 break;
 else
 count=0;
 
}
if(count>=3)
cout<<"Yes";
else
cout<<"No";
}


Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


vector<int>E[330];
ll dist[330][330];
ll dist2[330][330];
int N, M, L;


void bfs(int s) {
	queue<pair<int, int>>q;
	q.push({s,-1});
	while (q.size()) {
		auto f = q.front();
		q.pop();
		int v = f.first;
		int d = f.second;
		for (int i = 0; i < N; i++) {
			if (dist[v][i] <= L) {
				if (dist2[s][i] > 1e15) {
					dist2[s][i] = d + 1;
					q.push({i,d+1});
				}
			}
		}
	}
}


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

	cin >> N >> M >> L;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dist[i][j] = (i == j)?0:inf;
		}
	}

	for (int i = 0; i < M; i++) {
		int A, B, C;
		cin >> A >> B >> C;
		A--, B--;
		if (C <= L) {
			dist[A][B] = C;
			dist[B][A] = C;
		}
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}


	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dist2[i][j] = ((i == j) ? 0 : inf);
		}
	}

	for (int i = 0; i < N;i++)bfs(i);
	
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		if (dist2[s][t] < 1e15)puts(dist2[s][t]);
		else puts(-1);
	}
	

	return 0;
}


Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(2000000)

from heapq import heappop, heappush

def input(f):
    n, = map(int, f.readline().split())
    s = [None for _ in range(n-1)]
    t = [None for _ in range(n-1)]
    w = [None for _ in range(n-1)]
    for i in range(n-1):
        s[i], t[i], w[i] = map(int, f.readline().split())
    return n, s, t, w

def solve(n, s, t, w):
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[s[i]].append((t[i], w[i]))
        g[t[i]].append((s[i], w[i]))

    def find(root):
        best = (0, root)
        q = []
        heappush(q, best)

        inf = 10**8+1
        dist = [inf for _ in range(n)]
        dist[root] = 0
        while q:
            cur = heappop(q)
            for nxt in g[cur[1]]:
                if cur[0] + nxt[1] < dist[nxt[0]]:
                    dist[nxt[0]] = cur[0] + nxt[1]
                    heappush(q, (cur[0] + nxt[1], nxt[0]))

        for i in range(n):
            if dist[i] != inf and dist[i] > best[0]:
                best = (dist[i], i)
        return best

    ret1 = find(0)
    ret2 = find(ret1[1])
    return ret2[0]

with open('/dev/stdin') as f:
    print(solve(*input(f)))



Measured memory_bytes: 44868
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let abc: Vec<i32> = read_vec();
  let ans = abc[2] - (abc[0] - abc[1]);
  
  println!("{}", if ans <= 0 { 0 } else { ans });
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String[] ar = new String[n];
        for (int i = 0; i < n; i++) {
            char[] v = scan.next().toCharArray();
            Arrays.sort(v);
            ar[i] = new String(v);
        }

        Arrays.sort(ar);
        long cnt = 0;
        long sum = 0;
        for (int i = 1; i < ar.length; i++) {
            if(ar[i].equals(ar[i-1])){
                cnt++;
                sum+=cnt;
            }else{
                cnt = 0;
            }
        }

        System.out.println(sum);
    }
}


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

int main(){
  int N;
  long S[5]={};
  cin >> N;
  for(int i=0; i<N; i++){
    string s; cin >> s;
    if(s[0]=='M') S[0]++;
    else if(s[0]=='A') S[1]++;
    else if(s[0]=='R') S[2]++;
    else if(s[0]=='C') S[3]++;
    else if(s[0]=='H') S[4]++;
  }
  long ans=0;
  for(int i=0; i<3; i++){
    for(int j=i+1; j<4; j++){
      for(int k=j+1; k<5; k++){
        ans+=S[i]*S[j]*S[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256