akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll h[n];
    rep(i,0,n){
        scanf("%lld",&h[i]);
    }
    // ll up=0;
    ans=h[0];
    rep(i,1,n){
        if(h[i]>=h[i-1]){
            ans+=h[i]-h[i-1];
        //     if(up==-1){

        //     }
        //     if(up==0){
        //         up=1;
        //         ma=h[i];
        //     }else if(up==-1){
        //         ans+=ma-mi;
        //         ma=h[i];
        //     }else{
        //         ma=h[i];
        //     }
        //     // ma=h[i];
        }            
    }

    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  string s;
  cin >> s;
  transform(all(s), s.begin(), ::tolower);
  int c = 0;
  while (true) {
    string t;
    cin >> t;
    if (t == "END_OF_TEXT") break;
    transform(all(t), t.begin(), ::tolower);
    c += s == t;
  }
  cout << c << endl;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;
using P = pair<ll, ll>;

bool cp(tuple<string, int, int> p1, tuple<string, int, int> p2) {
    if (get<0>(p1) == get<0>(p2)) {
        return get<1>(p1) > get<1>(p2);
    } else {
        return get<0>(p1) < get<0>(p2);
    }
}

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> p(N);

    for (int i = 0; i < N; i++) {
        string s;
        int t;
        cin >> s >> t;
        p[i] = make_tuple(s, t, i + 1);
    }
    sort(ALL(p), cp);
    for (int i = 0; i < N; i++) {
        cout << get<2>(p[i]) << endl;
    }
    return 0;
}


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

bool reversedigit(int x) {
    if (x < 0 || (x && !(x % 10))) return false;
    int n(0);
    while (x > n) n = (n * 10) + (x % 10), x /= 10;
    return (n == x || n/10 == x);
}

int main() {
    int x;
    while (~scanf("%d", &x)) printf("%s\n", reversedigit(x) ? "Yes" : "No");
}


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

int pos[2][2005];
int inv[2][2][2005][2005];
int S[2005][2005];

int main() {
  int n;
  cin >> n;
  for (int ni = 0; ni < n * 2; ni++) {
    char c;
    int a;
    cin >> c >> a;
    bool white = (c == 'W');
    pos[white][a] = ni;
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int ni = 1; ni <= n; ni++) {
        int cnt = 0;
        for (int nj = 1; nj <= n; nj++) {
          if (pos[i][ni] < pos[j][nj]) cnt++;
          inv[i][j][ni][nj] = cnt;
        }
      }
    }
  }
  S[0][0] = 0;
  for (int ni = 1; ni <= n; ni++) {
    S[ni][0] = S[ni - 1][0] + inv[0][0][ni][ni - 1];
    S[0][ni] = S[0][ni - 1] + inv[1][1][ni][ni - 1];
  }
  for (int ni = 1; ni <= n; ni++) {
    for (int nj = 1; nj <= n; nj++) {
      S[ni][nj] = min(S[ni - 1][nj] + inv[0][0][ni][ni - 1] + inv[0][1][ni][nj], S[ni][nj - 1] + inv[1][1][nj][nj - 1] + inv[1][0][nj][ni]);
    }
  }
  cout << S[n][n] << endl;
}


Measured memory_bytes: 78720
/* Tuan Kkura */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 1005

int n;
vector <int> DSK[MAXN];
int len[MAXN], trace[MAXN];

vector <int> Trace(int u)
{
    vector <int> S;
    while(u > 0)
    {
        S.pb(u);
        u = trace[u];
    }
    return S;
}

vector <int> BFS(int s)
{
    FOR(i, 1, n)
    {
        trace[i] = 0;
        len[i] = INT_MAX;
    }
    queue <int> Q;
    Q.push(s);
    len[s] = 0;
    while(!Q.empty())
    {
        int u = Q.front();
        Q.pop();
        REP(i, 0, DSK[u].size())
        {
            int v = DSK[u][i];
            if(v == s)
                return Trace(u);
            if(len[v] > len[u] + 1)
            {
                trace[v] = u;
                len[v] = len[u] + 1;
                Q.push(v);
            }
        }
    }
    vector <int> blank;
    return blank;
}

int vi[MAXN];
vii edges;

int main()
{
    _io
    int m; cin >> n >> m;
    FOR(i, 1, m)
    {
        int u, v;
        cin >> u >> v;
        edges.pb(mp(u, v));
        DSK[u].pb(v);
    }
    vector <int> res;
    res.resize(n+1);
    bool ok = false;
    FOR(i, 1, n)
    {
        fill(vi+1, vi+1+n, false);
        vector <int> tmp = BFS(i);
        if(tmp.size() == 0) continue;
        REP(j, 0, tmp.size())
            vi[tmp[j]] = 1;
        int cnt = 0;
        REP(j, 0, m)
            if(vi[edges[j].fi] == 1 && vi[edges[j].se] == 1)
                cnt++;
        //cout << i << ' ' << tmp.size() << ' ' << cnt << '\n';
        if(cnt > tmp.size())    continue;
        if(tmp.size() < res.size())
        {
            ok = true;
            res = tmp;
        }
    }
    if(!ok) return cout << -1, 0;
    cout << res.size() << '\n';
    REP(i, 0, res.size())
        cout << res[i] << '\n';
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{

    ll n;
    cin >> n;

    string s;
    cin >> s;

    ll result = 1;

    for (int i = 1; i < n; i++)
    {
        if(s[i] != s[i-1]){
            result++;
        }
    }

    cout << result << endl;

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

    // ll sum = 0;

    // ll result = 0;

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

    // for(int i= 0;i< n;i++){
    //     result += (sum - d[i]) * d[i];
    // }

    // cout << result / 2 << endl;
}


Measured memory_bytes: 512
package main

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

type edge struct {
	to    int
	value int
}

var edges [][]edge
var vertex []int
var visited []bool

func fillNumber(x int) {
	visited[x] = true
	for _, e := range edges[x] {
		if !visited[e.to] {
			vertex[e.to] = vertex[x] + e.value
			fillNumber(e.to)
		} else if vertex[e.to] != vertex[x]+e.value {
			fmt.Println("No")
			os.Exit(0)
		}
	}
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)

	if m == 0 || m == 1 {
		fmt.Println("Yes")
		return
	}

	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0, 32)
	}

	for i := 0; i < m; i++ {
		l, r, d := Int(in)-1, Int(in)-1, Int(in)
		edges[l] = append(edges[l], edge{to: r, value: d})
		edges[r] = append(edges[r], edge{to: l, value: -d})
	}

	vertex = make([]int, n)
	visited = make([]bool, n)

	for i := range visited {
		if !visited[i] {
			visited[i] = true
			fillNumber(i)
		}
	}
	fmt.Println("Yes")
}

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

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


Measured memory_bytes: 111360
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times {|i|yield(i)}                    end
def repl(st,en,n=1);       n*= -1 if st>en;st.step(en,n){|i|yield(i)} end

s = gs
a = s[0].split("").first
b = s[1].split("").first
c = s[2].split("").first
puts a+b+c

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,k,ans,a[505],b[505];
bool chk(int x)
{
    int cnt=0;
    for(int i=1;i<=n;i++)b[i]=a[i]%x;
    sort(b+1,b+1+n);
    for(int i=1,i0=n;i<i0;)
    {
        if(b[i]+b[i0]<x)b[i0]+=b[i],cnt+=b[i],b[i]=0,i++;
        else cnt+=x-b[i0],b[i]-=x-b[i0],b[i0]=0,i0--;
    }
    //printf("%d %d\n",x,cnt);
    return cnt<=k;
}
int main()
{
    scanf("%d %d",&n,&k);
    int sum=0;
    for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
    for(i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            if(chk(i))ans=max(i,ans);
            if(chk(sum/i))ans=max(sum/i,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#define int long long

signed main()
{
    int i=0, j=0, ans=0;
    
    int n, a, b;
    cin>>n>>a>>b;

    j=n/(a+b);
    ans=a*j;

    if(a+(a+b)*j<=n)
        ans+=a;
    else
        ans+=n-(a+b)*j;

    cout<<ans<<endl;

    return 0;
}

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

int main(){
    int N,n,k,total;
    cin >> N;
    n = N;
    while(N > 0){
        k = N % 10;
        total = total + k;
        N = N /10;
    }
    if (n % total == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define rep(i, N) for(int (i) = 0; (i) < (N); i++)
#define all(v) v.begin(), v.end()
using i64 = int_fast64_t;

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

    vector<int> B(1, 0);
    int del = 0;
    rep(i,N){
        if(A[i] > i+1 - del) del++;
        else B.emplace_back(A[i]);
    }

    int len = B.size();
    vector<vector<int>> dp(len, vector<int>(2, 0));

    for(int i = 1; i < B.size(); i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
        if(B[i] == dp[i-1][1]+1) dp[i][1] = B[i];
        if(B[i] == dp[i-1][0]+1) dp[i][1] = B[i];
    }

    int K = max(dp[len-1][0],dp[len-1][1]);


    if(K < 1) K = N+1;
    cout << N - K << endl;
}

Measured memory_bytes: 12788
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll N,x,ans=0;cin>>N>>x;
    vector<int> a(N,0);
    REP(i,N){
        cin>>a[i];
        if(a[i]>x){
            ans+=a[i]-x;
            a[i]=x;
        }
    }
    REP(i,N-1){
        if(a[i]+a[i+1]>x){
            ans+=(a[i]+a[i+1])-x;
            a[i+1]-=(a[i]+a[i+1])-x;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    int buka[n + 1];
    for(int i = 0; i < n + 1; i++){
        buka[i] = 0;
    }
    for(int i = 2; i < n + 1; i++){
        int a;
        cin >> a;
        buka[a] += 1;
    }

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

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

int main(){
	int n; cin >> n; n = 2 * n - 1;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	int lo = 1, hi = n, ans = 1;
	while(lo <= hi){
		int mid = (lo + hi)>>1;
		vector<int> b = a;
		for(int i = 0; i < n; i++) b[i] = b[i] >= mid;
		int i = n / 2, j = i;
		int found = -1;
		while(i > 0){
			if(b[i] == b[i - 1] || b[j] == b[j + 1]){
				found = b[i];
				break;
			}
			i--;
			j++;
		}	
		if(found == -1){
			if((n / 2 + 1) % 2) found = b[n / 2];
			else found = 1 ^ b[n / 2];
		}
		if(found) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) a.begin(),a.end()

const int MAX_N = 2e5;

int main(){
    int N, Q; cin >> N >> Q;
    vector<int> G[MAX_N];
    for(int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
    }
    //vector<pair<int,int>> P(Q);
    map<int,int> MP;
    for(int i = 0; i < Q; i++){
        int p, x; cin >> p >> x;
        p--;
        //P[i] = {p,x};
        MP[p] += x;
    }
    vector<int> ans(N,0);
    //sort(P.begin(),P.end());
    for(int i = 0; i < N; i++){
        //cout << e.first << " " << e.second << endl;
        ans[i] += MP[i];
        for(auto v: G[i]){
            ans[v] += ans[i];
        }
    }

    for(int i = 0; i < N; i++){
        if(i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

}

Measured memory_bytes: 23424
#include<stdio.h>

int main(){
    int n;
    int numbers[200];
    int i,j,k;
    int counter = 0;
    int flag = 0;

    scanf("%d", &n);

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

    while(1){
        for (j = 0; j < n ; ++j){
            if (numbers[j] %2 == 1)
                flag = 1;
            
        }
        if (flag ==1)
            break;
        
        
        ++counter;

        for(k = 0; k < n; ++k){
                numbers[k] = numbers[k]/2;
            }
        
    }
    printf("%d", counter);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val S = sc.next()
    var num = 0

    for (i <- S){
      if (i == '+') {
        num += 1
      } else {
        num -= 1
      }
    }
    println(num)
  }
}

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


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sub1 = 0, sub2 = 0;
	rep(i, b) {
		int put;
		cin >> put;
		if (put < c) {
			sub1++;
		}
		else {
			sub2++;
		}
	}
	cout << min(sub1, sub2) << endl;

	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vi  g[100005]; 
int  ver, color[100005]; 
bool vis[100005];

map <pii,int> mp;

void dfs(int u){ 
	if (vis[u]) return; 
	vis[u] = true; 
	int c[sz(g[u])]; 
	for (int i=1,k=0;i<=sz(g[u]);i++){ 
		if (color[u] != i) c[k++]=i; 
	} 
	int k=0; 
	for (auto &it: g[u]){ 
		if (!vis[it]){ 
			mp[{u,it}] = c[k] ; 
			mp[{it,u}] = c[k] ; 
			color[it] = c[k] ; 
			dfs(it) ; 
			k++;
		} 
	} 
} 


signed main() 
{ 
	int color=0;
    cin >> ver ; 
    int a[ver],b[ver];
    for (int i=1;i<ver;i++){ 
    	cin >> a[i] >> b[i] ; 
    	g[a[i]].pb(b[i]) ; 
    	g[b[i]].pb(a[i]) ; 
    	color = max(color,sz(g[a[i]]));
    } 
    dfs(1); 
    cout << color << endl; 
    for (int i=1;i<ver;i++){ 
    	cout << mp[{a[i],b[i]}] << endl; 
    } 
    return 0; 
} 


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

#define UNIQUE(xs) sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end());

typedef long long ll;

int G[4040][4040];

int main() {

  int N; cin >> N;
  vector<int> xs, ys;
  vector<int> inx[2], iny[2];
  rep(i, 2) inx[i].resize(N), iny[i].resize(N);
  rep(i, N) {
    scanf("%d%d%d%d", &inx[0][i], &iny[0][i], &inx[1][i], &iny[1][i]);
    xs.push_back(inx[0][i]), xs.push_back(inx[1][i]);
    ys.push_back(iny[0][i]), ys.push_back(iny[1][i]);
  }

  auto lp = [&](vector<int>& xs, int x) {
    return lower_bound(all(xs), x) - xs.begin();
  };

  UNIQUE(xs);
  UNIQUE(ys);

  const int CMaxX = xs.size(), CMaxY = ys.size();

  rep(i, N) {
    G[lp(ys, iny[0][i])][lp(xs, inx[0][i])]++;
    G[lp(ys, iny[0][i])][lp(xs, inx[1][i])]--;
    G[lp(ys, iny[1][i])][lp(xs, inx[0][i])]--;
    G[lp(ys, iny[1][i])][lp(xs, inx[1][i])]++;
  }

  rep(i, CMaxY + 1)
    REP(j, 1, CMaxX + 1)
      G[i][j] += G[i][j - 1];

  REP(i, 1, CMaxY + 1)
    rep(j, CMaxX + 1)
      G[i][j] += G[i - 1][j];

  ll ans = 0;

  rep(y, ys.size() - 1) rep(x, xs.size() - 1) {
    if(G[y][x])
      ans += (ll)(ys[y + 1] - ys[y]) * (xs[x + 1] - xs[x]);
  }

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

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()
#define prev asdasd

const int MAXN = 2 * 105000;

class SegmentTree {
private: 
  const long long INF = 1e18;
  vector<long long> tree;
  int n;
public:
  void init(int sz) {
    n = 1;
    while (n < sz) {
      n *= 2;
    }
    tree.assign(2 * n, -INF);
  }

  // l, r are in [0, n - 1]
  long long getMax(int l, int r) {
    l = n + l; r = n + r;
    long long res = -INF;
    
    while (l <= r) {
      if (l & 1) {
        res = max(res, tree[l]);
        l++;
      }
      if (r % 2 == 0) {
        res = max(res, tree[r]);
        r--;
      }
      l /= 2; r /= 2;
    }

    return res;
  }

  // pos is in [0, n - 1]
  void update(int pos, long long val) {
    pos = n + pos;
    tree[pos] = val;
    pos /= 2;
    while (pos >= 1) {
      tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
      pos /= 2;
    }
  }
};

int n;
int a[MAXN];
vector<int> g[MAXN];
int ans[MAXN];
SegmentTree tree;

void go(int v, int prevAns, int par = -1) {
    int best = 1;
    if (a[v] > 0)
        best = max(1ll * best, tree.getMax(0, a[v] - 1) + 1);
    ans[v] = max(best, prevAns);

    long long prev = tree.getMax(a[v], a[v]);
    if (best > prev) {
        tree.update(a[v], best);
    }

    for (int to : g[v]) {
        if (to == par) continue;
        go(to, ans[v], v);
    }

    tree.update(a[v], prev);
}

int main() {

    scanf("%d", &n);
    for (int i = 0; i < n; i++) 
        scanf("%d", &a[i]);

    for (int i = 0; i < n - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    vector<int> v;
    for (int i = 0; i < n; i++) 
        v.push_back(a[i]);
    sort(all(v));
    for (int i = 0; i < n; i++)
        a[i] = lower_bound(all(v), a[i]) - v.begin();

    tree.init(n);
    go(0, 0);

    for (int i = 0; i < n; i++) 
        printf("%d\n", ans[i]);

    return 0;
}


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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int a[m];
	int asum = 0;
	for( int i=0; i<m; i++ ){
		cin >> a[i];
		asum += a[i];
	}

	if( asum > n )	cout << "-1" << endl;
	else	cout << n - asum << endl;

	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s,t;
	getline(cin,t);
    getline(cin,s);
    int m = s.length(),n=t.length(),i,j;
    vector<vector<int>> lcs(m+1,vector<int>(n+1,0)) ;
    for(i=1;i<m+1;i++){
    	for(j=1;j<n+1;j++){
    		if(s[i-1]==t[j-1])
    			lcs[i][j]=1+lcs[i-1][j-1];
    		else
    			lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
    	}
    }
    s="";
    i=m;j=n;
    while(lcs[i][j]!=0){
    			if(lcs[i-1][j]==lcs[i][j]) i--;
        		else if (lcs[i][j-1]==lcs[i][j]) j--;
        		else{
        			s=t[j-1]+s;
        			i--;j--;
        		}
    	}
    cout << s;
}


Measured memory_bytes: 35584
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ll dpmax[100001];
ll dpmin[100001];
ll K;
ll a[100001];


int main (){
      cin>>K;
      rep1(i,K) cin>>a[i];
      dpmin[K]=2;
      dpmax[K]=2;
      for(int i=K;i>=1;i--){
            if((dpmax[i]/a[i])==(dpmin[i]/a[i])&&dpmax[i]%a[i]!=0&&dpmin[i]%a[i]!=0){
                  cout<<-1<<endl;
                  return 0;
            }
            dpmax[i-1]=(dpmax[i]/a[i])*a[i]+a[i]-1;
            dpmin[i-1]=((dpmin[i]+a[i]-1)/a[i])*a[i];
      }
      cout<<dpmin[0]<<" "<<dpmax[0]<<endl;

      return 0;
}


Measured memory_bytes: 2560
#N=3485
#A=[ 32, 1, 87, 25, 36]
N=int(input())


for i in range(1,3501):
    for j in range(1,3501):
        u=-N*i*j
        d=N*i+N*j-4*i*j
        if(d!=0):
            if(u%d==0 and (u*d > 0)):
                k=u//d
                if(N*(i*j+j*k+k*i)==4*i*j*k):
                    print(i,j,k)
                    exit()

Measured memory_bytes: 40684
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int h,w,k;
	cin>>h>>w>>k;
	vvl dp(h+1,vl(w,0ll));
	dp[0][0]=1;
	rep(i,h){
	    rep(s,1<<(w-1)){
	        bool ok=true;
	        rep(j,w-2){
	            ok&=((s&(3<<j))!=(3<<j));
	        }
	        if(!ok)continue;
//	        cout<<bitset<7>(s).to_string()<<endl;
    	    rep(j,w){
    	        if(j>0 and s&(1<<(j-1))){
    	            dp[i+1][j-1]+=dp[i][j];
    	        }else if(j<w-1 and s&(1<<(j))){
    	            dp[i+1][j+1]+=dp[i][j];
    	        }else{
        	        dp[i+1][j]+=dp[i][j];
    	        }
    	    }
	    }
	    rep(j,w)dp[i+1][j]%=MOD;
	}
	cout<<dp[h][k-1]<<endl;
	//for(auto&l:dp)cout<<l<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    ans += a - 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define nil -1
#define max 251
typedef struct{
  int key;
  int parent;
  int right;
  int left;
} node;
int parent(int);
int left(int);
int right(int);
void PrintData(void);
int H;
node data[max];

int main()
{
  int i;

  scanf("%d",&H);

  for(i = 0 ; i < H + 1 ; i++){
    data[i].parent = nil;
    data[i].right = nil;
    data[i].left = nil; }
  
  for(i = 1 ; i < H + 1 ; i++){
    scanf("%d",&data[i].key);
    if(i != 1) data[i].parent = parent(i); 
    if(left(i) < H + 1) data[i].left = left(i);
    if(right(i) < H + 1) data[i].right = right(i); }
  
  PrintData();
  
  return 0;
}

int parent(int i)
{
  return i/2;
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i + 1;
}

void PrintData(void)
{
  int i;	

  for(i = 1 ; i < H + 1 ; i++){ 
    printf("node %d: key = %d, ",i, data[i].key);
    if(data[i].parent != nil) printf("parent key = %d, ",data[data[i].parent].key);
    if(data[i].left != nil) printf("left key = %d, ",data[data[i].left].key);
    if(data[i].right != nil) printf("right key = %d, ",data[data[i].right].key);
    printf("\n"); }
     
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s){
    TSTART();

    replace(ALL(s),',',' ');
    cout << s << endl;
    TSTOP();
  }
    return 0;
}



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

constexpr int INF = 1e9;

int main() {
    vector<int> w = {2, 3, 5}, v = {380, 550, 850};
    vector<int> dis = {20, 15, 12}, dis_cnt = {5, 4, 3};
    vector<vector<int>> dp(4, vector<int>(51, INF));
    dp[0][0] = 0;
    for(int i=0; i<3; ++i) {
        for(int j=50; j>=0; --j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            for(int k=1; k<=(50-j+w[i]-1)/w[i]; ++k) {
                int next = min(50, j+w[i]*k);
                dp[i+1][next] = min(dp[i+1][next], dp[i][j]+(v[i]*dis_cnt[i])*(k/dis_cnt[i])*(100-dis[i])/100+v[i]*(k%dis_cnt[i]));
            }
        }
    }
    int n;
    while(cin >> n, n) {
        n /= 100;
        cout << dp[3][n] << endl;
    }
}


Measured memory_bytes: 3084
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
    }
    let s = s
        .into_iter()
        .map(|ch| ch.to_string().parse::<isize>().unwrap())
        .collect::<Vec<isize>>();
    let mut min = std::isize::MAX;
    for i in 0..s.len() - 2 {
        let num: isize = s[i] * 100 + s[i + 1] * 10 + s[i + 2];
        // eprintln!("{}", num);
        let num = (num - 753).abs();
        // eprintln!("{}", num);
        min = cmp::min(min, num);
    }
    println!("{}", min);
}


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

using namespace std ;

const int MAXN = 210 , MAXK = 11;
const int MAXDP = (1ll << (MAXK-1)) ;

vector< vector< pair<int , long long> > >adj(MAXN) ;
int n , m , k ;

long long dist[MAXN][MAXN] , d[MAXN] , dp[MAXN][MAXDP];
int arr[MAXN] ;

void dijkstra(int src)
{
	for(int i = 1 ; i <= n ; ++i)
		d[i] = INT_MAX ;
	priority_queue< pair<long long , int> , vector< pair<int , int> > , greater< pair<int , int> > >q ;
	q.push({0ll , src}) ;
	d[src] = 0ll ;
	while(!q.empty())
	{
		pair<long long , int>p = q.top() ;
		q.pop() ;
		int node = p.second ;
		long long cost = p.first ;
		if(cost > d[node])
			continue ;
		dist[src][node] = cost ;
		for(auto &to : adj[node])
		{
			int cur = to.first ;
			long long ncost = to.second + cost ;
			if(ncost < d[cur])
			{
				d[cur] = ncost ;
				q.push({ncost , cur}) ;
			}
		}
	}
	return ;
}

int solve(int idx , int mask)
{
	if(mask == (1 << k) - 1)
		return 0 ;
	long long &ret = dp[idx][mask] ;
	if(ret != -1)
		return ret ;
	ret = 1e15 ;
	for(int i = 0 ; i < k ; ++i)
	{
		if((mask & (1 << i)))
			continue ;
		ret = min(ret , solve(arr[i] , mask | (1 << i)) + dist[idx][arr[i]]) ;
	}
	return ret ;
}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	scanf("%d %d %d" , &n , &m , &k) ;
	for(int i = 0 ; i < k ; ++i)
		cin>>arr[i] ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		long long z ;
		scanf("%d %d %lld" , &x , &y , &z) ;
		adj[x].push_back({y , z}) ;
		adj[y].push_back({x , z}) ;
	}
	for(int i = 0 ; i < k ; ++i)
		dijkstra(arr[i]) ;
	return cout<<solve(1 , 0)<<"\n" , 0 ;
}

Measured memory_bytes: 2816
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for(int i = 0; i < 8; i++) {
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < s.length(); j++) {
                sb.append(s.charAt(j));
                if(j == s.length()-1) break;
                if((1 & i >> j) == 1) {
                    sb.append("+");
                } else {
                    sb.append("-");
                }
            }
            int sum = 0;
            String expression = sb.toString();
            for(int k = 0; k < expression.length(); k++) {
                if (expression.charAt(k) == '+') {
                    sum += (expression.charAt(k+1) - '0');
                    k++;
                } else if (expression.charAt(k) == '-') {
                    sum -= (expression.charAt(k+1) - '0');
                    k++;
                } else {
                    sum += expression.charAt(k) - '0';
                }
            }
            if(sum == 7) {
                System.out.println(expression + "=7");
                return;
            }
        }
    }
}


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

#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
bool isprime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res=((res%mod)*((n-i)%mod))%mod;res=((res%mod)*(power(i+1,mod-2))%mod)%mod;}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll sol=a>b?a:b;return sol;}
ll min(ll a,ll b){ll sol=a<b?a:b;return sol;}
////////////////////////////////////////////////////
int main()
{
   bolt;
   ll n;
   cin>>n;
   string s;
   cin>>s;
   for (ll i=0;s[i];i++)
   {
      s[i]+=n;
      if (s[i]>90)
         s[i]=s[i]-90-1+'A';
   }
   cout<<s;

}


Measured memory_bytes: 256
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << endl
template <class T>
using VV = vector<vector<T>>;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}
#pragma endregion

int main() {
  int N;
  cin >> N;
  vi L(N);
  cin >> L;
  sort(all(L));
  ll ans = 0;
  rep(i, N - 1) {
    rep2(j, i + 1, N) {
      int sum = L[i] + L[j]-1;
      int index = upper_bound(L.begin(), L.end(), sum) - L.begin();
      int tmp = max(index - j - 1, 0);
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  ll ans = 0;

  rep(i, K) {
    int t = 1;
    for(int j = i; j < N; j += K) {
      if(j+K >= N) {
        if(T[j] == 'r') ans += (t+1)/2*P;
        if(T[j] == 's') ans += (t+1)/2*R;
        if(T[j] == 'p') ans += (t+1)/2*S;
        break;
      }
      if(T[j] == T[j+K]) t++;
      else {
        if(T[j] == 'r') ans += (t+1)/2*P;
        if(T[j] == 's') ans += (t+1)/2*R;
        if(T[j] == 'p') ans += (t+1)/2*S;
        t = 1;
      } 
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int a[11][11];
int main()
{
	int n,d,cnt=0;
	cin>>n>>d;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=d;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n-1;i++)
		for(int j=i+1;j<=n;j++)
		{
			double p=0;
			int dd=0;
			for(int k=1;k<=d;k++)
			{
				dd=a[i][k]-a[j][k];
				p+=pow(dd,2);
			}
			p=sqrt(p);
			if(floor(p)==p)	
				cnt++;
		}
	cout<<cnt;
	return 0;
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

void panic() {
	cout << "-1\n";
	exit(0);
}

int main() {
	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}
	if (a[0]) {
		panic();
	}
	for (int i = 1; i < n; ++i) {
		if (a[i] > a[i - 1] + 1) {
			panic();
		}
	}

	for (int i = 0; i < n; ++i) {
		a[i] -= i;
	}

	long long ans = 0;
	vector<pair<int, int>> ev;
	for (int i = 0; i < n; ++i) {
		if (a[i] > -i && (i == n - 1 || a[i] != a[i + 1])) {
			ev.push_back({i - (a[i] + i - 1), 1});
			ev.push_back({i + 1, -1});
			// cerr << "[" << ev[(int)ev.size() - 2].first << ", " << ev.back().first << ")\n";
		}
	}

	sort(all(ev));
	int j = 0;
	int cur = 0;
	for (int i = 0; i < n; ++i) {
		while (j < (int)ev.size() && ev[j].first == i) {
			cur += ev[j++].second;
		}
		ans += cur;
	}

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

	return 0;
}

Measured memory_bytes: 7024
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(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 sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}

#define N 200005

void solve(){
    int x,n;
    cin >> x >> n;

    int i,a[n];
    map<int,int>mp;
    for(i=0; i<n; i++){
       cin >> a[i];
       mp[a[i]]++;
    }
    int j=0;
    while(1){
        if((x-j)>=0 && mp[x-j]==0){
            cout << x-j << '\n';
            return;
        }
        else if(mp[x+j]==0){
            cout << x+j << '\n';
            return;
        }
        j++;
    }

}




int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int tt;
        tt=1;
       // cin >> tt;
        while(tt--){
            solve();
        }
        

}

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

int main() {

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

    d = d * 2 + 1;
    if ( ( n % d ) == 0 ) {
        cout << n / d << endl;
    } else {
        cout << n / d + 1 << endl;
    }

    return 0;

}


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

int main()
{
	int n;
	cin >> n;
	vector<int> ps(n);
	for (auto &p : ps)
	{
		cin >> p;
	}

	int ans = 0;
	for (int i = 1; i < n - 1; i++)
	{
		vector<int> as;
		for (int j = -1; j <= 1; j++)
		{
			as.emplace_back(ps[i + j]);
		}
		sort(as.begin(), as.end());
		if (as[1] == ps[i])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

bool tbl[50000];

int main(void) {
        memset(tbl, 0, sizeof(tbl));
        int n,m,t;
        int a;
        scanf("%d%d%d",&n,&m,&t);
        for(int i=0; i<n; i++){
            scanf("%d",&a);
            a--;
            for(int j=0; j<m; j++)
                tbl[a-j] = tbl[a+j] = true;
            tbl[a+m] = true;
        }
        int res=0;
        for(int i=0; i<t; i++)
            res += !tbl[i];
        printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 2712