akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	vector<ll> h(n);
	rep(i,n) cin >> x[i] >> y[i] >> h[i];
	vector<pair<ll, pii>> v(n);
	rep(i,n) {
		v[i].first = h[i];
		v[i].second.first = x[i];
		v[i].second.second = y[i];
	}
	sort(ALL(v), greater<>());
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			ll mh = v[0].first + abs(v[0].second.first - j) + abs(v[0].second.second - i);
			if (mh < 1) continue;
			bool b = true;
			for (int k = 0; k < n; k++) {
				if (v[k].first != max(mh - abs(v[k].second.first - j) - abs(v[k].second.second - i), 0ll)) b = false;
			}
			if (b) {
				cout << j << " " << i << " " << mh << endl;
				return;
			}
		}
	}
}

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


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

struct P {
    int x, y;
    bool operator<(const P& o) const {
        if (y == o.y) {
            return x < o.x;
        } else {
            return y > o.y;
        }
    }
};

using namespace std;

int main() {
    int n; cin >> n;
    vector<P> Ps;
    for (int i = 0; i < n; i++) {
        P p; cin >> p.x >> p.y;
        Ps.push_back(p);
    }
    sort(Ps.begin(), Ps.end());
    cout << Ps[0].x << ' ' << Ps[0].y << endl;
    return 0;
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline
large_p = 10**9 + 7

def comb_mod(n, r, large_p):
    a, b = 1, 1
    r = min(r, n - r)
    for i in range(r):
        a = a * (n - i) % large_p
        b = b * (r - i) % large_p
    return a * pow(b, large_p - 2, large_p) % large_p

def main():
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    p1, p2 = 0, 0
    for i1 in range(0, x + 1):
        if x - i1 == (y - i1 * 2) * 2:
            p1 = i1
            p2 = y - i1 * 2
            break
    if p1 < 0 or p2 < 0 or (p1 == 0 and p2 == 0):
        print(0)
        sys.exit()

    r = comb_mod(p1 + p2, p1, large_p)
    print(r)

if __name__ == '__main__':
    main()

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

ll K;
ll A[50];

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

    std::cin >> K;
    ll N = K / 50, M = K % 50;

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

    for(int i=0;i<50;++i){
        if(50 - M <= i){
            A[i] += 50;
            A[i] -= M - 1;
        }else{
            A[i] -= M;
        }
    }

    std::cout << 50 << std::endl;
    for(int i=0;i<50;++i){
        std::cout << A[i] << " \n"[i+1==50];
    }
}


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

        using namespace std;

        typedef long long ll;
        const ll N = 5e5+5;
        const ll MOD = 1000000007;
        #define all(x) x.begin(),x.end()
        #define pii pair<ll,ll>
        #define pis pair<ll,string>
        #define F first
        #define S second
        #define LCM(a,b) ((a*b)/__gcd(a,b))
        #define inf 1e15
        #define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
        #define PI 3.14159265
        #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
        const double EPS = 1E-9;
        typedef vector< vector<double> > matrix;
        typedef vector<int> vi;




int main(){

    fast;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(a * d, max( b * c, max(a * c, b * d))) << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<vector>


int main()
{
	std::vector<int> w_vec;
	int k, n;
	std::cin >> n >> k;
	w_vec.resize(n);
	for (auto& elem : w_vec) std::cin >> elem;
	std::vector<int> c_vec(n, -1);
	c_vec.front() = 0;
	if (k >= n) {
		std::cout << std::abs(w_vec.front() - w_vec.back()) << "\n";
	}
	else {
		for (int j = 1; j <= k; ++j) {
			c_vec[j] = c_vec.front() + std::abs(w_vec.front() - w_vec[j]);
		}



		int cost;
		for (int cnt = k + 1; cnt < n; ++cnt) {
			for (int j = cnt - k; j < cnt; ++j) {
				cost = c_vec[j] + std::abs(w_vec[j] - w_vec[cnt]);
				if (c_vec[cnt] == -1 || c_vec[cnt] > cost)
					c_vec[cnt] = cost;
			}
		}

		std::cout << c_vec.back() << "\n";
	}
		
}

Measured memory_bytes: 1024
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**10
    best_j = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[jj] * (i - L[jj]) for jj in range(26)])
        if diff > max_diff:
            max_diff = diff
            best_j = j
        L[j] = memo
    L[best_j] = i
    X.append(best_j)
for x in X:
    print(x + 1)


Measured memory_bytes: 74448
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++)
      a[i] = sc.nextInt();
    sc.close();

    int K = 3;
    int[] c = new int[K + 1];
    for (int i = 0; i < N; i++) c[a[i]]++;

    double[][][] mm = new double[N + 1][N + 1][N + 1];
    double ans = f(mm, c);
    System.out.println(ans);
  }

  private static double f(double[][][] mm, int[] c) {
    if (mm[c[1]][c[2]][c[3]] != 0) return mm[c[1]][c[2]][c[3]];

    double fsum = 0;
    int csum = 0;
    for (int i = c.length - 1; 0 < i; i--) {
      if (c[i] == 0) continue;
      c[i]--;
      c[i - 1]++;
      double f = f(mm, c);
      c[i - 1]--;
      c[i]++;
      fsum += f * c[i];
      csum += c[i];
    }
    if (csum == 0) return 0d;
    double ans = (fsum + c[0] + csum) / csum;

    mm[c[1]][c[2]][c[3]] = ans;
    return ans;
  }
}

Measured memory_bytes: 305748
# coding: utf-8

def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = tuple(map(int, args[1].split()))

    l, r = 0, max(A)
    while l+1 < r:
        m = (l+r)//2
        cnt = 0
        for a in A:
            cnt += -(-a//m)-1

        if k < cnt:
            l = m
        else:
            r = m

    return str(r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main(){

    int n; cin>>n;

    vector<int> seq(n);

    vector<int> cseq(n,0);

    int mx =0,secmx =0;

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

        cin>>seq.at(i);

        mx = max(mx,seq.at(i));

        cseq.at(i) = seq.at(i);
    }

    sort(cseq.begin(),cseq.end());

    secmx = cseq.at(n-2);

    for(int i=0; i<n; i++){
        if(seq.at(i) == mx) cout<<secmx<<endl;

        else  cout<<mx<<endl;
    }

    return 0;

}

Measured memory_bytes: 3200
def aa(s):
    joi = 0
    ioi = 0
    for i in range(len(s)-2):
        if s[i:i+3] == "JOI":
            joi += 1
        if s[i:i+3] == "IOI":
            ioi += 1
    print(joi)
    print(ioi)
    
n = []
while True:
    try:
        n.append(input())
    except EOFError:
        break
for i in n:
    aa(i)


Measured memory_bytes: 5572
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <cmath>
#include <map>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define decn int n = 0; cin >> n
#define sort(v) sort(v.begin(), v.end())
#define in(type, n) type n = 0; cin >> n

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

int main(){
	ll n;
	int k;
	cin >> n >> k;
	rep(i, 100) {
		if (n / pow(k, i) < 1) {
			if (n == pow(k, i)) {
				cout << i + 1;
				return 0;
			}
			cout << i;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll vis[200003]={0};
ll vis2[200003]={0};
vector<ll>adj[200003];
vector<ll>x;
ll ans[200003];
ll n;
void dfs(ll k,ll count)
{
    vis[k]=1;
    vis2[k]=1;
    for(ll i=0;i<adj[k].size();i++)
    {
           if(vis[adj[k][i]]==0)
           {
               count++;
               dfs(adj[k][i],count);
           }
    }
    for(ll i=1;i<=n;i++)
    {
        if(vis2[i]==1)
            {ans[i]=count;
              vis2[i]=0;
            }
    }

}

int main()
{
   ll s,w;
   cin>>s>>w;
   if(w>=s)
   cout<<"unsafe"<<endl;
   else
    cout<<"safe"<<endl;
    
}


Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


int main() {
	ll m1,d1,m2,d2;
	cin>>m1>>d1>>m2>>d2;
	if(d2==1){
		cout << "1";
	}
	else{
		cout << "0";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<ctime>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<tuple>
#include<cassert>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<climits>
#include<typeinfo>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
double pi = 3.141592653589793238;
using ll = long long;
using namespace std;

ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpcombination[10000][10000];

ll modi = 1000000007;
ll combination(ll n, ll r) {
	if (n == r) { return dpcombination[n][n] = 1; }
	else if (r == 0) { return dpcombination[n][0] = 1; }
	else if (r == 1) { return dpcombination[n][1] = n; }
	else if (dpcombination[n][r]) { return dpcombination[n][r]; }
	else { return dpcombination[n][r] = combination(n - 1, r - 1) % modi + combination(n - 1, r) % modi; }
}

void clockman(int time1) {

	cout << 1.0*(clock() - time1) / CLOCKS_PER_SEC << endl;
	return;
}
//cout << fixed << setprecision(10)

void printVec(std::vector<int> &vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


int main() {
	int n;
	cin >> n;
	vector<string>s(n);
	vector<int>c(4);
	for (int i = 0;i < n;i++) { 
		cin >> s[i];
		if (s[i] == "AC")c[0]++;
		else if (s[i] == "WA")c[1]++;
		else if (s[i] == "TLE")c[2]++;
		else c[3]++;

	
	}
	cout << "AC x " << c[0] << endl;
	cout << "WA x " << c[1] << endl;
	cout << "TLE x " << c[2] << endl;
	cout << "RE x " << c[3] << endl;
	
	
	return 0;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int p[29];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int cnt=0;
  for(int i=1;i<n-1;i++){
    vector<int>vec;
    vec.push_back(p[i-1]);
    vec.push_back(p[i]);
    vec.push_back(p[i+1]);
    sort(vec.begin(),vec.end());
    if(vec[1]==p[i])cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	S = input()
	S = S[:-1]
 
	if S == "Sunny":
		print("Cloudy")
	elif S == "Cloudy":
		print("Rainy")
	else:
		print("Sunny")
	




if __name__ == "__main__":
	main()


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int x; cin >> x;

    if(x == 0){
    	cout<<"1";
    }
    if(x == 1){
    	cout<<"0";
    }

    return 0;

}


Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#define f first
#define s second
#define pb push_back
using namespace std;
long long const inf=1e18+5;
int const maxn=1005;
typedef long long ll;
typedef pair<int,int>P;
vector<P>p;
char s[maxn];
int num[30];
ll solve(ll n,ll x){
	ll num = n/x;
	return (x+num*x)*num>>1;
}
int main(){
	ll n,res;
	scanf("%lld",&n);
	res = n*(n+1)>>1;
	res = res - solve(n,3) - solve(n,5) + solve(n,15);
	printf("%lld\n",res);
}


Measured memory_bytes: 3764
#include <stdio.h>

int	main(void)
{
	int	n;
	int	count = 0, flag = 0;
	int	d1[100];
	int	d2[100];

	scanf("%i", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%i", &d1[i]);
		scanf("%i", &d2[i]);
		if (d1[i] == d2[i])
		{
			count++;
			if (count == 3)
				flag = 1;
		}
		else
			count = 0;
	}

	if (flag == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return (0);
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using product = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
 
ll H,W;
vvll route;
vvll dist;
 
bool checkRoute(ll x,ll y)
{
    if(x<0 || y<0 || H-1<x || W-1<y)return false;
    if(dist[x][y]==-1 && route[x][y]==1)return true;
    return false;
}
 
int main(){
    ll black=0;
    cin>>H>>W;
    route.resize(H);
    dist.resize(H);
    for(ll i=0;i<H;i++)
    {
        route[i]=vll(W,0);
        dist[i]=vll(W,-1);
        for(ll j=0;j<W;j++)
        {
            char s;cin>>s;
            if(s=='.'){
                route[i][j]=1;
            }
            else {
                route[i][j]=0;black+=1;
            }
        }
    }
    queue<product>  que;
    que.push(make_pair(0,0));
    dist[0][0]=0;
    while(!que.empty())
    {
        product v=que.front();
        que.pop();
 
        if(checkRoute(v.first+1,v.second))
        {
            que.push(make_pair(v.first+1,v.second));
            dist[v.first+1][v.second]=dist[v.first][v.second]+1;
        }
        if(checkRoute(v.first-1,v.second))
        {
            que.push(make_pair(v.first-1,v.second));
            dist[v.first-1][v.second]=dist[v.first][v.second]+1;
        }
        if(checkRoute(v.first,v.second+1))
        {
            que.push(make_pair(v.first,v.second+1));
            dist[v.first][v.second+1]=dist[v.first][v.second]+1;
        }
        if(checkRoute(v.first,v.second-1))
        {
            que.push(make_pair(v.first,v.second-1));
            dist[v.first][v.second-1]=dist[v.first][v.second]+1;
        }
    }
    if(dist[H-1][W-1]==-1)cout<<-1<<endl;
    else cout<<H*W-(dist[H-1][W-1]+1)-black<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n, k, a[100], tmp[100100], cnt;
LL x[100100], y[100100], mx;
int main() {
	scanf("%lld%lld", &n, &k);
	while(k) {
		a[++cnt] = k % 2;
		k /= 2;
	}
	for(int i = 1; i <= n; i++) {
		scanf("%lld%lld", &x[i], &y[i]);
	}
	for(int i = 0; i <= cnt; i++) {
		if(i && a[i] == 0) continue;
		LL ans = 0;
		for(int j = 1; j <= n; j++) {
			int xx = x[j], now = 0, flg = 0;
			while(xx) {
				now++;
				if(now == i && xx % 2) flg = 1;
				if(now > i && a[now] < xx % 2) flg = 1;
				if(flg) break;
				xx /= 2;
			}
			if(!flg) ans += y[j];
			//if(!flg) printf("%d\n", x[j]);
		}
		mx = max(mx, ans);
		//printf("\n");
	}
	printf("%lld\n", mx);
}

Measured memory_bytes: 1792
/**
 *    author:  FromDihPout
 *    created: 2020-08-11
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, y;
    cin >> n >> y;
    if (y > n * 10000 || y < n * 1000) {
        cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
        return 0;
    }
    
    int a = 0, b = 0, c = y / 1000;
    while (a + b + c > n) {
        if (a + b + c - 4 >= n && c - 5 >= 0) {
            b += 1;
            c -= 5;
        }
        else if (a + b + c - 1 >= n && b - 2 >= 0) {
            a += 1;
            b -= 2;
        }
        else {
            break;
        }
    }
    if (a + b + c == n) {
        cout << a << ' ' << b << ' ' << c << '\n';
    }
    else {
        cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k, q;
vector<i64> a;
int main() {
  cin >> n >> k >> q;
  read_n(a, n);

  i64 ans = 1ll << 50;
  for (i64 j = 0; j < n; ++j) {
    i64 x = a[j];
    vector<vector<i64>> r;
    bool f = true;

    for (i64 i = 0; i < n; ++i) {
      if (a[i] >= x) {
        if (f) {
          r.emplace_back();
          f = false;
        }
        r.back().push_back(a[i]);
      } else {
        f = true;
      }
    }

    vector<i64> s;
    for (vector<i64>& v : r) {
      sort(begin(v), end(v));
      for (i64 i = 0; i < i64(v.size()) - k + 1; ++i) {
        s.push_back(v[i]);
      }
    }
    sort(begin(s), end(s));

    if (s.size() >= q) ans = min(ans, s[q - 1] - x);
  }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=2e5+7;
const ll inf=(ll)1e17+7;
struct e{
	int from,to,dis,nxt;
}edge[MAXN<<2];
struct po{
	int x,y;
	ll l;
	bool operator <(const po &rhs)const
	{
		return l<rhs.l;
	}
}a[MAXN*20],g[MAXN<<2],pre;
int n,m,wson[MAXN],size[MAXN],vis[MAXN*2];
int f[MAXN],tp=0,num,head[MAXN<<1],root,sum,cnt;
ll ans,dep[MAXN],x[MAXN];
inline int read()
{
	int x=0,c=1;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
inline void add_edge(int from,int to,int dis)
{
	edge[++num].nxt=head[from];
	edge[num].to=to;
	edge[num].dis=dis;
	head[from]=num;
}
inline void get_root(int u,int fa)
{
	size[u]=1;wson[u]=0;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]||v==fa) continue;
		get_root(v,u);
		size[u]+=size[v];
		wson[u]=max(wson[u],size[v]);
	}
	wson[u]=max(wson[u],sum-size[u]);
	root=(wson[u]<wson[root]?u:root);
}
inline void dfs(int u,int fa,ll d)
{
	g[++tp]=(po){u,0,d+x[u]};
	pre=min(pre,g[tp]);
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]||v==fa) continue;
		dfs(v,u,d+edge[i].dis);
	}
}
inline void solve(int u)	
{
	pre=(po){0,0,inf};
	vis[u]=1;tp=0;
	dfs(u,0,0);
	for(int i=1;i<=tp;i++) a[++cnt]=(po){pre.x,g[i].x,pre.l+g[i].l};
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(vis[v]) continue;
		sum=size[v];root=0;
		get_root(v,u);solve(root);
	}
}
int find(int x) {return f[x]==x?f[x]:f[x]=find(f[x]);}
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("my.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) x[i]=read();
	for(int i=1;i<=n-1;i++){
		int u,v,l;
		u=read();v=read();l=read();
		add_edge(u,v,l);add_edge(v,u,l);
	}
	wson[0]=10000007;
	sum=n;
	
	get_root(1,0);
	
	solve(root);
	
	sort(a+1,a+cnt+1);
	for(int i=1;i<=n;i++) f[i]=i;	
	for(int i=1;i<=cnt;i++){
		int r1=find(a[i].x),r2=find(a[i].y);
		if(r1!=r2){
			ans+=a[i].l;
			f[r1]=r2;
		}
	}
	cout<<ans;
}

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

int main(){
    char c; cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
	cout << "vowel" << endl;
    }else{
	cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> mat(n, std::vector<int>(n, 0));
    
    for (int i = 0; i < n; i++){
        int u, k;
        std::cin >> u >> k;
        while(k--){
            int a;
            std::cin >> a;
            mat[u - 1][a - 1] = 1;
        }
    }
    
    // output
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            std::cout << mat[i][j];
            if (j != n - 1) std::cout << " ";
        }
        std::cout << std::endl;
    }
}


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





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

    bool dp[k+1];

    for(int i=0; i<=k; ++i)
    {
        dp[i] = false;
    }
    vector<int> arr(n);

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

        cin>>arr[i];

    }


    for(int i=1; i<=k; ++i)
    {
        for(int j=0; j<n; ++j)
        {
            if(arr[j]<=i)
            {
                dp[i] = !(dp[i-arr[j]]);
                if(dp[i])
                {
                    break;
                }
            }
        }
    }




    if(dp[k])
    {
        cout<<"First"<<endl;
    }
    else
    {
        cout<<"Second"<<endl;
    }




    return 0;

}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const long double PI = 3.14159265358979323846264338327950L;

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  long double rad = 2 * PI *((long double)h / 12.0 + (long double)m / 60.0 / 12.0
                             - (long double)m / 60.0);
  long double ans = (long double)(a*a+b*b)-(long double)(2*a*b)*cosl(rad);
  printf("%20.20Lf\n", sqrt(ans));
  return 0;
}
    

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

int main(){
    string s;
    cin >> s;
    int len = s.length();
    int ans=0;
    for(int i=2; i<len; i+=2){
        bool check=true;
        int ii = i/2;
        for(int j=0; j<i/2; j++){
            if(s[j]==s[ii+j]){
                continue;
            }else{
                check=false;
            }
        }
        if(check){
            ans=i;
        }
    }
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll x;
int main(){
	cin>>n>>x;
	if(x==1||x==2*n-1){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	int t=0;
	for(int i=1;i<=n*2-1;i++){
		if(i==n-1){
			cout<<n*2-1<<endl;
			continue;
		}else if(i==n){
			cout<<x<<endl;
			continue;
		}else if(i==n+1){
			cout<<1<<endl;
			continue;
		}
		t++;
		while((t==1||t==n*2-1||t==x)){
			t++;
		}
		cout<<t<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  string s; cin >> s;
  set<char> uni;
  for(int i=0;i<s.size();++i) uni.insert(s[i]);
  cout << (uni.size()==s.size()?"yes":"no") << endl;
  
  return 0;
}


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

using namespace std;

vector<int> vc[100];
int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
	int a,b;
    cin >> a >> b;
    vc[a].push_back(b);
    vc[b].push_back(a);
  }
  
  for(int i=1;i<=n;i++){
	cout << vc[i].size() << '\n';
  }
}

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

int main(){
    string s;
    cin >> s;
  	string a = s;
  	reverse(s.begin(),s.end());
    int res = 0;
    rep(i,s.size()){
    	if(s[i] != a[i]) res++;
    }
  	cout << res/2 << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		while(true){
			int[] map = new int[24*60*60];
			int n = sc.nextInt();
			if(n==0) break;
			while(n-->0){
				String s = sc.next();
				String e = sc.next();
				int start = Integer.valueOf(s.substring(0, 2))*3600 
						+ Integer.valueOf(s.substring(3, 5))*60
						+ Integer.valueOf(s.substring(6, 8));
				int end = Integer.valueOf(e.substring(0, 2))*3600 
						+ Integer.valueOf(e.substring(3, 5))*60
						+ Integer.valueOf(e.substring(6, 8));
				for(int i=start;i<end;i++){
					map[i]++;
				}
			}
			int max = 0;
			for(int i=0;i<3600*24;i++){
				if(max<map[i]){
					max = map[i];
				}
			}
			pr.println(max);
		}
		pr.flush();
		sc.close();
	}
}

Measured memory_bytes: 69764
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim().split("\n");
  const configs = input.shift().split(" ");
  const problemCount = configs[0];
  const answerCount = configs[1];

  let acCount = 0;
  let waCount = 0;
  const map = new Map();
  for (let i = 0; i < answerCount; i++) {
    const data = input[i].split(" ");
    const nextProblem = parseInt(data[0], 10);
    const nextRw = data[1]; // Right and Wrong

    const prevRw = map.get(nextProblem) || null;

    if (prevRw === null) {
      // 初めて解く問題
      if (nextRw === "AC") {
        acCount++;
        map.set(nextProblem, "AC");
      } else {
        map.set(nextProblem, 1);
      }
    } else if (prevRw !== "AC") {
      // 解答経験がある問題
      if (nextRw === "AC") {
        acCount++;
        waCount += prevRw;
        map.set(nextProblem, "AC");
      } else {
        map.set(nextProblem, prevRw + 1);
      }
    }
  }

  console.log(acCount + " " + waCount);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 33668
#include <stdio.h>
#include<stdlib.h>
#define MAX 100

int top = 0;
void push(int);
int pop(void);
//int isEmpty(int);
//int isFull(int);
int st[MAX];

int main()
{
  int x,y,i;
  char s[20];
  
 
  //scanf("%c ",&s);

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      x = pop();
      y = pop();
      push(x+y);
      //break;
      
    }
    else if(s[0]=='-'){
      x = pop();
      y = pop();
      push(y-x);
      // break;
    }
    else if(s[0]=='*'){
      x = pop();
      y = pop();
      push(x*y);
      //break;
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;

}

void push(int x){
  /*if (top>=MAX){
    isFull(x);
    return 0;
  }
  /*エラー処理*/

  st[top]=x;
  top++;
  //return st[top];
}
int pop(void){
  
  /*if (top==0){
    isEmpty(top);
    return 0;
  }
  /*エラー処理*/
  top--;
  return st[top];
}



Measured memory_bytes: 2752
#include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #define  judge(x,y) x>=1&&x<=n&&y>=1&&y<=m&&map[x][y]!=1

    using namespace std;

    int n,m,sx,sy,ex,ey; //?置全局?量
    int map[25][25];

    //?置方向数??化深搜代?
    int xx[]={-1,1,0,0};
    int yy[]={0,0,-1,1};
    int step,steps;

    void dfs(int x,int y)
    {

      if(step>10)return;     //  ??出口，?数大于10?就返回

      for(int i=0;i<4;i++)
      {
        int dx=x+xx[i];
        int dy=y+yy[i];
        int ok=0;  //作?某个方向能不能走的一个?志?量

        while(judge(dx,dy))
        {
            ok=1;
            if(dx==ex&&dy==ey)
            {
              if(step<steps)steps=step;
            }
            dx+=xx[i]; //搜索整条直?
            dy+=yy[i];
        }
        if(map[dx][dy]==1&&ok)
        {
            step++;
            map[dx][dy]=0;
            dfs(dx-xx[i],dy-yy[i]);
            step--;
            map[dx][dy]=1;
        }
      }

    }

    int main()
    {
            while(cin>>m>>n)
            {
                if(n==0&&m==0)break;
                memset(map,0,sizeof(map));
                for(int i=1;i<=n;i++)
                 for(int j=1;j<=m;j++)
                  {
                      cin>>map[i][j];
                      if(map[i][j]==2){sx=i;sy=j;}
                      if(map[i][j]==3){ex=i;ey=j;}
                  }
                step=1;
                steps=1000000;
                dfs(sx,sy);

                if(steps>10) cout<<-1<<endl;
                else  cout<<steps<<endl;
            }
            return 0;
    }

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

int to_int(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    else return -1;
}               

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    string S;cin >> S;int N = S.size();
    int K;cin >> K;
    int dp[N+10][K+10][2] = {};
    dp[0][0][0] = 1;
    REP(i,N)REP(j,K+1)REP(k,2){
        int nd = to_int(S[i]);
        REP(d,10){
            int ni = i+1,nj = j,nk = k;
            if(d != 0) nj++;
            if(k == 0){
                if(d > nd) continue;
                if(d < nd) nk= 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    cout << dp[N][K][1] + dp[N][K][0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=998244353;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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

void next(vector<int> &use){
    bool ans=true;
    int cnt=0;
    while(ans){
        use[cnt]++;
        if(use[cnt]<=2)ans=false;
        else use[cnt]=0;
        cnt++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int n,s;cin >> n >> s;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    /*
    普通の(Tとか考えない)やつならdp[i][j]:=i個目まででjをつくる　で解ける
    i番目を使わずに次に移るときは、そいつがTにある/なし関係なく構成できるので*2
    i番目を使うときは1倍
    */
    vector<vector<ll>> dp(n+1,vector<ll>(s+1));
    dp[0][0]=1;
    rep(i,n)rep(j,s+1){
        dp[i+1][j]+=2*dp[i][j];
        dp[i+1][j]%=big;
        if(j+a[i]<=s){
            dp[i+1][j+a[i]]+=dp[i][j];
            dp[i+1][j+a[i]]%=big;
        }
    }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 73684
/*
[abc118] C - Monsters Battle Royale
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int gcd(int a, int b) {
    while (b > 0) {
        swap(a %= b, b);
    }
    return a;
}

const int MAX_N = 1e5;

int N;
int A[MAX_N];

ll solve() {
    int ans = A[0];
    for (int i = 1; i < N; i++) {
        ans = gcd(ans, A[i]);
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

#define int int64_t
//int a[N+2];

int32_t  main(){
	IOS;
  int a,b,x;cin>>a>>b>>x;
  int ans=(b/x)+1;
  if(a>0)ans-=(a-1)/x+1;
  cout<<ans<<endl;

  return 0;
}



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

int main() {
  long n, m, z = 0;
  cin >> n >> m;
  long lmax = 0, rmin = n;
  for (int i = 0; i < m; i++) {
    long l, r;
    cin >> l >> r;
    lmax = max(l, lmax);
    rmin = min(r, rmin);
  }
  long ans = max((rmin - lmax + 1), z);
  cout << ans;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
eda = []
for _ in range(M):
    A, B = map(int, input().split())
    eda.append((A-1, B-1))

uf = UnionFind(N)

ans = [N * (N - 1) // 2]
for i in range(M-1, -1, -1):
    if uf.same(eda[i][0], eda[i][1]):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(eda[i][0]) * uf.size(eda[i][1]))
        uf.union(eda[i][0], eda[i][1])

print('\n'.join(list(map(str, reversed(ans[:-1])))))

Measured memory_bytes: 29560
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextLong();
    long[]x = new long[n];
    long[]y = new long[n];

    for(int i=0; i<n; i++) {
    	x[i] = sc.nextLong();
    	y[i] = sc.nextLong();
    }
    long cou = 0;
    long a = 0;
    for(int i=0; i<n; i++) {
    	a = x[i]*x[i]+y[i]*y[i] ;
     	if(Math.sqrt(a) <= d) {
    		cou++;
    	}
    }
    	System.out.println(cou);
    }
}


Measured memory_bytes: 63148
#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>
#include <assert.h>
#include <numeric>

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)

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


ll gcd(ll a, ll b) {
    ll d = 1;
    if (b != 0) {
        d = gcd(b, a % b);
    } else {
        return a;
    }
    return d;
}

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

    ll a, b;
    cin >> a >> b;

    ll d = gcd(a, b);

    ll res = a * b / d;

    cout << res << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int x,y,z;cin>>x>>y>>z;
    int ans=x+y+z-max(x,max(y,z));
    cout<<ans;
}

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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  auto itr = unique(a.begin(), a.end());
  a.erase(itr, a.end());
  cout << a.size() + a.size() % 2 - 1 << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+18;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = INF;
    rep(_, 2) {
        ll sum = 0;
        ll res = 0;
        rep(i, n) {
            if (i%2==0) {
                ll x = 1LL - (sum+a[i]);
                chmax(x, 0LL);
                res += x;
                sum += (a[i]+x);
            }
            else {
                ll x = (sum+a[i]) + 1LL;
                chmax(x, 0LL);
                res += x;
                sum += (a[i]-x);
            }
        }
        chmin(ans, res);
        if (_==1) break;
        rep(i, n) {
            a[i] *= -1;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == 0:
    print(sum(a))
    exit()
max_ = len(bin(10**12))-2

bins = [[0,0] for i in range(max_)]
for i in a:
    s = bin(i)[2:][::-1]
    for ind in range(max_):
        if ind >= len(s):
            bins[ind][0] += 1
        else:
            if s[ind] == "1":
                bins[ind][1] += 1
            else:
                bins[ind][0] += 1
keta = len(bin(k))-2
ans = 0
def DFS(now_point, now_keta, can_all=False):
    global ans
    if now_keta < 1:
        ans = max(ans, now_point)
        return
    if can_all:
        for i in range(now_keta):
            now_point += max(bins[i])*2**i
        ans = max(ans, now_point)
        return
    now = bin(k)[2:][::-1][now_keta-1]
    if now == "0":
        new_point = now_point + bins[now_keta-1][1]*2**(now_keta-1)
        DFS(new_point, now_keta-1, can_all=False)
    else:
        new_point_0 = now_point + bins[now_keta-1][1]*2**(now_keta-1)
        DFS(new_point_0, now_keta-1, can_all=True)
        new_point_1 = now_point + bins[now_keta-1][0]*2**(now_keta-1)
        DFS(new_point_1, now_keta-1, can_all=False)
DFS(0, keta, False)
for i in range(keta, max_):
    ans += bins[i][1]*(2**i)
print(ans)

Measured memory_bytes: 14748
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N = 1e6 + 5;

int n, m, k;
int x11, y11, x2, y2;
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;
set<int> leftR[N], leftC[N];

void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	leftR[y].erase(x);
	leftC[x].erase(y);
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		{
			auto it = leftC[x].lower_bound(y);
			vector<int> del;
			while(true)
			{
				if(it == leftC[x].end())
					break;
				int dista = *it - y;
				if(dista > k)
					break;
				if(a[x][*it] == '@')
					break;
				del.push_back(*it);
				int nx = x, ny = *it;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
				it++;
			}
			for(auto &it:del)
			{
				leftR[it].erase(x);
				leftC[x].erase(it);
			}
		}
		{
			auto it = leftR[y].lower_bound(x);
			vector<int> del;
			while(true)
			{
				if(it == leftR[y].end())
					break;
				int dista = *it - x;
				if(dista > k)
					break;
				if(a[*it][y] == '@')
					break;
				del.push_back(*it);
				int nx = *it, ny = y;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
				it++;
			}
			for(auto &it:del)
			{
				leftC[it].erase(y);
				leftR[y].erase(it);
			}
		}
		{
			auto it = leftC[x].lower_bound(y);
			vector<int> del;
			while(true)
			{
				if(it == leftC[x].begin())
					break;
				it--;
				int dista = y - *it;
				if(dista > k)
					break;
				if(a[x][*it] == '@')
					break;
				del.push_back(*it);
				int nx = x, ny = *it;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
			for(auto &it:del)
			{
				leftR[it].erase(x);
				leftC[x].erase(it);
			}
		}
		{
			auto it = leftR[y].lower_bound(x);
			vector<int> del;
			while(true)
			{
				if(it == leftR[y].begin())
					break;
				it--;
				int dista = x - *it;
				if(dista > k)
					break;
				if(a[*it][y] == '@')
					break;
				del.push_back(*it);
				int nx = *it, ny = y;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
			for(auto &it:del)
			{
				leftC[it].erase(y);
				leftR[y].erase(it);
			}
		}
	}
}

int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			leftC[i].insert(j);
			leftR[j].insert(i);
			cin >> a[i][j];
		}
	}
	bfs(x11, y11);
	if(!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}

Measured memory_bytes: 216244
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e9;

int main(){
	int W,H,N;
	cin>>W>>H>>N;
	int x1=0,x2=W,y3=0,y4=H;
	rep(i,N){
		int x,y,a;
		cin>>x>>y>>a;
		if(a==1)x1=max(x1,x);
		if(a==2)x2=min(x2,x);
		if(a==3)y3=max(y3,y);
		if(a==4)y4=min(y4,y);
	}
	cout<<max(0,x2-x1)*max(0,y4-y3);
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin >> a[i];
    int64_t ans = 0;
    for(int i=1;i<=n;) {
        if(a[i] != i) {
        	i++;
        	continue;
        }
        int len = 0;
        while(a[i] == i) {
        	len++;
        	i++;
        }
        ans += len&1 ? len/2 + 1 : len/2;
    }
    cout << ans;
}
    

Measured memory_bytes: 640