akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cstring>
#include<algorithm>
#include<vector>
#define maxn 100005
#define ll long long
using namespace std;

int n,i,j,k;
ll ans,c[maxn],x[maxn],now;

ll dg(int l,int r){
	ll s;
	if (x[l]>=now) {s=x[r]-now,now=x[r];return s;}
	if (x[r]<=now) {s=now-x[l],now=x[l];return s;}
	if (c[l]>=c[r]) 
		c[l]+=c[r],s=dg(l,r-1),s+=x[r]-now,now=x[r];
	else c[r]+=c[l],s=dg(l+1,r),s+=now-x[l],now=x[l];
	return s;
}

int main(){
	scanf("%d%lld",&n,&now);
	for(i=1;i<=n;i++) scanf("%lld%lld",&x[i],&c[i]);
	printf("%lld",dg(1,n));
}

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>

using namespace std;

void read_data(int n, vector<set<int> > &to)
{
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    to[a].insert(b);
    to[b].insert(a);
  }

  return;
}

void unidir(vector<set<int> > &to, vector<int> &parent, vector<int> &depth)
{
  int d_cnt = 0;
  queue<int> q;
  q.push(1);
  parent[0] = -1;
  parent[1] = 0;
  depth[0] = d_cnt++;
  while(!q.empty()) {
    int node = q.front();
    q.pop();
    depth[node] = d_cnt++;
    for (auto it = to[node].begin(); it != to[node].end(); it++) {
      q.push(*it);
      parent[*it] = node;
      auto it2 = to[*it].find(node);
      if (it2 != to[*it].end()) {
        to[*it].erase(it2);
      }
    }
  }

  return;
}

class Comp {
 public:
  vector<int> &depth;

  Comp(vector<int> &d): depth(d) { }
  bool operator() (const tuple<int, int> &t1, const tuple<int, int> &t2) {
    return depth[get<0>(t1)] < depth[get<0>(t2)];
  }
};

void add(
 int n, int q, vector<int> &parent, vector<int> &depth, vector<int64_t> &acc)
{
  vector<tuple<int, int> > pacc(n+1);
  for (int i = 0; i <= n; i++) {
    pacc[i] = make_tuple(i, 0);
  }

  for (int i = 0; i < q; i++) {
    int p1;
    int x;
    cin >> p1 >> x;
    get<1>(pacc[p1]) += x;
  }

  sort(pacc.begin(), pacc.end(), Comp(depth));
  vector<int> stack;

  for (int i = 1; i <= n; i++) {
    acc[get<0>(pacc[i])] = acc[parent[get<0>(pacc[i])]] + get<1>(pacc[i]);
  }

  return;
}

int main()
{
  int n, q;
  cin >> n >> q;
  vector<set<int> > to(n+1);
  vector<int64_t> acc(n+1);
  vector<int> parent(n+1), depth(n+1);

  read_data(n, to);
  unidir(to, parent, depth);
  add(n, q, parent, depth, acc);

  for (int i = 1; i < acc.size(); i++) {
    cout << acc[i] << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 33636
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10002;
int n,m,a,b,i,j,k,h[N],t[N],v[N];
int x[N],y[N],X[N],Y[N],fa[N],dep[N],val[N],ac[N];
int ans,id[N],d,l,r,cnt[2002],vis[N],col[N],oa,ob;
vector<int>e[N],w[N];
void add(int a,int b){
	t[++k]=h[a];h[a]=k;v[k]=b;
}
void dfs(int i){
	for(int j=h[i];j;j=t[j])
		if(v[j]!=fa[i]){
			fa[v[j]]=i;
			dep[v[j]]=dep[i]+1;
			dfs(v[j]);
		}
}
//clear x[i]==y[i];
void init(){
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++){
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	dfs(1);
	for(i=1;i<=m;i++){
		//ac[i]=i;ac[i+m]=i+m;???
		scanf("%d%d",x+i,y+i);
		X[i]=x[i];Y[i]=y[i];
		a=x[i];b=y[i];
		while(a!=b){
			if(dep[a]>dep[b]){
				val[a]++;
				a=fa[a];
			}
			else{
				val[b]++;
				b=fa[b];
			}
		}
	}
	for(i=1;i<=n;i++){
		if(val[i]>2)
			val[i]=2;
		ans+=val[i];
	}
	printf("%d\n",ans);
	for(i=1;i<=n;i++)
		id[i]=i;
}
bool cmp(int x,int y){
	return dep[x]>dep[y];
}
void Cover(int x,int y){
	while(x!=y){
		if(dep[x]>dep[y]){
			cnt[x]++;
			x=fa[x];
		}
		else{
			cnt[y]++;
			y=fa[y];
		}
	}
}
void Adde(int a,int b,int c){
	e[a].push_back(b);
	w[a].push_back(c);
	e[b].push_back(a);
	w[b].push_back(c);
}
void D(int i){
	vis[i]=1;
	for(int j=0;j<e[i].size();j++)
		if(!vis[e[i][j]]){
			col[e[i][j]]=col[i]^w[i][j];
			D(e[i][j]);
		}
}
void work(){
	sort(id+1,id+n+1,cmp);
	for(i=1;i<=n;i++){
		k=id[i];
		if(val[k]<2){
			for(d=1;d<=m;d++){
				if(x[d]==k)x[d]=fa[x[d]];
				if(y[d]==k)y[d]=fa[y[d]];
			}
			val[k]=0;
		}
		else{
			a=b=0;
			for(d=1;d<=m;d++){
				if(x[d]==k||y[d]==k){
					if(!a){
						a=d;
						if(x[d]==k)oa=1;
						else oa=0;
					}
					else{
						b=d;
						if(x[d]==k)ob=1;
						else ob=0;
					}
				}
			}
			if(a==0||b==0||x[a]==0||y[a]==0||x[b]==0||y[b]==0)
				break;
			Adde(a,b,oa^ob^1);
			memset(cnt,0,sizeof(cnt));
			Cover(x[a],y[a]);
			Cover(x[b],y[b]);
			for(d=1;d<=n;d++)
				if(cnt[d]==2)
					val[d]=0;
			if(x[a]==k){
				x[a]^=x[b]^y[b];
			}
			else{
				y[a]^=x[b]^y[b];
			}
			x[b]=y[b]=0;
			for(d=1;d<=m;d++){
				if(x[d]==k)x[d]=fa[x[d]];
				if(y[d]==k)y[d]=fa[y[d]];
			}
		}
		for(d=1;d<=m;d++)
			if(x[d]==y[d]){
				x[d]=y[d]=0;
			}
	}
	for(i=1;i<=m;i++)
		if(!vis[i])
			D(i);
	for(i=1;i<=m;i++)
		if(col[i]==0)
			printf("%d %d\n",X[i],Y[i]);
		else
			printf("%d %d\n",Y[i],X[i]);			
}
int main(){
	init();
	work();
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

struct Node {
  vector<int> edge_to;
  vector<int> edge_from;
  vector<ll> edge_cost;
  vector<ll> edge_from_cost;

  bool done;
  bool contain;
  ll cost;
};

int main() {
  int n, m, R;
  cin >> n >> m >> R;
  vector<int> r(R);
  for(int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }
  sort(r.begin(), r.end());
  vector<Node> node(n);
  for(int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    node[a].edge_to.push_back(b);
    node[a].edge_cost.push_back(c);
    node[b].edge_to.push_back(a);
    node[b].edge_cost.push_back(c);
  }

  vector<vector<ll>> dis(n + 1, vector<ll>(n + 1, -1));
  for(int i = 0; i < R; i++) {
    for(int j = 0; j < n; j++) {
      node[j].done = false;
      node[j].cost = -1;
    }
    auto compare = [](Node *a, Node *b) { return a->cost < b->cost; };
    priority_queue<Node, vector<Node*>, decltype(compare)> q{compare};
    node[r[i]].cost = 0;
    q.push(&node[r[i]]);
    while(!q.empty()) {
      Node doneNode = *q.top();
      q.pop();
      doneNode.done = true;
      for(int j = 0; j < doneNode.edge_to.size(); j++) {
        ll to = doneNode.edge_to[j];
        ll cost = doneNode.cost + doneNode.edge_cost[j];
        if(node[to].cost < 0 || cost < node[to].cost) {
          node[to].cost = cost;
          if(node[to].contain == false){
            q.push(&node[to]);
          }
        }
      }
    }
    for(int j = 0; j < R; j++) {
      dis[r[i]][r[j]] = node[r[j]].cost;
    }
  }

  ll ans = 100101001001001;
  do {
    ll sum = 0;
    for(int i = 0; i < R - 1; i++) {
      sum += dis[r[i]][r[i + 1]];
    }
    ans = min(ans, sum);
  } while(next_permutation(r.begin(), r.end()));

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

Measured memory_bytes: 1280
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
string s;
char tmp[maxn];

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  return true;
}

void solve() {
  int cnt[3] = {0, 0, 0};
  for (int i = 0; i < sz(s); i++) {
    cnt[s[i] - 'a']++;
  }
  if (max(max(cnt[0], cnt[1]), cnt[2]) - min(min(cnt[0], cnt[1]), cnt[2]) <= 1) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int len = s.size();
    for(int i=0;i<len;i++)
    {
        if(s[i]=='?')
        {
            s[i] = 'D';
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;
string s;
int n, q, ac[mx], sz, l, r;
int main(){
    cin >> n >> q >> s;
    sz = s.size();
    for(int i = 1; i < sz; i++){
        ac[i] = ac[i-1];
        if(s[i-1] == 'A' && s[i] == 'C') ac[i]++;
    }
    for(int i = 0; i < q; i++){
        scanf("%d%d", &l, &r);l--; r--;
        printf("%d\n", ac[r] - ac[l]);
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, K;
	cin >> N >> K;
	int h[N];
	for(int i = 0; i < N; i++) cin >> h[i];
	ll ans = 0;
	for(int i = 0; i < N; i++) {
		if(K <= h[i]) ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3928
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

ll a,b,x;

int main(){
    cin>>a>>b>>x;
    if(a%x==0)out(b/x-a/x+1);
    else out(b/x-a/x);
    
    
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i64>();
  let mut a = vec![];

  for _ in 0..n {
    let ai = read::<i64>();
    a.push(ai);
  }

  let ans: i64 = a.iter().map(|x| x - 1).sum();
  println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr long long LINF=334ll<<53; constexpr int INF=15<<26; constexpr long long MOD=1E9+7;

struct lazy_segment_tree{
    struct Node{
        LL val,delay;
        Node(){val=delay=0;}
    };
    int N;
    vector<Node> data;
    explicit lazy_segment_tree(int size){
        N=1;
        while(N<size)N*=2;
        data=vector<Node>(2*N,Node());
    }
    inline void lazy_evaluate(int k,int a,int b){
        data[k].val+=data[k].delay*(b-a);//
        if(k<N){
            data[2*k].delay+=data[k].delay;//
            data[2*k+1].delay+=data[k].delay;//
        }
        data[k].delay=0;
    }
    inline LL f(LL a,LL b){
        return a+b;
    }
    inline LL merge(int k){
        return data[k].val=f(data[2*k].val,data[2*k+1].val);//
    }
    inline void update(int l,int r,LL v){update(l,r,v,1,0,N);}
    void update(int l, int r, LL v, int k, int a, int b){
        if(l<=a && b<=r){
            data[k].delay+=v;//
            //lazy_evaluate(k,a,b);
            return ;
        }
        lazy_evaluate(k,a,b);
        if(b<=l || r<=a){return ;}//
        update(l,r,v,2*k,a,(a+b)/2);
        update(l,r,v,2*k+1,(a+b)/2,b);
        merge(k);
    }
    inline LL get(int l,int r){return get(l,r,1,0,N);}
    LL get(int l, int r, int k, int a, int b){
        if(b<=l || r<=a){return 0;}//
        lazy_evaluate(k,a,b);
        if(l<=a && b<=r){
            return data[k].val;
        }
        LL vall=get(l,r,2*k,a,(a+b)/2);
        LL valr=get(l,r,2*k+1,(a+b)/2,b);
        return f(vall,valr);
    }

};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<tuple<int,int,int>> s(n);
    for(int i=0; i<n; ++i){
        int l,r;
        cin >> l >> r;
        s[i]=make_tuple(r-l+1,l,r);
    }
    sort(s.begin(),s.end());

    auto it=s.begin();
    lazy_segment_tree seg(m+1);
    for(int i=1; i<=m; ++i){
        int ans=0;
        while(get<0>(*it)<i && it<s.end()){
            seg.update(get<1>(*it),get<2>(*it)+1,1);
            it++;
        }

        ans=s.end()-it;
        for(int j=i; j<=m; j+=i){
            ans+=seg.get(j,j+1);
        }
        cout << ans <<"\n";
    }




    return 0;
}



Measured memory_bytes: 8576
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
	int i, n;
	int a, b, c;
	char s[100005];
	scanf("%s", s);
	int len = strlen(s);
	int vis1=0,vis2=0,vis3 = 0;
	for(i = 0 ; i < len ; i++)
	{
		if(s[i] == 'a')vis1++;
		if(s[i] == 'b')vis2++;
		if(s[i] == 'c')vis3++;
	}
	if(vis1 >= 1 && vis2 >= 1 && vis3 >= 1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    vector<int>a(n+2,0),l(n+2,0),r(n+2,0);
    rep2(i,1,n+1)cin>>a[i];

    rep2(i,1,n+2){
        l[i]=max(a[i],l[i-1]);
    }
    for(int i=n;i>=0;i--){
       r[i]=max(a[i],r[i+1]);
    }

    rep2(i,1,n+1)
            cout<<max(l[i-1],r[i+1])<<endl;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	string x = "CODEFESTIVAL2016";
	ll ans = 0;
	for (int i = 0; i < x.length(); i++) {
		if (s.at(i) != x.at(i))ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){

	ll n;
	cin>>n;
	ll cnt=2;
	set<ll> st;
    if(n==2){
    	cout<<1<<endl;
    	return 0;
    }
	FOR(i,2,sqrt(n)){
		ll tmp=n;
		while(tmp%i==0){
			tmp=tmp/i;

		}
		if(tmp%i==1) {st.insert(i); }
	}
	st.insert(n);
	st.insert(n-1);

	FOR(i,2,sqrt(n-1)){
		ll tmp=n-1;
		
		if(tmp%i==0) {st.insert(i); st.insert((n-1)/i); }
		

	}
	cout<<sz(st)<<endl;

	
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a[3];
    scanf("%d%d%d",&a[0], &a[1], &a[2]);
    int ans;
    int temp;
    for(int i = 0; i < 3; i++){
        for(int j = i; j < 3; j++){
            if(a[i] < a[j]){
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    ans = a[0]*10 + a[1] + a[2];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

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

  vector<int> dp(n + 1, 0);
  int seq = 0;
  for(int i = 0; i < n; ++i){
    dp[p[i]] = dp[p[i] - 1] + 1;
    seq = max(seq, dp[p[i]]);
  }

  cout << n - seq << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=1005;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,-1,1};
int d[N][N],q[N*N][2],n,m,l,r,x,y,xx,yy;
char s[N][N];

int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%s",s[i]+1);
	memset(d,-1,sizeof d);
	rep(i,1,n)rep(j,1,m)
		if(s[i][j]=='#'){
			d[i][j]=0;
			q[r][0]=i;
			q[r++][1]=j;
		}
	int ans=0;
	while(l<r){
		x=q[l][0],y=q[l++][1];
		ans=max(ans,d[x][y]);
		REP(k,4){
			xx=x+dx[k],yy=y+dy[k];
			if(xx<1||xx>n||yy<1||yy>m)continue;
			if(d[xx][yy]!=-1)continue;
			d[xx][yy]=d[x][y]+1;
			q[r][0]=xx;
			q[r++][1]=yy;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long LL;
const LL INF = 1e18;
const int MAXN = 111111 * 2;
const int W = 9e8;
int n, E;
LL f[MAXN], minf[MAXN], x[MAXN], T, tr[MAXN << 2], a[MAXN], b[MAXN], p[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> p[i];
	for (int i = 1; i <= n; ++i) {
		a[i] = W / n * (i);
		b[i] = W / n * (n - i + 1);
	}
	for (int i = 1; i <= n; ++i) {
		b[p[i]] += i;
	}
	for (int i = 1; i < n; ++i) cout << a[i] << " ";
	cout << a[n] << endl;
	for (int i = 1; i < n; ++i) cout << b[i] << " ";
	cout << b[n] << endl;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N,HP[111],M;
int dpa[100001],dps[100001];
vector<P> ds,da;
int MAX;
const int INF = (1<<29);

void init(const vector<P> &D,int *dp){
  for(int j=0;j<=MAX;j++){
    for(int i=0;i<(int)D.size();i++){
      int np = j + D[i].first;
      np = min( np, MAX );
      dp[np] = min( dp[j] + D[i].second, dp[np] );
    }
  }
  for(int i=MAX-1;i>=0;i--){
    dp[i] = min( dp[i+1], dp[i] );
  }
}

int main(){
  while( cin >> N && N ){
    MAX = 0;
    for(int i=0;i<N;i++) {
      cin >> HP[i]; MAX = max( MAX, HP[i] );
    }
    cin >> M;
    ds.clear(); da.clear();
    for(int i=0;i<M;i++){
      string s,ta;int mp,dm;
      cin >> s >> mp >> ta >> dm;
      if( ta == "Single" )
	ds.push_back( P(dm,mp) );
      else
	da.push_back( P(dm,mp) );
    }
    fill(dps,dps+MAX+1,INF);
    fill(dpa,dpa+MAX+1,INF);
    dps[0] = dpa[0] = 0;
    init(da,dpa);
    init(ds,dps);
    int res = INF;
    for(int i=0;i<=MAX;i++){
      int ret = dpa[i];
      for(int j=0;j<N;j++){
	int hp = HP[j] - i;
	hp = max(hp,0);
	ret += dps[hp];
	if( ret > INF ) ret = INF;
      }
      res = min( res, ret );
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 2000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf>
?????????============================================================
N(1<=N<=20000)???????????¬???????????????????????¬??????i?????§?????????Ai??§?????????

???????????¬????????????????????????????????????????????±??????????????????????????¨?????????????????¨????????±??????
??£?¶?????????????????????¬??????????????????????????¨?????§????????????

?????¨????????±???????????§??§M(1<=M<=1000)?????§?????¬???????????????????????¨?????§??????
??±????????¬?????????????????????????????????????????????????????±?????????????????§????????¬???????????§?????????a,
??±????????????????°?????????¬???????????§?????????b, ??±?????????????????¬??????????????°???s??¨????????¨???, K+s*(a-b)??¨?????????
K?????±???????????????????????§???????????¨????????±??§??±???

??????????????°?????±?????¨?????????????????????????????¬????????????????????±??°??????????????¨??§??±??°???????????????
???????????????????????§?????????????°????????????????
=================================================================
?§£??¬=============================================================
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M, K; cin >> N >> M >> K;
	vector<int> A(N); for (auto& in : A)cin >> in;

//	vector<vector<pair<ll, pair<int, int>>>> dp(N + 1, vector<pair<ll, pair<int, int>>>(M + 1, { LINF,{-INF,INF} }));
//	dp[0][0].first = 0;
	vector<vector<pair<ll, pair<int, int>>>> dp(2, vector<pair<ll, pair<int, int>>>(M, { LINF,{ -INF,INF } }));
	int cur = 0, next = 1;
	dp[0][0].first = 0;
	for (int i = 0; i < N;i++) {
		for (int j = 0; j < M;j++) {
			dp[next][j] = { LINF,{-INF,INF} };
		}
		for (int j = 0; j < M;j++) {
			if (dp[cur][j].first == LINF)continue;
			if (j != M-1 && i != N-1) {
				dp[next][j+1] = min(dp[next][j + 1], { dp[cur][j].first,{ max(dp[cur][j].second.first,A[i]),min(dp[cur][j].second.second,A[i]) } });
//				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], { dp[i][j].first,{max(dp[i][j].second.first,A[i]),min(dp[i][j].second.second,A[i])} });
			}
			dp[next][0] = min(dp[next][0], { dp[cur][j].first + (ll)K + (ll)(j + 1)*((ll)max(dp[cur][j].second.first,A[i]) - (ll)min(dp[cur][j].second.second,A[i])),{ -INF,INF } });
//			dp[i + 1][0] = min(dp[i + 1][0], { dp[i][j].first + (ll)K + (ll)(j+1)*((ll)max(dp[i][j].second.first,A[i]) - (ll)min(dp[i][j].second.second,A[i])),{-INF,INF} });
		}
		cur = !cur;
		next = !next;
	}
	cout << dp[cur][0].first << endl;
	return 0;
}

Measured memory_bytes: 3340
#include <iostream>

int n,a;
int cnt[100001]={0};

int main(){

  std::cin >> n;
  for (int i=0; i<n; i++) {
    std::cin >> a;
    cnt[a]++,cnt[a-1]++,cnt[a+1]++;
  }
  int ans = cnt[0];
  for (int i=1; i <=100000; i++){
    ans = std::max(ans,cnt[i]);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    long long i, j, min;
    i = 2; j = N / 2;
    min = N - 1;
    while(i <= j){
        if(N % i == 0){
            min = i + j - 2;
        }
        i++;
        j = N / i;
    }
    cout << min << "\n";
}


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

double dist(double x1,double y1,double x2,double y2){
    double res;
    res=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    return res;
}

int main(){
    int n;
    cin>>n;
    double x[n],y[n];
    rep(i,n){
        cin>>x[i]>>y[i];
    }

    vector<int> order(n);
    rep(i,n) order[i]=i;

    int cnt=0;
    double sum=0;
    do{
        for(int i=1;i<n;i++){
            sum+=dist(x[order[i-1]],y[order[i-1]],x[order[i]],y[order[i]]);
        }
        cnt++;
    }while(next_permutation(all(order)));
    double ans=sum/(double)cnt;
    //cout<<cnt<<endl;
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#include <tuple>
#include <vector>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
typedef tuple<double,double,double> tddd;
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
template<typename T>
tuple<T,T,T> line_equation_real(const complex<T> &A,const complex<T> &B){
	T a=imag(B)-imag(A);
	T b=real(A)-real(B);
	T c=-real(A)*a-imag(A)*b;
	if(a<0 || (a==0&&b<0))a=-a,b=-b,c=-c;
	return make_tuple(a,b,c);
}
int main(){
	int N,M;
	for(;scanf("%d",&N),N;){
		vector<tddd> v(N);
		for(int i=0;i<N;i++){
			double x,y,r;
			scanf("%lf%lf%lf",&x,&y,&r);
			v[i]=make_tuple(x,y,r);
		}
		for(scanf("%d",&M);M--;){
			double x1,y1,x2,y2;
			scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
			P A(x1,y1),B(x2,y2);
			auto t=line_equation_real(A,B);
			double a=get<0>(t);
			double b=get<1>(t);
			double c=get<2>(t);
			double nrm=a*a+b*b;
			for(auto &e:v){
				double d=a*get<0>(e)+b*get<1>(e)+c;
				double x=sqrt(get<2>(e)*get<2>(e)*nrm-d*d);
				P X(get<0>(e) + (-a*d+b*x)/nrm,get<1>(e) + (-b*d-a*x)/nrm);
				P Y(get<0>(e) + (-a*d-b*x)/nrm,get<1>(e) + (-b*d+a*x)/nrm);
				if((dot(X-A,B-A)>0&&dot(X-B,A-B)>0) || (dot(Y-A,B-A)>0&&dot(Y-B,A-B)>0)){
					puts("Safe");
					goto NEXT;
				}
			}
			puts("Danger");
			NEXT:;
		}
	}
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int dp[100][100001],cumulative[100][100001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;	cin>>n>>k;
	int a[n],i,j;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(j=a[n-1];j>=0;j--){
		dp[n-1][j]=1;
	}
	cumulative[n-1][0]=1;
	for(j=1;j<=k;j++){
		cumulative[n-1][j]=(dp[n-1][j]+cumulative[n-1][j-1])%mod;
	}
	for(i=n-2;i>=0;i--){
		for(j=k;j>a[i];j--){
			dp[i][j]=(cumulative[i+1][j]-cumulative[i+1][j-a[i]-1])%mod;
		}
		for(j=a[i];j>=0;j--){
			dp[i][j]=cumulative[i+1][j];
		}
		cumulative[i][0]=1;
		for(j=1;j<=k;j++){
			cumulative[i][j]=(dp[i][j]+cumulative[i][j-1])%mod;
		}
	}
	// for(i=0;i<n;i++){
	// 	for(j=1;j<=k;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	// cout<<endl;
	// for(i=0;i<n;i++){
	// 	for(j=1;j<=k;j++){
	// 		cout<<cumulative[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<(dp[0][k]%mod+mod)%mod<<endl;
	return 0;
}

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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
  	cin >> h.at(i);
  }
  
  vector<int> dp(n);
  dp.at(0) = 0; dp.at(1) = abs(h.at(1) - h.at(0));
  
  if(n >= 3){
  	for(int i = 2; i < n; i++){
  		dp.at(i) = min(dp.at(i-1) + abs(h.at(i) - h.at(i-1)), dp.at(i-2) + abs(h.at(i) - h.at(i-2)));
  }
  }
  cout << dp.at(n-1) << endl;
}


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

int main() {
	int n;
	cin >> n;
	vector <int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 1;
	int x = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) x++;
		else ans++;
	}
	if (x % 2 == 1)ans--;
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define pai 3.1415926535


int main(void) {
	
	char a[4], b[4];
	scanf("%s %s", a, b);
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		printf("YES");
	}
	else {
		printf("NO");
	}


	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  string s;cin>>s;
  ll n=s.size();
  char tmp[2];
  if(s[0]==s.back()){
    for(j=0;j<26;j++){
      tmp[0]=s[0];
      tmp[1]='a'+j;
      if(tmp[0]!=tmp[1]){
        buf=0;
        buf2=0;
        for(i=0;i<n;i++){
          if(s[i]==tmp[buf2]){
            buf2^=1;
          }
          else{
            buf++;
          }
          //cout<<s[i] spa tmp[buf2] spa buf<<endl;
        }
        //cout<<buf spa tmp[0] spa tmp[1]<<endl;
        if(buf==0){judge=false;break;}
        else if(buf==1){judge=true;break;}
        else judge=((n-1)%2==1);
      }
    }
  }
  else{
    tmp[0]=s[0];
    tmp[1]=s.back();
    buf=0;
    buf2=0;
    for(i=0;i<n;i++){
      if(s[i]==tmp[buf2]){
        buf2^=1;
      }
      else{
        buf++;
      }
    }
    if(buf==0)judge=false;
    else if(buf==1)judge=true;
    else judge=((n-2)%2==1);
  }
  ans(judge,"First","Second");
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void solve(){
    ll n;
    cin >> n ;
    cout << (1000-n%1000)%1000 ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}




Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <tuple>

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

  int tmp_min = p_arr[0];
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(tmp_min >= p_arr[i]){
      tmp_min = p_arr[i];
      ans++;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;

int n,m;
vector<int> a[200005];
int vis[200005];
int sz ;
void dfs(int i)
{
    sz++;
    vis[i] = 1;
    for(int t : a[i]){
        if(!vis[t]){
            dfs(t);
        }
    }
}
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; ++i){
        int u,v;
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    int ans = 0;
    for(int i=1; i<=n; ++i){
        sz = 0;
        if(!vis[i]){
            dfs(i);
            ans = max(ans,sz);
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 21532
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn = 2e5 + 10;
int a[maxn],l[maxn],r[maxn];
int n;
stack<int> st;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i) scanf("%d",a+i);
	for(int i=0;i<n;++i)
	{
		while(st.size() && a[st.top()] > a[i]) 
		{
			r[st.top()] = i-1;
			st.pop();
		}
		st.push(i);
	}
	while(st.size())
	{
		r[st.top()] = n-1;
	   	st.pop();
	}
	for(int i=n-1;i>=0;--i)
	{
		while(st.size() && a[st.top()] > a[i]) 
		{
			l[st.top()] = i+1;
			st.pop();
		}
		st.push(i);
	}
	while(st.size())
	{
		l[st.top()] = 0;
	   	st.pop();
	}
	LL ans = 0;
	for(int i=0;i<n;++i)
	{
//		printf("%d %d\n",l[i],r[i]);
		ans += 1LL*(i-l[i]+1)*(r[i]-i+1)*a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int a, b;

  // 変数aで入力を受け取る
  cin >> a >> b;

  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << (a + b + 1) / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i,n) for (int i=0; i< (n); ++i)
typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  char cur, next;
  ll carry = 0;
  vector<int> ansl(n);  
  for (int i=0; i<n-1; i++) {
    cur = s[i];
    next = s[i+1];    
    if (cur == 'R') {
      if (next == 'R') {      
	carry++;
      } else if (next == 'L') {
	carry++;	
	ansl[i] = carry;
	carry = 0;
      }
    }
  }
  carry = 0;
  vector<int> ansr(n);    
  for (int i=n-1; i>0; i--) {
    cur = s[i];
    next = s[i-1];    
    if (cur == 'L') {
      if (next == 'L') {      
	carry++;
      } else if (next == 'R') {
	carry++;	
	ansr[i] = carry;
	carry = 0;
      }
    }
  }
  
  vector<int> ans(n, 0);      
  for (int i=0; i<n-1; i++) {
    if (ansl[i]%2==0) {
      ans[i] += ansl[i] / 2;
      ans[i+1] += ansl[i] / 2;      
    } else {
      ans[i] += ansl[i] / 2 + 1;
      ans[i+1] += ansl[i] / 2;
    }
  }
  for (int i=n-1; i>0; i--) {
    if (ansr[i]%2==0) {
      ans[i] += ansr[i] / 2;
      ans[i-1] += ansr[i] / 2;      
    } else {
      ans[i] += ansr[i] / 2 + 1;
      ans[i-1] += ansr[i] / 2;
    }
  }
  cout << endl;
  rep(i,n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


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

# dp[i][j]：A_1,...,A_iを確定させ, A_iの符号をj回反転させたときの
# Aの和の最大値

INF = float('inf')
dp = [[-INF]*2 for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(2):
        dp[i+1][j] = max(dp[i][0]+A[i]*(-1)**j, dp[i][1]-A[i]*(-1)**j)
print(dp[N][0])

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

int main(){
	int k, a, b;
	cin >> k >> a >> b;
	if(a%k == 0){
		if((a/k) * k <=b){
			cout << "OK" << endl;
		}
		else{
			cout << "NG" << endl;
		}
	}
	else{
		if((a/k + 1) * k <=b){
			cout << "OK" << endl;
		}
		else{
			cout << "NG" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	put(max(c - (a - b),0));
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb       push_back
#define sz(x)    ((int)(x.size()))
#define all(x)   x.begin(),x.end()
#define clr(x)   memset(x,0,sizeof x)
const int inf = ( 1953125 << 9 );
const int maxn = 2 * 1e5 + 5;
bool vis[maxn];


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.in", "r", stdin); //freopen("output.txt", "w", stdout);
	clr(vis);

	int a,b,c;
	cin>>a>>b>>c;
	cout<<max((a*10)+b  +c , max(a+(b*10)+c, a+b + c*10));
}


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

int main() {
    long long w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<w*h*0.5;
    if(2*x==w&&2*y==h)
    cout<<" 1";
    else
    cout<<" 0";
    cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
string ans="";
bool a[5][5][4] = {{{0}}};
int main(){
    string str;
    for(int i=0;i<9;i++){
        if(i%2==0){
            cin>>str;
            for(int j=0;j<4;j++){
                if(str[j]=='1'){

                    a[i/2][j][1] = true;
                    a[i/2][j+1][3] = true;
                    //cout<<"-("<<i/2<<" ,"<<j<<")("<<i/2<<" ,"<<j+1<<")"<<endl;
                }

            }
        }
        else{
            cin>>str;
            for(int j=0;j<5;j++){
                if(str[j]=='1'){
                    a[i/2][j][2] = true;
                    a[i/2+1][j][0] = true;
                    //cout<<"|("<<i/2<<" ,"<<j<<")("<<i/2+1<<" ,"<<j<<")"<<endl;
                }
				
            }
        }
    }
	cout<<"R";
		int x=1,y=0,way=1;
		while(1){
			if(x==0&&y==0)break;
			if(way == 0){
				if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
			}
			else if(way == 1){
				if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
			}
			else if(way == 2){
				if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
				else if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
			}
			else if(way == 3){
				if(y!=4&&a[y][x][2]){
					cout<<"D";
					y++;
					way = 2;
				}
				else if(x!=0&&a[y][x][3]){
					cout<<"L";
					x--;
					way = 3;
				}
				else if(y!=0&&a[y][x][0]){
					cout<<"U";
					y--;
					way = 0;
				}
				else if(x!=4&&a[y][x][1]){
					cout<<"R";
					x++;
					way = 1;
				}
			}
		}
    
	cout<<endl;
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
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;
}
long long dp[200010];
  
int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);
  map<ll,ll> mp;
  map<ll,ll> mp2;
  REP(i, N){
    cin >> A[i];
    B.at(i)=A[i]+i;
    mp[B.at(i)]++;
    C.at(i)=-A[i]+i;
    mp2[C.at(i)]++;
  }

  ll cnt = 0;
  for(auto x:mp){
    cnt+=mp2[x.first]*x.second;
  }


  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  string ans = "No";
  if (n <= 81) {
    for (int i = 1; i <= 9; i++) {
      if (n%i == 0) {
        if (n/i <= 9) {
        ans = "Yes";
        }
      }
    }
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int m,f,r,i,n;
    char grade[100];
    i=0;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1){
            break;
         }else if(m==-1||f==-1){
            grade[i]='F';
        }else if(80<=m+f){
            grade[i]='A';
        }else if(65<=m+f&&m+f<80){
            grade[i]='B';
        }else if(50<=m+f&&m+f<65){
            grade[i]='C';
        }else if(30<=m+f&&m+f<50){
            if(50<=r){
                grade[i]='C';
            }else{
                grade[i]='D';
            }
        }else if(m+f<30){
            grade[i]='F';
        }
        i++;
    }
    for(n=0;n<i;n++){
        printf("%c\n",grade[n]);
    }
    return 0;
}

Measured memory_bytes: 1776
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[110];
    rep(i, N) cin >> a[i];
    sort(a, a + N);
    rep(i, N - 1) {
        if (a[i + 1] - a[i] > 1) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if (a[0] * 2 != a[N - 1] && a[0] * 2 != a[N - 1] + 1) {
        cout << "Impossible" << endl;
    } else if (a[N - 1] % 2 == 0 && a[0] == a[1]) {
        cout << "Impossible" << endl;
    } else if (a[N - 1] % 2 == 1 && a[0] == a[2]) {
        cout << "Impossible" << endl;
    }  else {
        cout << "Possible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// E - League
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int N; cin>>N;

	vector<vi> A(N, vi(N-1));
	rp(s,N){
		rp(d,N-1){ cin>>A[s][d]; --A[s][d]; }
		reverse(A[s].begin(), A[s].end());
	}

	set<P> q;//選手iの直近の試合を選手のペアで保持

	//qへ、選手sの直近の試合を登録する関数（ラムダ式）
	auto match_make = [&](int s){
		if(A[s].size()==0) return;
		int d = A[s].back();
		if(A[d].back()==s){
			if(s > d) swap(s,d);//重複をなくすために、s<d にそろえておく
			q.insert(P(s,d));
		}
	};

	rp(s,N) match_make(s);//全選手の直近の試合をqへ登録

	int day = 0;
	while(q.size()){
		++day;

		set<P> p; swap(p,q);//p<-q, q<-{} : copy & clear

		for(P e:p){
			int s,d; tie(s,d) = e;
			A[s].pop_back(); A[d].pop_back();//s,d 両選手の直近の対戦相手を削除
			match_make(s); match_make(d);//s,d 両選手の直近の試合をqに再登録
		}
	}

	rp(s,N) if(A[s].size()){ cout<< -1 <<endl; return 0; }
	cout<< day <<endl;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <vector>
#include <tuple>

using namespace std;

int main() {
  int x;
  scanf("%d", &x);
  --x;
  if (x == 1) {
    puts("2 2");
    puts("1 2 0");
    puts("1 2 1");
    return 0;
  }
  int hi = -1;
  for (int i = 0; i <= 19; ++i) {
    if (x >> i & 1) {
      hi = i;
    }
  }
  vector<tuple<int, int, int>> ans;
  for (int i = 1; i <= hi; ++i) {
    ans.emplace_back(i, i + 1, 0);
    ans.emplace_back(i, i + 1, 1 << (hi - i));
  }
  int cur = 1 << hi;
  for (int i = hi - 1; i >= 0; --i) {
    if ((x >> i & 1) == 0) {
      continue;
    }
    ans.emplace_back(1, (hi + 1) - i, cur);
    cur += 1 << i;
  }
  ans.emplace_back(1, hi + 1, cur);
  printf("%d %d\n", hi + 1, (int)ans.size());
  for (auto &e : ans) {
    printf("%d %d %d\n", get<0>(e), get<1>(e), get<2>(e));
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  string s;
  cin >> s;

  auto replace = [&](int i) {
    s[i] = 'B';
    s[i + 1] = 'C';
    s[i + 2] = 'A';
  };

  int na = 0;
  ll ans = 0;
  int l = s.length();
  rep(i, l - 2) {
    if (s.substr(i, 3) == "ABC") {
      replace(i);
      ans += na + 1;
      i++;
    } else if (s[i] == 'A') {
      na++;
    } else {
      na = 0;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  int end = a;
  int ans = 0;
  if((end%10<b%10) or (b%10==0)) ans = b;
  else {
    end = b;
    ans = a;
  }
  if(ans%10!=0) ans += 10-ans%10;
  if((end%10<c%10) or (c%10==0)) ans += c;
  else {
    ans += end;
    end = c;
  }
  if(ans%10!=0) ans += 10-ans%10;
  if((end%10<d%10) or (d%10==0)) ans += d;
  else {
    ans += end;
    end = d;
  }
  if(ans%10!=0) ans += 10-ans%10;
  if((end%10<e%10) or (e%10==0)) ans += e;
  else {
    ans += end;
    end = e;
  }
  if(ans%10!=0) ans += 10-ans%10;
  ans += end;
  cout << ans;
}

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

using namespace std;
const int N = 2000;
int n,ans;
int a[N][N],t[N];
bool flag;
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		a[i][0]=1;
		for(int j=1; j<=n-1; j++){
			scanf("%d",&a[i][j]);
		}
	}
	while(1){
		int ok=0;
		bool tmp=0;
		bool vis[N]={0};
		for(int i=1; i<=n; i++){
			if(a[i][0]==n){
				ok++;
				continue;
			}
			if(vis[i]){
				continue;
			}
			int pos=a[i][a[i][0]];
			if(a[pos][a[pos][0]]==i){
				t[i]=t[pos]=max(t[i], t[pos])+1;
				a[i][0]++;
				a[pos][0]++;
				vis[pos]=1;
				vis[i]=1;
				tmp=1;
			}
		}
		if(ok==n){
			flag=1;
			break;
		}
		if(tmp==0){
			flag=0;
			break;
		}
	}
	if(flag){
		for(int i=1; i<=n; i++){
			ans=max(ans, t[i]); 
		}
		printf("%d\n",ans);
	}
	else{
		puts("-1");
	}
	return 0;
} 


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

int main(){
  int n;
  cin >> n;
  if(n == 1000 || n == 2000 || n == 3000 || n == 3000 || n == 4000 || n == 5000 || n == 6000 || n == 7000 || n == 8000|| n == 9000 || n == 10000) cout << 0 << endl;
  else if(n < 1000) cout << 1000 - n << endl;
  else if (n < 2000) cout << 2000 - n << endl;
  else if (n < 3000) cout << 3000 - n << endl;
  else if (n < 4000) cout << 4000 - n << endl;
  else if (n < 5000) cout << 5000 - n << endl;
  else if (n < 6000) cout << 6000 - n << endl;
  else if (n < 7000) cout << 7000 - n << endl;
  else if (n < 8000) cout << 8000 - n << endl;
  else if (n < 9000) cout << 9000 - n << endl;
  else cout << 10000 - n << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;

struct han {
	set<int> to;
	set<int> from;
};
	 
int main() {
 int a,b,n,m,i,j,ans[20],use[21];
 set<int>::iterator it;
 han h[21];
 cin >> n;
 for (i=0;i<=n;i++) { use[i]=0; ans[i]=0;}
 ans[0]=2; use[2]=1;
 cin >> m;
 for (i=0;i<m;i++) {
	 cin >> a >> b ;
	 if (b!=2) { h[b].to.insert(a); h[a].from.insert(b); }
	 }
 for (i=1;i<n;i++) {
	 for (j=1;j<=n;j++) {
		 if (use[j]==1 || !h[j].from.empty()) continue;
		 ans[i]=j; use[j]=1;
		 for (it=h[j].to.begin(); it!=h[j].to.end(); it++) h[*it].from.erase(j);
		 break;
	 }
 }
 for (i=n-1;i>=0;i--) cout << ans[i] << endl;
 return 0;	
}

Measured memory_bytes: 1204