akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = zip(*sorted(zip(m,m)))
    
    over = [-1]*N
    tmp=0
    for i in range(N):
      while(tmp<N and X[i]+D*2>=X[tmp]):
        tmp += 1
      over[i] = tmp
    reset = [0]*N
    
    ans = 0
    dam = 0
    for i in range(N):
      if i>0:
        reset[i] += reset[i-1]
      hp = H[i]-dam+reset[i]
      if hp > 0:
        bomb = (hp+A-1)//A
        ans += bomb
        dam += bomb * A
        if(over[i]<N):
          reset[over[i]] += bomb * A

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 53592
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define NUM_MAX 200000
#define DIVISOR 1000000007

struct pair {
    int x;
    int y;
};

static uint64_t factorial[NUM_MAX*2+1];
static uint64_t inv_factorial[NUM_MAX*2+1];

struct pair gcdext(int a, int b) {
    if(a == 0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y - (b/a)*p.x, p.x};
}

void prep_factorial(int n) {
    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;
    int i;
    for(i = 2; i <= n; i++) {
        factorial[i] = (factorial[i-1] * i)%DIVISOR;
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1] * inv)%DIVISOR;
    }
    return;
}

uint64_t get_combi(int n, int k) {
    uint64_t res = factorial[n];
    res = (res * inv_factorial[k])%DIVISOR;
    res = (res * inv_factorial[n-k])%DIVISOR;
    return res;
}

uint64_t get_homog(int n, int k) {
    return get_combi(n+k-1, k);
}

int main(void) {
    int n, k;
    get_int2(&n, &k);
    if(k>=n-1) k = n-1;
    prep_factorial(n*2);
    int i;
    uint64_t ans = 0;
    for(i = 0; i <= k; i++) {
        int rem = n - i;
        // rem: splits
        // n-rem: balls(0-indexed)
        uint64_t res = get_homog(rem, n-rem);
        res = (res * get_combi(n, i))%DIVISOR;
#ifdef DEBUG
        printf("%d: %llu\n", i, res);
#endif
        ans = (ans + res)%DIVISOR;
    }
    printf("%d\n", (int)ans);
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
#define binom(x,y) (((fact[(x) + (y)] * fact_inv[x])%MOD * fact_inv[y])%MOD)

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2) return (a*pow(a,b-1))%MOD;
	else return pow((a*a)%MOD,b/2);
}
ll inv(ll a){ return pow(a, MOD-2); }

int main(){
	vector<ll> fact(1e6); fact[0] = 1;
	for(ll i = 1; i < fact.size(); i++) fact[i] = (fact[i-1] * i) % MOD;
	vector<ll> fact_inv(1e6); fact_inv[fact_inv.size()-1] = inv(fact[fact.size()-1]);
	for(ll i = fact_inv.size() - 2; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % MOD;

	ll h,w,n; cin >> h >> w >> n;
	vector<pair<ll,ll> > traps(n);
	for(auto &p: traps) cin >> p.first >> p.second, p.first--, p.second--;
	traps.emplace_back(h-1,w-1);
	sort(begin(traps),end(traps));
	vector<ll> dp(n+1);
	for(ll i = 0; i < n+1; i++){
		dp[i] = binom(traps[i].first, traps[i].second);
		for(ll j = 0; j < i; j++){
			if(traps[i].second < traps[j].second) continue;
			dp[i] -= (dp[j] * binom(traps[i].first - traps[j].first, traps[i].second - traps[j].second))%MOD;
			dp[i] %= MOD;
		}
	}
	cout << (dp[n]+MOD)%MOD << endl;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 880000
using namespace std;
int tree[N],flag[N],n,m;
struct node{
	int x,y;
}a[N];
inline bool cmp(node x,node y){
	return (x.x<y.x or(x.x==y.x and x.y<y.y))?true:false;
}
inline void update(int p){
	tree[p]=max(tree[p<<1],tree[p<<1|1]);
}
inline void pushdown(int p){
	if(flag[p]==0) return ;
	tree[p<<1]+=flag[p];
	flag[p<<1]+=flag[p];
	tree[p<<1|1]+=flag[p];
	flag[p<<1|1]+=flag[p];
	flag[p]=0;
}
void build(int p,int l,int r){
	if(l==r){
		tree[p]=l;flag[p]=0;return ;
	}
	int mid=(l+r)/2;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	update(p);
}
void change(int p,int l,int r,int ql,int qr,int x){
	if(ql>qr) return ; 
	if(ql<=l and r<=qr){
		tree[p]+=x;flag[p]+=x;return ;
	}
	pushdown(p);
	int mid=(l+r)/2;
	if(ql<=mid) change(p<<1,l,mid,ql,qr,x);
	if(mid<qr) change(p<<1|1,mid+1,r,ql,qr,x);
	update(p);
}
int query(int p,int l,int r,int ql,int qr){
	if(ql>qr) return 0;
	if(ql<=l and r<=qr) return tree[p];
	pushdown(p);
	int mid=(l+r)/2;
	int ans=0;
	if(ql<=mid) ans=max(ans,query(p<<1,l,mid,ql,qr));
	if(mid<qr) ans=max(ans,query(p<<1|1,mid+1,r,ql,qr));
	return ans;
}
void print(int p,int l,int r){
	if(l==r){
		printf("%d ",tree[p]);return ;
	}
	int mid=(l+r)/2;
	pushdown(p);
	print(p<<1,l,mid);
	print(p<<1|1,mid+1,r);
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	build(1,1,m);
	int ans=max(0,n-m);
	for(int i=1;i<=n;++i){
		if(max(a[i].x+1,1)<a[i].y)
		change(1,1,m,max(a[i].x+1,1),m,1),
		change(1,1,m,a[i].y,m,-1);
		ans=max(ans,query(1,1,m,max(a[i].x+1,1),m)-max(a[i].x,0)-m);
//		print(1,1,m);
//		printf("%d %d %d\n",a[i].x,a[i].y,ans);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[220000][3];
void chmax(int &a,int b){
	if(a < b)a = b;
}
signed main(){
	int n,k;cin >> n>> k;
	vector<int> p(3);
	rep(i,3)cin >> p[i];
	string s;cin >> s;
	vector<int> d(n);
	rep(i,n){
		if(s[i] == 'r')d[i] = 0;
		else if(s[i] == 's')d[i] = 1;
		else d[i] = 2;

	}
	auto win = [&](int x){
		return (x+2)%3;
	};
	rep(i,n)rep(j,3){
		rep(l,3){
			if(l == j)continue;
			if(l == win(d[i]))chmax(dp[i+k][l],dp[i][j] + p[l]);
			else chmax(dp[i+k][l],dp[i][j]);
		}
	}
	int ret = 0;
	for(int i = n;i < n+k;i++){
		int tmp = 0;
		rep(j,3){
			// trace(i,j,dp[i][j]);
			tmp = max(tmp,dp[i][j]);
		}
		ret += tmp;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 6652
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>> dp(m+1,vector<ll>((1<<n),INF));
    vector<ll> key(m),cost(m);
    ll a,b,c;
    rep(i,m){
        cin >> a >> b;
        ll can = 0;
        rep(j,b){
            cin >> c;
            --c;
            can |= (1<<c);
        }
        key[i] = can;
        cost[i] = a;
    }
    dp[0][0] = 0;
    rep(i,m){
        rep(j,(1<<n)){
            chmin(dp[i+1][j|key[i]],dp[i][j]+cost[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    if (dp[m][(1<<n)-1] == INF) PRINT(-1);
    else PRINT(dp[m][(1<<n)-1]);
}


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

//AtCoder ABC 77

using namespace std;

#define int long long
#define all(m) m.begin(),m.end()
#define all_mas(m) for(auto &i: m) cout << i  << " ";\
cout << endl;
#define fast ios::sync_with_stdio(0), cin.tie(), cout.tie()

signed main() {
    int n;
    cin >> n;
    vector <int> a (n), b = a, c = a;
    for (auto &i: a)
        cin >> i;
    for (auto &i: b)
        cin >> i;
    for (auto &i: c)
        cin >> i;
    sort(all(a));
    sort(all(b));
    sort(all(c));
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int pos1 = lower_bound(all(a), b[i]) - a.begin();
        int pos3 = upper_bound(all(c), b[i]) - c.begin();
        //cout << pos1 << ' ' << pos3 << endl;
        ans+=(n-pos3)*(pos1);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 2010
#define S 0
#define T 2001
#define red(x) (x)
#define blue(x) (n+(x))
#define id(x) (2002+(x))
#define int long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,p[N],d[N],q[N],pre[N],t=-1,ans;
bool flag[N];
struct data{int x,y,c,v[4];
}a[N],b[N];
struct data2{int to,nxt,cap,flow,cost;
}edge[N<<5];
void addedge(int x,int y,int z,int cost)
{
	t++;edge[t].to=y,edge[t].nxt=p[x],edge[t].cap=z,edge[t].flow=0,edge[t].cost=cost,p[x]=t;
	t++;edge[t].to=x,edge[t].nxt=p[y],edge[t].cap=0,edge[t].flow=0,edge[t].cost=-cost,p[y]=t;
}
int inc(int &x){x++;if (x>2007) x-=2007;return x;}
bool spfa()
{
	memset(d,60,sizeof(d));d[S]=0;
	memset(flag,0,sizeof(flag));
	int head=0,tail=1;q[1]=S;
	do
	{
		int x=q[inc(head)];flag[x]=0;
		for (int i=p[x];~i;i=edge[i].nxt)
		if (edge[i].flow<edge[i].cap&&d[x]+edge[i].cost<d[edge[i].to])
		{
			d[edge[i].to]=d[x]+edge[i].cost;
			pre[edge[i].to]=i;
			if (!flag[edge[i].to]) q[inc(tail)]=edge[i].to,flag[edge[i].to]=1;
		}
	}while (head!=tail);
	return d[T]<10000000000000000ll;
}
void ekspfa()
{
	while (spfa())
	{
		int v=n;
		for (int i=T;i!=S;i=edge[pre[i]^1].to)
		v=min(v,edge[pre[i]].cap-edge[pre[i]].flow);
		for (int i=T;i!=S;i=edge[pre[i]^1].to)
		edge[pre[i]].flow+=v,edge[pre[i]^1].flow-=v,ans+=v*edge[pre[i]].cost;
	}
}
signed main()
{
	n=read();memset(p,255,sizeof(p));
	for (int i=1;i<=n;i++) 
	{
		a[i].x=read(),a[i].y=read(),a[i].c=read();
		a[i].v[0]=a[i].x+a[i].y;
		a[i].v[1]=a[i].x-a[i].y;
		a[i].v[2]=-a[i].x+a[i].y;
		a[i].v[3]=-a[i].x-a[i].y;
	}
	for (int i=1;i<=n;i++)
	{
		b[i].x=read(),b[i].y=read(),b[i].c=read();
		b[i].v[0]=-b[i].x-b[i].y;
		b[i].v[1]=-b[i].x+b[i].y;
		b[i].v[2]=b[i].x-b[i].y;
		b[i].v[3]=b[i].x+b[i].y;
	}
	for (int i=1;i<=n;i++)
	{
		addedge(S,red(i),a[i].c,0),addedge(blue(i),T,b[i].c,0);
		for (int j=0;j<4;j++)
		addedge(red(i),id(j),a[i].c,-a[i].v[j]),addedge(id(j),blue(i),b[i].c,-b[i].v[j]);
	} 
	ekspfa();
	cout<<-ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//绝对值四种形态 取其中的max
//每个点在四种里选一个 最终使两堆点的每种个数相同即可
//

Measured memory_bytes: 1280
H, N = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
    if dp[i] == -1:
        continue
    for j in range(N):
        k = min(i+A[j], H)
        if dp[k] == -1:
            dp[k] = dp[i]+B[j]
        else:
            dp[k] = min(dp[k], dp[i]+B[j])

print(dp[H])

Measured memory_bytes: 42588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

template<class SIGNED_T>
class union_find {
private:
    vector<SIGNED_T> parent;
public:
    union_find(SIGNED_T n) : parent(n, -1) {}
    ~union_find() {}
    void link(SIGNED_T x, SIGNED_T y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (parent[x] > parent[y])
            swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
    }
    SIGNED_T find(SIGNED_T x) {
        if (parent[x] < 0)
            return x;
        return parent[x] = find(parent[x]);
    }
    SIGNED_T count(SIGNED_T x) {
        return -parent[find(x)];
    }
    bool linked(SIGNED_T x, SIGNED_T y) {
        return find(x) == find(y);
    }
};

signed main()
{
    int N, M; cin >>N>>M;
    vector<int> A(M), B(M);
    rep(i, M) cin >> A[i] >> B[i];

    union_find<ll> uf(N+1);
    vector<ll> ans;
    ans.push_back((ll)N*(N-1)/2);
    for (int i = M-1; i >= 0; i--) {
        if (uf.linked(A[i], B[i])) {
            ans.push_back(ans.back());
        } else {
            ll ca = uf.count(A[i]);
            ll cb = uf.count(B[i]);
            ans.push_back(ans.back()-ca*cb);
            uf.link(A[i], B[i]);
        }
    }
    for (int i = M-1; i >= 0; i--) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3828
//encoding:utf-8
// #include<iostream> //c++
// #include<time.h> //時間にかんして
// #include<stack> //スタックに関して　最新のデータから捨てる
// #include<queue> //キューに関して　最古のデータから捨てる
// #include<math.h>
// #include<vector>
// #include<algorithm> //sort とかにいる
#include<bits/stdc++.h>
#define int long long //int　宣言をlong longとする

using namespace std;
// int inf = INFINITY;
signed main(){
  int N;
  cin>>N;
  int A[N],B[N],C[N];//これはリスト
  //v()を使いたいなvector

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

  sort(A,A+N);
  sort(B,B+N);
  sort(C,C+N);

  int sum = 0;
  for(int i=0;i<N;i++){
    auto itr1 = lower_bound(A,A+N,B[i]);
    int a = itr1-A;
    // cout<<a<<endl;

    auto itr2 = upper_bound(C,C+N,B[i]);
    int c = C+N-itr2;
    // cout<<c<<endl;
    sum = sum + c*a;
  }
  cout<<sum<<endl;


  return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using static System.Console;

namespace ABC121C
{
    static class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().SplitTryParseToList<long>();
            var a = new List<List<long>>();
            for (long i = 0; i < line[0]; i++)
            {
                a.Add(ReadLine().SplitTryParseToList<long>());

            }

            var aa = a.OrderBy(x => x[0]).ToList();
            long katta = 0;
            long kane = 0;
            int index = 0;
            while (katta < line[1])
            {
                var kau = (katta + aa[index][1] > line[1] ? line[1] - katta : aa[index][1]);
                kane += (kau * aa[index][0]);
                katta += kau;
                index++;
            }

            WriteLine(kane);

        }

        public static T TryParse<T>(this String input)
        {
            try
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                if (converter != null)
                {
                    return (T)converter.ConvertFromString(input);
                }
                else
                {
                    throw new InvalidCastException("");
                }
            }
            catch
            {
                throw new InvalidCastException(typeof(T) + " is not supported.");
            }
        }

        public static List<T> SplitTryParseToList<T>(this String input)
        {
            return input.Split().Select(n => n.TryParse<T>()).ToList();
        }

        public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2)
        {
            var t = list[index1];
            list[index1] = list[index2];
            list[index2] = t;
            return list;
        }

        public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list)
        {
            return list
                .GroupBy(i => i)
                .Where(g => g.Any())
                .Select(g => Tuple.Create(g.Key, g.Count()))
                .ToList();
        }
        public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list)
        {
            return list.OrderByDescending((x) => x.Item2).ToList();
        }
        public static List<T> ReadLineOne<T>(int n)
        {
            var list = new List<T>();
            foreach (var i in Enumerable.Range(1, n))
            {
                list.Add(Console.ReadLine().TryParse<T>());
            }
            return list;
        }
        public static void PrintAll<T>(this IEnumerable<T> list)
        {
            foreach (var i in list)
            {
                Console.Write($"{i} ");
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 34716
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i = 1; i <= n; i++){
            ans += i-1;
        }
        System.out.println(ans);
    }
}

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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char line[9];
		cin >> line;
		sort(line, line + 8);
		int mi = 0;
		int ma = 0;
		int ten = 10000000;
		for (int j = 0; j < 8; j++)
		{
			mi += ten * (line[j] - '0');
			ten /= 10;
		}
		ten = 10000000;
		for (int j = 7; j >= 0; j--)
		{
			ma += ten * (line[j] - '0');
			ten /= 10;
		}
		cout << ma - mi << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
function Main(inp) {
    var input = inp.split('\n').map(function(n) {
        return Number(n);
    });
    var N = input[0];
    var visited = new Array(N);
    var current = 1;
    var step = 1;
    var next = input[current];
    visited[current] = true;
    while (next !== 2) {
        current = next;
        next = input[current];
        if (visited[current]) {
            console.log(-1);
            return
        }
        visited[current] = true;
        step += 1;
    }
    console.log(step);
}

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


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

int main() {
  int N;
  cin >> N;
  if (N <= 599) return cout << 8 << "\n", 0;
  if (N <= 799) return cout << 7 << "\n", 0;
  if (N <= 999) return cout << 6 << "\n", 0;
  if (N <= 1199) return cout << 5 << "\n", 0;
  if (N <= 1399) return cout << 4 << "\n", 0;
  if (N <= 1599) return cout << 3 << "\n", 0;
  if (N <= 1799) return cout << 2 << "\n", 0;
  cout << 1 << "\n";
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> L(2*N);
    cin >> L;
    sort(L.begin(),L.end());
    int ans=0;
    for (int i=0;i<2*N;i+=2) ans+=L[i];
    cout << ans << '\n';
}

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

int main() {
	
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			int rem = x - (500 * i + 100 * j);
			if(rem >= 0 && rem / 50 <= c && rem % 50 == 0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
const int N = 200005;
int n, x[N], y[N], ansd = INT_MAX;
char d[N]; 
void solvelr()
{
	vector<int> a[N], b[N];
	for (int i = 0; i < n; ++i)
	{
		if (d[i] == 'L')
			a[y[i]].push_back(x[i]);
		else if (d[i] == 'R')
			b[y[i]].push_back(x[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		sort(a[i].begin(), a[i].end());
		sort(b[i].begin(), b[i].end());
	}
	for (int i = 0; i < N; ++i)
	{
		for (int xc: b[i])
		{
			auto it = upper_bound(a[i].begin(), a[i].end(), xc);
			if (it == a[i].end())
				continue;
			else
			{
				int d = *it - xc;
				d *= 5;
				ansd = min(ansd, d);
			}
		}
	}
}
void solveud()
{
	vector<int> a[N], b[N];
	for (int i = 0; i < n; ++i)
	{
		if (d[i] == 'U')
			a[x[i]].push_back(y[i]);
		else if (d[i] == 'D')
			b[x[i]].push_back(y[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		sort(a[i].begin(), a[i].end());
		sort(b[i].begin(), b[i].end());
	}
	for (int i = 0; i < N; ++i)
	{
		for (int yc: a[i])
		{
			auto it = upper_bound(b[i].begin(), b[i].end(), yc);
			if (it == b[i].end())
				continue;
			else
			{
				int d = *it - yc;
				d *= 5;
				ansd = min(ansd, d);
			}
		}
	}
}
bool cmp(pair<int, int> lhs, pair<int, int> rhs)
{
	return lhs.first < rhs.first;
}
void solve1()
{
	vector<pair<int, int> > a[2 * N];
	for (int i = 0; i < n; ++i)
	{
		int dif = x[i] - y[i];
		a[dif + 200000].push_back(make_pair(x[i], d[i]));
	}
	for (int i = 0; i < 2 * N; ++i)
	{
		int l = -1, r = -1, u = -1, d = -1;
		sort(a[i].begin(), a[i].end(), cmp);
		for (pair<int, int> p: a[i])
		{
			if (p.second == 'L')
			{
				if (u != -1)
					ansd = min(ansd, 10 * (p.first - u));
				l = p.first;
			}
			else if (p.second == 'R')
				r = p.first;
			else if (p.second == 'U')
				u = p.first;
			else if (p.second == 'D')
			{
				if (r != -1)
					ansd = min(ansd, 10 * (p.first - r));
				d = p.first;
			}
		}
	}
}
void solve2()
{
	vector<pair<int, int> > a[2 * N];
	for (int i = 0; i < n; ++i)
	{
		int dif = x[i] + y[i];
		a[dif].push_back(make_pair(x[i], d[i]));
	}
	for (int i = 0; i < 2 * N; ++i)
	{
		int l = -1, r = -1, u = -1, d = -1;
		sort(a[i].begin(), a[i].end(), cmp);
		for (pair<int, int> p: a[i])
		{
			if (p.second == 'L')
			{
				if (d != -1)
					ansd = min(ansd, 10 * (p.first - d));
				l = p.first;
			}
			else if (p.second == 'R')
				r = p.first;
			else if (p.second == 'U')
			{
				if (r != -1)
					ansd = min(ansd, 10 * (p.first - r));
				u = p.first;
			}
			else
				d = p.first;
		}

	}
}
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i] >> y[i] >> d[i];
	}
	solvelr();
	solveud();
	solve1();
	solve2();
	if (ansd == INT_MAX)
		cout << "SAFE" << '\n';
	else
		cout << ansd << '\n';
	return 0;
}

Measured memory_bytes: 20896
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

int main()
{
	int N, M, a0;
	scanf("%d %d", &N, &M);
	set<pair<int, int>> g;
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (!i) a0 = a;
		g.insert(make_pair(a, b));
	}
	int b = 0;
	for (auto e : g) {
		int n[100] = { 0 };
		auto h = g;
		h.erase(e);
		n[a0] = 1;
		for (int i = 0; i < 100; i++) {
			for (int j = 1; j <= N; j++) {
				if (!n[j]) continue;
				for (int k = 1; k < j; k++)
					if (h.find(make_pair(k, j)) != h.end())
						n[k] = 1;
				for (int k = j+1; k <=N; k++)
					if (h.find(make_pair(j,k)) != h.end())
						n[k] = 1;
			}
		}
		int t = 0;
		for (int j = 1; j <= N; j++)
			t += n[j];
		if (t < N) b++;
	}
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i=0; i<M; i++){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<bool> isVisited(N, false);

    vector<int> ans1, ans2;
    int s = 0;
    int t = G[0][0];

    ans1.push_back(s);
    ans2.push_back(t);
    isVisited[s] = isVisited[t] = true;
    while(true){
        bool flag1 = true;
        bool flag2 = true;
        for(int i : G[s]){
            if(!isVisited[i]){
                isVisited[i] = true;
                s = i;
                flag1 = false;
                ans1.push_back(s);
                break;
            }
        }
        for(int i : G[t]){
            if(!isVisited[i]){
                isVisited[i] = true;
                t = i;
                flag2 = false;
                ans2.push_back(t);
                break;
            }
        }
        if(flag1 && flag2) break;
    }
    reverse(ans1.begin(), ans1.end());
    cout << ans1.size() + ans2.size() << endl;
    for(auto i : ans1) cout << i + 1 << " ";
    for(auto i : ans2) cout << i + 1 << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 6972
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
string s;
cin>>s;
int n=size(s);
while(n--)
cout<<"x";
}
int main()
{
//code

fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

count = {}
rect = {}
for i in range(N):
    if A[i] in rect:
        rect[A[i]] += 1
    elif A[i] in count:
        rect[A[i]] = 2
    else:
        count[A[i]] = 1

if len(rect) < 1:
    ans = 0
else:
    x = max(rect)
    if rect[x] >= 4:
        ans = x * x 
    else:
        del rect[x]
        if len(rect) < 1:
            ans = 0
        else:
            y = max(rect)
            ans = x * y
print(ans)
        

Measured memory_bytes: 21832
#include <bits/stdc++.h>
using namespace std;
int calc(int x){
  int ret = 0;
  while(x % 100 == 0){
    x /= 100;
    ++ret;
  }
  return ret;
}

int main() {
  int D, N;cin >> D >> N;
  int cnt = 0, val = 0;
  while(cnt < N){
    ++val;
    if(calc(val) == D) ++cnt;
  }
  cout << val << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
    
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long int
    #define ull unsigned long long int
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vl vector<ll>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define viii vector<tuple<ll, ll, ll>>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define bs(l, h, k) equal_range(l, h, k);
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define IP(v1, v2) inner_product(all(v1), v2.begin(), (ll)0)
    
    const long double PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    #define N 100005   
        bool pal(string s){
            for(int i=0;i<=s.length()/2;i++){
                if(s[i]!=s[s.length()-i-1])return false;
            }
            return true;
        }
        int main() {
            fio;
            string s;
            cin>>s;
            string s1="",s2="";
            for(int i=0;i<s.length()/2;i++){
                s1+=s[i];
            }
            for(int i=s.length()/2+1;i<s.length();i++){
                s2+=s[i];
            }
            //cout<<s1<<" "<<s2<<el;
            if(pal(s)&&pal(s1)&&pal(s2))cout<<"Yes"<<el;
            else cout<<"No"<<el;

            return 0;
        }


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

using namespace std;

int main() {

	while (1) {
		int n, m;
		cin >> n >> m;

		if (n == 0 && m == 0) { return 0; }

		vector<int> c(m + 1);
		for (int i = 1; i <= m; i++) {
			cin >> c[i];
		}
		vector<int> x(n + 1);
		for (int i = 1; i <= n; i++) {
			cin >> x[i];
		}

		vector<vector<long long>> dp(n + 1, vector<long long>(256, 2000000000000));

			for (int j = 1; j <= m; j++) {
				dp[0][128] = 0;
			}
//		dp[1][128] = 1000000000;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= 255; j++) {

				for (int k = 1; k <= m; k++) {

					if (dp[i - 1][j] > 2000000000) { continue; }

					int tmp = j + c[k];
					if (tmp < 0) { tmp = 0; }
					if (tmp > 255) { tmp = 255; }

					dp[i][tmp] = min(dp[i][tmp], dp[i - 1][j] + (x[i] - tmp)*(x[i] - tmp));

				}
			}
		}
		long long res = 2000000000000;
		for (int i = 0; i <= 255; i++) {
			if (dp[n][i] < 2000000000) {
				res = min(res, dp[n][i]);
			}
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 43872
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e8;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int histEven[100001];
int histOdd[100001];

void solve()
{
    int N; cin >> N;

    vector<int> V(N+1);
    int v_max = 0;
    int v_min = INTINF;
    REP1(i, N)
    {
        int v; cin >> v;
        V[i] = v;
        if (i % 2 == 0) histEven[v]++;
        else if (i % 2 == 1) histOdd[v]++;
        v_max = max(v_max, v);
        v_min = min(v_min, v);
    }

    int h_e_max = 0;
    int h_e_max_2 = 0;
    int h_o_max = 0;
    int h_o_max_2 = 0;
    int h_e_argmax = 0;
    int h_e_argmax_2 = 0;
    int h_o_argmax = 0;
    int h_o_argmax_2 = 0;

    FOR(i, v_min, v_max+1)
    {
        if (h_e_max <= histEven[i])
        {
            h_e_argmax_2 = h_e_argmax;
            h_e_max_2 = h_e_max;
            h_e_max = histEven[i];
            h_e_argmax = i;
        }
        else if (h_e_max_2 <= histEven[i])
        {
            h_e_max_2 = histEven[i];
            h_e_argmax_2 = i;
        }

        if (h_o_max <= histOdd[i])
        {
            h_o_max_2 = h_o_max;
            h_o_argmax_2 = h_o_argmax;
            
            h_o_max = histOdd[i];
            h_o_argmax = i;
        }
        else if (h_o_max_2 <= histOdd[i])
        {
            h_o_max_2 = histOdd[i];
            h_o_argmax_2 = i;
        }
    }

    int ans0 = 0;
    int ans1 = 0;
    int ans2 = 0;
    
    REP1(i, N/2)
    {
        ans0 += (V[2*i  ] != h_e_argmax);
        ans0 += (V[2*i-1] != h_o_argmax);

        ans1 += (V[2*i  ] != h_e_argmax_2);
        ans1 += (V[2*i-1] != h_o_argmax );
        
        ans2 += (V[2*i  ] != h_e_argmax );
        ans2 += (V[2*i-1] != h_o_argmax_2);
    }
    cout << ((h_o_argmax != h_e_argmax) ? ans0 : min(ans1, ans2)) << endl;  
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

int main(){
  set<int,greater<int>> st;
  st.insert(1);
  int x; cin >>x;
  repa(i,2,x){
    li s=i*i;
    while(s<=x) {
      st.insert(s);
      s*=i;
    }
  }
  print(*st.begin());
}





Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, X[200] = { 0 }, a, b, c, d, Y[200];
	scanf("%d", &N);
	for (int i = 1; i <= N*(N - 1) / 2; i++) {
		scanf("%d %d %d %d", &a, &b, &c, &d);
		if (c == d) {
			X[a]++;
			X[b]++;
		}
		else if (c < d) {
			X[b] += 3;
		}
		else {
			X[a] += 3;
		}
	}
	int p = 1;
	for (int i = 1; i <= N; i++) {
		p = 1;
		//printf("%d\n", X[i]);
		for (int j = 1; j <= N; j++) {
			if (X[i] < X[j]) {
				p++;
			}
		}
		printf("%d\n", p);
	}
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
#define pb push_back

#define rep(i, n) for (int i=0;i<(n);++i)
#define rep2(i, s, n) for (int i=s;i<(n);++i)
#define rev(i, n) for (int i=(n);i>0;--i)
#define INF (1e9+1e9)

int main() {
    int a, b, c; cin>>a>>b>>c;
    if(a==b) cout << c << endl;
    else if(b==c) cout << a << endl;
    else cout << b  << endl;
                 
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,k,x,i,sum=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){scanf("%d",&x);int c=x<k-x?x:k-x;sum+=2*c;}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> d(n); for(int i = 0; i < n; i++) cin >> d[i];

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

    int ans = 0;
    for(int i = 0; i < d[n - 1]; i++) {
        auto itr = upper_bound(d.begin(), d.end(), i);
        int idx = itr - d.begin();
        if(idx == n / 2) ans++;
    }

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


Measured memory_bytes: 1024
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  rrep(i, 1, 4) {
    if (i == a || i == b) continue;
    Cout(i);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  
  vector<int> v;
  v.reserve(n);
  
  for (int i = 0; i < n; ++i) {
    int coord;
    cin >> coord;
    v.push_back(coord);
  }
    
  int ans;
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    int diff = x - *itr;
    if (itr == v.begin()) {
      ans = diff;
    } else {
      ans = __gcd(ans, diff);
    }
  }
    
  cout << abs(ans) << "\n";
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define mp make_pair

int main(){
    int n,l;
    while(cin>>n>>l && n){
        typedef pair<int,pair<char,int>> P;
        vector<P> v(n);
        int t=-1;
        rep(i,n){
            char d; int p;
            cin>>d>>p;
            v[i]=mp(p,mp(d,i+1));
            t=max(t, (d=='L' ? p : l-p));
        }
        int ans;
        while(1){
            rep(i,v.size()){
                if(v[i].second.first=='L')v[i].first--;
                else v[i].first++;
            }
            auto it=remove_if(v.begin(),v.end(),[l](const P& a){
                    return a.first==0 || a.first==l;
                });
            v.erase(it,v.end());
            if(v.size()==0)break;
            sort(v.begin(),v.end());
            // rep(i,v.size()){
            //     printf("(%c %d %d) ", v[i].second.first,v[i].first,v[i].second.second);
            // }
            // puts("");
            ans=v.front().second.second;
            rep(i,v.size()-1){
                if(v[i].first==v[i+1].first){
                    swap(v[i].second.second,v[i+1].second.second);
                }
            }
        }
        cout << t << " " << ans << endl;
    }
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

vector<long long> d(100010);

int main(){
    int n, q, a, b, c;
    cin >> n;
    long long ans = 0;
    rep(i,n){
        cin >> a;
        d[a]++;
        ans += a;
    }
    cin >> q;
    rep(i,q){
        cin >> b >> c;
        ans -= d[b] * b;
        ans -= d[c] * c;
        d[c] += d[b];
        d[b]= 0;
        ans += d[c] * c;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3884
h,w=map(int,input().split())
s=[input() for _ in range(h)]
yoko_map=[[0 for i in range(w)] for j in range(h)]
tate_map=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
    p=0
    s_=s[i]
    s_=s_.split('#')
    for x in s_:
        num=len(x)
        for j in range(num):
            yoko_map[i][p]=num
            p+=1
        p+=1
for i in range(w):
    p=0
    s_=''.join([s__[i] for s__ in s])
    s_=s_.split('#')
    for x in s_:
        num=len(x)
        for j in range(num):
            tate_map[p][i]=num
            p+=1
        p+=1
m=0
for i in range(h):
    yoko_=yoko_map[i]
    tate_=tate_map[i]
    for j in range(w):
        m=max(m,tate_[j]+yoko_[j])
print(max(0,m-1))

Measured memory_bytes: 126552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
int A[1001001];

void solve() {
    cin >> N;
    for (int i = 0; i < N - 1; ++i) {
        int a;
        cin >> a;
        A[a] += 1;
    }
    for (int i = 1; i <= N; ++i) {
        cout << A[i] << endl;
    }
}

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


Measured memory_bytes: 4348
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <iostream>
#include <deque>
#define  N 100005
#define  ul unsigned long long
#define  ll long long int
#define  loop0(i,a,b) for(int i = a;i<b;++i)
#define  loop1(i,a,b) for(int i = a;i<=b;++i)
#define  ini0(i,b) for(int i = b;i>=0;--i)
#define  ini1(i,b) for(int i = b-1;i>=0;--i)
#define  pl pair<ll,ll>
#define  pi pair<int,int>
#define  ff first
#define  ss second
#define  bg begin()
#define  ed end()

#define  READ freopen("input.txt","r",stdin);
#define  WRITE freopen("output.txt","w",stdout);

#define  test1(x) cout<<#x<<" : "<<x<<endl;   
#define  test2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define  test3(x,y,z) cout<<#x<<" : "<<x<<"   "<<#y<<" : "<<y<<"  "<<#z<<" : "<<z<<endl;


int bgval(int n, int a)
{
	int rt = n / a;
	if (n%a != 0) rt++;
	return rt;
}


using namespace std;

map<string, int> mp;

ll phi(ll n)
{
	ll result = n; // Initialize result as n 

	// Consider all prime factors of n and subtract their 
	// multiples from result 
	for (ll p = 2; p * p <= n; ++p) {

		// Check if p is a prime factor. 
		if (n % p == 0) {

			// If yes, then update n and result 
			while (n % p == 0)
				n /= p;
			result -= result / p;
		}
	}

	// If n has a prime factor greater than sqrt(n) 
	// (There can be at-most one such prime factor) 
	if (n > 1)
		result -= result / n;
	return result;
}

bool isprime(ll n) {
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	//cin >> t;
	while (t--)
	{
		int n,k=0;
		cin >> n;
		vector<ll> vc(n,0), dp(n,INT_MAX);
		for (auto &it : vc) cin >> it;
		dp[0] = 0;
		for (int i = 1;i<n;i++)
		{
			dp[i] = dp[i - 1] + abs(vc[i] - vc[i-1]);
			if (i-2>=0)
			{
				dp[i] = min(dp[i],dp[i - 2] + abs(vc[i] - vc[i - 2]));
			}
		}
		cout << dp[n - 1] << endl;
	
	}


	return 0;
}


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














int R;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> R;
	int ans = R * R;
	cout << ans << endl;
}







Measured memory_bytes: 256