akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int in(){int k;cin>>k;return k;}
inline int low(int x){return x&(-x);}
char s[N];
typedef std::pair<int,int> P;
#define mk make_pair
int f[205][N],a[N];
inline void add(int &x,int y){if((x+=y)>=YL)x-=YL;}
int main()
{
	ios::sync_with_stdio(0);
	int n,m,ans=0;cin>>n>>m;
	for(int i=1;i<=n;++i)a[i]=in();
	std::sort(a+1,a+n+1);f[0][m]=1;
	std::reverse(a+1,a+n+1);
	for(int i=1;i<=n;++i)
		for(int j=0;j<N;++j)
			add(f[i][j%a[i]],1ll*f[i-1][j]),add(f[i][j],1ll*f[i-1][j]*(n-i)%YL);
	for(int i=0;i<N;++i)add(ans,1ll*i*f[n][i]%YL);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 158464
#include <bits/stdc++.h>
using namespace std;
int i,j,n,k,p,a[20],b[20],c[20];
string s;
int main(){
  for(cin>>s;i<s.size();i++){
    if(i%2==0&&s[i]=='L')return cout<<"No",0;
    if(i%2==1&&s[i]=='R')return cout<<"No",0;
  }
  cout<<"Yes";
}

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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

#define MAX_V 4000

typedef pair<int,int> P;

struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> g[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<MAX_V;i++){
    g[i].clear();
  }
}

void add_edge(int from,int to,int cap,int cost){
  g[from].push_back((edge){to,cap,cost,(int)g[to].size()});
  g[to].push_back((edge){from,0,-cost,(int)g[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  memset(h,0,sizeof(h));
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(que.size()){
      P p=que.top(); que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<g[v].size();i++){
        edge e=g[v][i];
        if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
    if(dist[t]==INF)return -1;
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

int n,a[1000],b[1000];
vector<int> vs;

int main(){
  scanf("%d",&n);
  rep(i,n)scanf("%d%d",a+i,b+i);
  rep(i,n){
    vs.push_back(a[i]);
    vs.push_back(b[i]);
  }
  sort(all(vs));
  uni(vs);

  int m=vs.size();
  int src=m+n,dest=m+n+1;
  init(m+n+2);
  rep(i,m){
    add_edge(src,i,1,0);
  }
  rep(i,n){
    int f1,f2;
    f1=lower_bound(all(vs),a[i])-vs.begin();
    f2=lower_bound(all(vs),b[i])-vs.begin();
    add_edge(f1,i+m,1,-b[i]);
    add_edge(f2,i+m,1,-a[i]);
    add_edge(i+m,dest,1,0);
  }
  add_edge(src,dest,n,0);

  cout<<-min_cost_flow(src,dest,n)<<endl;

  return 0;
}



Measured memory_bytes: 3684
#include<iostream>
using namespace std;
int main(){
	int n,k,s[100000]={0},bb,i,j;
	while(1){
	cin>>n>>k;
	if(n==0&&k==0) break;
	for(i=0;i<k;i++){
		cin>>s[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<k;j++){
		cin>>bb;
		s[j]-=bb;
		}
	}
	bb=0;
	for(i=0;i<k;i++){
		if(s[i]<=-1) bb++;
	}
	if(bb==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    string t; cin >> t;
    int a, b;
    cin >> a >> b;
    string u; cin >> u;
    if (s == u) a--;
    else b--;
    cout << a << " " << b << '\n';

    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    map<int, queue<int>> mp;
    for(int i=0;i<n;i++){
        mp[a[i]].push(i);
    }

    vector<bool> ok(n, false);
    vector<int> ans;
    int ptr = 0;
    for(int i=n-1;i>=0;i--){
        int p = mp[a[i]].front();
        mp[a[i]].pop();

        ok[p] = true;
        if(ok[ptr]){
            for(int j=ptr+1;j<n;j++){
                if(ok[j] == false){
                    ptr = j;
                    break;
                }
            }
            if(ok[ptr]){
                ptr = n;
            }
        }

        if(ptr == n-i){
            ans.push_back(ptr);
        }
    }


    // out
    sort(ans.begin(), ans.end());
    int m = ans.size();
    for(int i=0;i<m;i++){
        cout << ans[i];
        if(i != m-1){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}



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

int main(){
  int a,b,c,d,e;
  int A,B,C,D,E;
  cin >> a >> b >> c >> d >> e;
  A=(a+9)%10+1;
  B=(b+9)%10+1;
  C=(c+9)%10+1;
  D=(d+9)%10+1;
  E=(e+9)%10+1;
  cout << ((a-1)/10+(b-1)/10+(c-1)/10+(d-1)/10+(e-1)/10+4)*10+min(A,min(B,min(C,min(D,E)))) << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll m = 0;
    ll p = 0;
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        if (a == b) {
            p++;
        }
        else
            p = 0;
        m = std::max(p, m);
    }

    if (m >= 3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    repl(i, 1, n + 1) {
        string s = to_string(i);
        int tmp = 0;
        rep(j, s.size()) tmp += s[j] - '0';
        if (a <= tmp && tmp <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
i=len(S)
flag=True
while i>0:
    if S[i-7:i]=='dreamer':
        i=i-7
    elif S[i-6:i]=='eraser':
        i=i-6
    elif S[i-5:i]=='dream' or S[i-5:i]=='erase':
        i=i-5
    else:
        flag=False
        break
if flag==True:
    print('YES')
else:
    print('NO')

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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long mod = 1e9 + 7;
const long long block = 500;

using namespace std;

int n;
int x;
int y;
int z;
int a[N];
int b[N];
int c[N];
int p[N];
long long l[N];
long long r[N];

bool cmp(int i, int j)
{
        return a[i] - b[i] > a[j] - b[j];
}

void solve()
{
        cin >> x >> y >> z;
        n = x + y + z;
        for(int i = 1; i <= n; i++){
                cin >> a[i] >> b[i] >> c[i];
                p[i] = i;
        }
        sort(p + 1, p + n + 1, cmp);
        set < pair < int, int > > s;
        for(int ii = 1; ii <= n; ii++){
                int i = p[ii];
                l[ii] = l[ii - 1] + a[i];
                s.insert({c[i] - a[i], i});
                if(s.size() == x + 1){
                        l[ii] += (--s.end())->fi;
                        s.erase(--s.end());
                }
        }
        s.clear();
        for(int ii = n; ii >= 1; ii--){
                int i = p[ii];
                r[ii] = r[ii + 1] + b[i];
                s.insert({c[i] - b[i], i});
                if(s.size() == y + 1){
                        r[ii] += (--s.end())->fi;
                        s.erase(--s.end());
                }
        }
        long long ans = 0;
        for(int i = x; i <= n - y; i++){
                ans = max(ans, l[i] + r[i + 1]);
        }
        cout << ans << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

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

    // int x[n];
    int sum = 0;

    rep(i, n){
        int xi;
        cin >> xi;
        int disCan1 = xi; 
        int disCan2 = k - xi;
        if(disCan1 < disCan2){
            sum += disCan1 * 2;
        }else{
            sum += disCan2 * 2;
        }
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 3632
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define ft first
#define st second
#define mp make_pair
#define pb push_back
#define sz(n) int(n.size())
#define all(n) n.begin(), n.end()


using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5 + 123;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;

ll n, k, dp[1010][1010], ans, col[1010];

int main ()
{      
	cin >> n >> k;
	for (int i = 1; i <= k; i ++) dp[1][i] = 1;

	for (int i = 2; i <= n; i ++)
	{
		for (int j = 1; j <= k; j ++)
		{
			col[i] += dp[i - 1][j];
		}

		for (int j = 1; j <= k; j ++)
		{
			dp[i][j] = col[i] - dp[i - 1][j];
		}
	}

	for (int i = 1; i <= k; i ++) ans += dp[n][i];

	cout << ans << " ";
}



Measured memory_bytes: 4224
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	boolean[] used;
	int[][] data;

	p[] cnt;
	int sum=0;
	
	boolean dfs() {
		int[] value = new int[data.length];
		int[] value2 = new int[data.length];
		if (sum*8 < data.length * used.length) {
			for (int i = 0; i < used.length; i++) {
				if (!used[cnt[i].b]) {
					used[cnt[i].b] = true;
					sum += cnt[i].a;
					if (dfs()) {
						return true;
					}
					sum -= cnt[i].a;
					used[cnt[i].b] = false;
				}
			}
		}
		if (sum*8 > data.length * used.length * 3) {
			return false;
		}
		int max = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < data.length; i++) {
			for (int j = 0; j < used.length / 2; j++) {
				if (used[data[i][j]]) {
					value[i] += 1;
				} else {
					value2[i] += 1;
				}
			}
			if (value[i] > max) {
				max = value[i];
			}
			if (value[i] < min) {
				min = value[i];
			}
			if (value[i] * 8 > used.length * 3) {
				return false;
			}
		}
		if (max * 8 <= used.length * 3) {
			if (min * 8 >= used.length) {
				return true;
			}

			for (int i = 0; i < used.length; i++) {
				if (!used[cnt[i].b]) {
					used[cnt[i].b] = true;
					sum += cnt[i].a;
					if (dfs()) {
						return true;
					}
					sum -= cnt[i].a;
					used[cnt[i].b] = false;
				}
			}
		}

		return false;
	}

	class p implements Comparable<p> {
		int a;
		int b;

		@Override
		public int compareTo(p arg0) {
			return arg0.a - a;
		}

	}

	void run() {
		int n = sc.nextInt();
		int k = sc.nextInt();

		data = new int[k][n / 2];
		cnt = new p[n];
		for (int i = 0; i < n; i++) {
			cnt[i] = new p();
			cnt[i].b = i;
		}
		for (int i = 0; i < k; i++) {
			for (int j = 0; j < n / 2; j++) {
				data[i][j] = sc.nextInt() - 1;
				cnt[data[i][j]].a++;
			}
		}

		Arrays.sort(cnt);

		// System.out.println(Arrays.toString(up));

		used = new boolean[n];
		dfs();
		for (int i = 0; i < n; i++) {
			System.out.print(used[i] ? "1" : "0");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	map<int,int>m;
	for(int i=2;i<=n;++i){
		int num=i;
		for(int j=2;j<=n;++j){
			while(num%j==0){
				num/=j;
				++m[j];
			}
		}
	}
	int ans=1,mod=1e9+7;
	for(auto&i:m)ans=(int64_t)ans*(i.second+1)%mod;
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
while 1:
    N,T,L,B = map(int,raw_input().split())
    if N == 0: break
    lose = [int(raw_input()) for i in xrange(L)]
    back = [int(raw_input()) for i in xrange(B)]

    dp = [[0.0]*(N+1) for i in xrange(T+2)]
    dp[0][0] = 1.0
    ans = 0.0
    p = 1.0/6.0
    for t in xrange(T):
        for i in xrange(N):
            tt = t-1 if i in lose else t
            for j in xrange(i+1,i+7):
                if j > N: j = N-j%N
                if j in back:
                    dp[t+1][0] += p*dp[tt][i]
                else:
                    dp[t+1][j] += p*dp[tt][i]
        dp[t+1][N] += dp[t][N]
    print "%.6f"%dp[T][N]

Measured memory_bytes: 4504
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void dfs(const vector<vector<int>> &gr, vector<bool> &chk, int now, int c, int &ans){
  if(c == chk.size()){
    ans++;
    return ;
  }
  for(auto nx : gr.at(now)){
    if(chk.at(nx) == true) continue;
    chk.at(nx) = true;
    dfs(gr, chk, nx, c+1, ans);
    chk.at(nx) = false;
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> gr(n, vector<int>());
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    gr.at(a).push_back(b);
    gr.at(b).push_back(a);
  }
  vector<bool> chk(n, false);
  chk.at(0) = true;
  int ans = 0;
  dfs(gr, chk, 0, 1, ans);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define repP(i, a, b) for(int i = a; i < b; i++)
#define repM(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0, i = 0, j = 0;
  int sum = 0, num = 0, count = 0, ans = 0, min = 0, max = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[999999], a2[999999], a3[999999];
  //char s1[200000], s2[200000], s3[200000];
  //string s1, s2, s3;
  
  cin >> a >> b >> c >> d;
  if(a != c){
    cout << "1"<< endl;
  }else{
    cout << "0" << endl;
  }
}
  


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int a[100000];

int main(void){
    ll n, l; cin >> n >> l;
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 1;i < n;i++){
        if(a[i] + a[i-1] >= l){
            printf("Possible\n");
            for(int j = 1;j < i;j++)printf("%d\n", j);
            for(int j = n-1;j > i;j--)printf("%d\n", j);
            printf("%d\n", i);
            return 0;
        }
    }
    printf("Impossible\n");
	return 0;
}

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

int main() {
  long long N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string ans = "NO";
  for (int m = 0; m < N; m++) {
      if (C * (N - 1 - m) - D * m <= B - A
      && D * (N - 1 - m) - C * m >= B - A) {
          ans = "YES";
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 1;
        while(true){
            int x = sc.nextInt();
            if(x == 0) break;
            System.out.println("Case " + (i++) + ": " + x );
        }
    }
}


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

#define ll long long int

#define pi 2*acos(0.0)
#define mod 1000000007

#define fast   ios_base::sync_with_stdio(false);cin.tie(NULL);

#define pii pair<ll,ll>

#define pb push_back

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

//ll Big_Mod(ll v1, ll p, ll md)  { ll res=1; v1=v1%md; while (p > 0){if (p & 1)res = (res * v1) % md; p =p>>1; v1 = (v1 * v1) % md;}return res;}
ll ar[500009],br[500009],cr[500009],tr[500009];
map<ll,ll>mp;
vector<ll>v;
string s;

struct evan
{
    ll l,r,pos;
} st[500009];
bool com(evan i1,evan i2)
{
    return (i1.r < i2.r);
}

int main()
{
    ll a,b,c,d,e,i,j,k,x,y,z,f,g,h,n,m;
    cin>>a;
    z=0;
    for(i=1; i<=a; i++)
    {
        cin>>b;
        ar[b]++;
        z+=b;
    }
    cin>>c;
    while(c--)
    {
        cin>>x>>y;
        z-=(x*ar[x]);
        z+=y*ar[x];
        ar[y]+=ar[x];
        ar[x]=0;
        cout<<z<<endl;
    }
}


Measured memory_bytes: 4416
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

vector<P> sortX, sortY, memo, cost;


struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<long long> Size;

	UnionFind(int n)  {
	      par.resize(n+3); rank.resize(n+3); Size.resize(n+3);
		for(int i = 0; i <= n; i++) {par[i] = i; rank[i] = 0; Size[i] = 1;}
	}

	int find(int x) {if (par[x]==x) return x; else return par[x] = find(par[x]);}
	void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x==y) return;
 
        if (rank[x]<rank[y]) swap(x, y);
        if (rank[x]==rank[y]) rank[x]++;
        par[y] = x;
        Size[x] += Size[y];
  }
	bool same(int x, int y) {return find(x)==find(y);}
	long long size(int i) {return Size[find(i)];}
};


int main(void) {
    int n;
    cin >> n;
    
    rep(i, 0, n) {
      int x, y;
      cin >> x >> y;
      sortX.pb(mp(x, i));
      sortY.pb(mp(y, i));
    }
    
    sort(all(sortX));
    sort(all(sortY));
    
    rep(i, 0, n-1) {
      int dx = sortX[i+1].first - sortX[i].first;
      cost.pb(mp(dx, sz(cost)));
      memo.pb(mp(sortX[i+1].second, sortX[i].second));
    }
    
    rep(i, 0, n-1) {
      int dy = sortY[i+1].first - sortY[i].first;
      cost.pb(mp(dy, sz(cost)));
      memo.pb(mp(sortY[i+1].second, sortY[i].second));
    }
    
    sort(all(cost));
    UnionFind uf(n+1);
    
    ll ans = 0;
    rep(i, 0, sz(cost)) {
      int s = memo[cost[i].second].first, t = memo[cost[i].second].second;
      //printf("cost: %d, s: %d, t: %d\n", cost[i].first, s, t);
      if (!uf.same(s, t)) {
        ans += (ll)cost[i].first;
        uf.unite(s, t);
      }
    }
    
  
    cout << ans << "\n";
    return 0;
}




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

int main() {
    string aaa;
    int ans;
    cin >> aaa;
    if(aaa[0] == '1') {
        ans += 1;
    };
    if(aaa[1] == '1') {
        ans += 1;
    }
    if(aaa[2] == '1') {
        ans += 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll as(n), bs(n);
  ll sum = 0;
  priority_queue<P, vP, greater<P>> pq;
  rep(i, n) {
    cin >> as[i] >> bs[i];
    if(as[i] > bs[i]) pq.emplace(bs[i], i);
    sum += as[i];
  }

  if(!pq.empty()) sum -= pq.top().first;
  else sum = 0;
  
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
//#include <unordered_set>
//#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
//using ll = long long;

const int INF = 1001001001;

int main()
{
    int h(0), w(0);
	while(true){
	    cin>>h>>w;
	    if(h==0&&w==0)break;
	    rep(j, h)rep(k, w){
	        cout<<"#";
	        if(k==w-1)cout<<endl;
	    }
	    cout<<endl;
	}
}


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

int main(void){
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cin >> a[i][j];
    }
    int b[m];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = 0; j < m; j++) sum += a[i][j] * b[j];
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3136
A, B, K = map(int, input().split())
num = []
for _ in range(A, A + K):
    if _ <= B:
        num.append(_)
for _ in range(B - K + 1, B + 1):
    if A <= _:
        num.append(_)
num = sorted(list(set(num)))
for n in num:
    print(n)

Measured memory_bytes: 3060
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	int n; cin >> n;
	vector<int>arr(n, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	int a = arr[n - 1];
	int b = -114514;
	for (int i = 0; i < n; i++)
	{
		if (abs(arr[i]*2-a) < abs(b*2-a))
		{
			b = arr[i];
		}
	}
	cout << a << " " << b << "\n";
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	var A, B string
	for i := 0; i < b; i++ {
		A += fmt.Sprintf("%d", a)
	}
	for i := 0; i < a; i++ {
		B += fmt.Sprintf("%d", b)
	}
	if A < B {
		fmt.Println(A)
	} else {
		fmt.Println(B)
	}

}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  vector<P> xy(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    xy[i] = P(x, y);
  }

  vector<int> indices(n);
  iota(indices.begin(), indices.end(), 0);

  double sum = 0;
  int cnt = 0;
  do {
    for (int i = 0; i < n - 1; ++i) {
      P left = xy[indices[i]];
      P right = xy[indices[i + 1]];
      sum += sqrt(pow(left.first - right.first, 2) + pow(left.second - right.second, 2));
    }
    cnt++;
  } while(next_permutation(indices.begin(), indices.end()));
  printf("%.10lf\n", sum /cnt);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	string temp;
	getline(cin, temp);
	int q = stoi(temp);
	vector<int>a;
	REP(i, q)
	{
		string query;
		getline(cin, query);
		if (query.length() == 1)
		{
			a.pop_back();
		}
		else
		{
			switch (static_cast<int>(query[0] - '0'))
			{
			case 0:
				a.push_back(static_cast<int>(stoi(query.substr(2))));
				break;
			case 1:
				cout << a[static_cast<int>(stoi(query.substr(2)))] << endl;
				break;
			}
		}
	}
}


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

int main(){
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    if(n >= m / 2){
        ans = m / 2;
    }else{
        ans = n;
        m -= n * 2;
        ans += m / 4;
    }
    cout << ans << endl;

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] array = new int[a];
        for(int i = 0; i < a; i++){
            array[i] = sc.nextInt();
        }
        int i;
        for(i = 0; i < a - 1; i++){
            if(array[i] == array[i + 1]){
                continue;
            }else if(array[i] > (array[i + 1])){
                array[i + 1] += 1;
                if(array[i] > array[i + 1]){
                    System.out.println("No");
                    break;
                }
            }
        }
        if(i == (a -1)){
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 52844
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
 ll K;
  cin>>K;
  vector<ll> h(N);
  for(ll i=0;i<N;i++) {
cin>>h[i];
  }
  
  vector<ll> dp(N);
  dp[N-1]=0;
  for(ll i=N-2;i>=0;i--) {
    dp[i]=dp[i+1]+abs(h[i]-h[i+1]);
for(ll j=2;j<=K;j++) {
  if(i+j>N-1) {
break;
  }
  dp[i]=min(dp[i],dp[i+j]+abs(h[i]-h[i+j]));
}
  }
  
  cout<<dp[0]<<endl;
}

  
    
    
    
  


Measured memory_bytes: 4748
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
using namespace std;

ll digit(ll num) {
  ll dig;
  ll sum=0;
  while(num){
    dig=num%10;
    sum+=dig;
    num/=10;
  }
  return sum;
}

int main() {
	ll n;
	cin>>n;
	if(n%digit(n)==0) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  set<P> st;
  rep2(i, 1, n) {
    ll j = n - i + 1 - n % 2;
    ll ii = i;
    if(ii > j) swap(ii, j);
    st.insert({ii, j});
  }
  cout << n * (n - 1) / 2 - st.size() << '\n';
  rep2(i, 1, n) rep2(j, i + 1, n + 1) if(!st.count({i, j})) cout << i << ' '
                                                                 << j << '\n';
}

Measured memory_bytes: 3604
import sys
input=sys.stdin.readline
n,q=map(int,input().split())

BIT=[0]*n
def ADD(x,y):#A[x]+=y,1-origin
	while x<=n:
		BIT[x-1]+=y
		x+=x&(-x)
def SUM(l):#1からlまでの和
	ret=0
	while l>=1:
		ret+=BIT[l-1]
		l-=l&(-l)
	return ret

IN=list(map(int,input().split()))
for i in range(n):
	ADD(i+1,IN[i])

for i in range(q):
	t,a,b=map(int,input().split())
	if t==0:
		ADD(a+1,b)
	else:
		print(SUM(b)-SUM(a))

Measured memory_bytes: 127600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  set<char> st;
  ll n;
  cin >> n;
  REP(i, n) {
    char c;
    cin >> c;
    st.insert(c);
  }
  cout << (SZ(st) == 4 ? "Four" : "Three") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string str;
void solve()
{
    int i,num[3]={0},len=str.length();
    for (i=0;i<len;i++)
        num[str[i]-'a']++;
    if(num[0]==num[1]&&num[1]==num[2]) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}
int main()
{
    while(cin>>str)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

const int INF = 100000000;

void solve(int& n, int& m, int& s, int& g1, int& g2) {
  int graph[105][105];
  for(int i = 0; i < 105; i++) {
    for(int j = 0; j < 105; j++) {
      if(i == j) graph[i][j] = 0;
      else graph[i][j] = INF;
    }
  }
  int b1, b2, c;
  for(int i = 0; i < m; i++) {
    cin >> b1 >> b2 >> c;
    graph[b1][b2] = c;
  }

  // wa-syaruhuroidoooooooooooooooooooooooooooooooooooooooo!!!!!!!
  for(int k = 0; k < 105; k++) {
    for(int i = 0; i < 105; i++) {
      for(int j = 0; j < 105; j++) {
	graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
      }
    }
  }
  
  // 
  int ans = graph[s][g1] + graph[s][g2];
  for(int k = 0; k < 105; k++) {
    for(int i = 0; i < 105; i++) {
      for(int j = 0; j < 105; j++) {
	
	ans = min(ans, graph[s][k] + graph[k][g1] + graph[k][g2]);
      }
    }
  }
  cout << ans << endl;
  return ;
}

int main(){
  int n, m, s, g1, g2;
  while(cin >> n >> m >> s >> g1 >> g2) {
    if(n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0) break;
    solve(n, m, s, g1, g2);
  }
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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(){
    ll n,c; cin>>n>>c;
    vector<ll> x(n), v(n);
    rep(i,n) cin>>x[i]>>v[i];
    vector<ll> left(n), right(n);
    ll res=0;
    rep(i,n){
        if(i>0) left[i]=left[i-1]+x[i-1];
        left[i]+=v[i]-x[i];
    }
    rep(i,n){
        if(i>0) right[i]=right[i-1]+(c-x[n-i]);
        right[i]+=v[n-1-i]-(c-x[n-1-i]);
    }
    // left[0], left[1], ... left[n-1];
    // right[0], right[1], ... right[n-1];
    // left[i] + right[j] - min(x[i], c-x[n-1-j]) (i + j < n - 1)
    vector<ll> tmp1(n+1), tmp2(n+1);
    rep(i,n) tmp1[i+1] = max(tmp1[i], left[i]-x[i]);
    rep(i,n) tmp2[i+1] = max(tmp2[i], right[i]-c+x[n-1-i]);
    rep(i,n-1){
        chmax(res, left[i]);
        chmax(res, left[i]+tmp2[n-1-i]);
    }
    chmax(res, left[n-1]);

    rep(i,n-1){
        chmax(res, right[i]);
        chmax(res, right[i]+tmp1[n-1-i]);
    }
    chmax(res, right[n-1]);

    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],b[maxn],n;
using namespace std;
int main(){
	int i,l,r;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+1+n),sort(b+1,b+1+n);//自小到大排序
	if(n%2)l=a[(n+1)/2],r=b[(n+1)/2];//n是奇数
	else l=a[n/2]+a[n/2+1],r=b[n/2]+b[n/2+1];//n是偶数
	printf("%d\n",r-l+1);
	return 0;
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int main (){
	int a,b,c,v,i;
	cin>>a>>b>>c;
	if(b<a){
		v=a-b; 
	}
	if(a<b){
		v=b-a; 
	}
	if(c<a){
		i=a-c; 
	}
	if(a<c){
		i=c-a; 
	}
	if(i<v){
		cout<<"B";
	}
	if(i>v){
		cout<<"A";
		return 0;
	}
} 

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

int main(void){
  int n, x;
  cin >> n >> x;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  long long temp;
  if(a[0] > x){
    temp = a[0] - x;
    ans += temp;
    a[0] = x;
  }
  for(int i = 1; i < n; i++){
    if((a[i - 1] + a[i]) <= x) continue;
    temp = a[i] + a[i - 1] - x;
    a[i] -= temp;
    ans += temp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main()
{
        int N, ans = 1;
        cin >> N;
        vector<int> vec(N);
        rep(i, N) cin >> vec[i];

        sort(all(vec));
        cout << vec[N - 1] - vec[0] << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

class DisjointSet{
public:
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    sz.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  int findSize(int x){
    return sz[findSet(x)];
  }
};

struct Edge{
    int to,id;
    Edge(int _to,int _id){
        to=_to;
        id=_id;
    }
};

vector<int> diff;
vector<Edge> g[100010];
int used[100010];

int ans[200020];

bool dfs(int now,int par){
    for(int i=0;i<g[now].size();i++){
        int nex=g[now][i].to;
        int id=g[now][i].id;
        if(par==nex) continue;

        if(dfs(nex,now)==false){
            ans[id]=1;
            diff[now]^=1;
            diff[nex]^=1;
        }
    }
    used[now]=1;
    if(diff[now]==0) return true;
    else return false;
}

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

  vector<pair<int,int>> v;
  rep(i,N) v.push_back(mkp(A[i],i));
  sort(v.begin(),v.end());

  vector<int> C(M),D(M);
  rep(i,M){
      if(v[N-1].first<L[i]||v[0].first>R[i]){
          C[i]=-1;D[i]=-1;
          continue;
      }

      int z=lower_bound(v.begin(),v.end(),mkp(L[i],0))-v.begin();
      C[i]=z;
      int w=upper_bound(v.begin(),v.end(),mkp(R[i],N))-v.begin();
      w--;
      D[i]=w;
  }
  //rep(i,M) cout<<i<<" "<<C[i]<<" "<<D[i]<<endl;

  diff.resize(N+1,0);
  diff[0]=B[v[0].second];
  rep(i,N-1) diff[i+1]=B[v[i].second]^B[v[i+1].second];

  //rep(i,N) cout<<i<<" "<<diff[i]<<endl;

  DisjointSet us(N+1);
  rep(i,M){
      if(C[i]==-1) continue;
      if(C[i]>D[i]) continue;
      if(us.same(C[i],D[i]+1)) continue;
      us.unite(C[i],D[i]+1);
      g[C[i]].push_back(Edge(D[i]+1,i));
      g[D[i]+1].push_back(Edge(C[i],i));
  }

  vector<int> parity(N+1,0);
  rep(i,N+1){
      int tar=us.findSet(i);
      if(i==N){
          diff[N]=parity[tar];
          parity[tar]=0;
      }else parity[tar]^=diff[i]; 
  }
  rep(i,N+1){
      if(parity[i]%2){
          cout<<-1<<endl;
          return 0;
      }
  }

  rep(i,N){
      if(used[i]) continue;
      dfs(i,-1);
  }

  vector<int> res;
  rep(i,M) if(ans[i]) res.push_back(i);

  cout<<res.size()<<endl;
  rep(i,res.size()) cout<<res[i]+1<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 14452
N , M = list(map(int, input().split()))
broken = [1] * (N + 1)
for i in range(M):
  broken[int(input())] = 0
ANS = [0] * (N + 1)
ANS[0] = 1
ANS[1] = broken[1]
for i in range(N - 1):
  if(broken[i + 2]):
    if(broken[i + 1]): 
      ANS[i + 2] = (ANS[i + 1] + ANS[i]) %  (10 ** 9 + 7)
    else: 
      ANS[i + 2] = ANS[i] % (10 ** 9 + 7)
  else: ANS[i + 2] = 0
print(ANS[N])

Measured memory_bytes: 76280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////


typedef string::const_iterator State;
ll siso(State &begin);
ll jou(State &begin);
ll kak(State &begin);
ll num(State &begin);

ll num(State &begin){
    ll ret=0;
    while(isdigit(*begin)){
        ret*=10;
        ret+=*begin-'0';
        begin++;
    }
    return ret;
}
ll kak(State &begin){
    if(*begin=='('){
        begin++;
        ll ret=siso(begin);
        begin++;
        return ret;
    }else{
        return num(begin);
    }
}
ll jou(State &begin){
    ll ret=kak(begin);
    while(1){
        if(*begin=='*'){
            begin++;
            ret*=kak(begin);
        }else if(*begin=='/'){
            begin++;
            ret/=kak(begin);
        }else{
            break;
        }
    }
    return ret;
}
ll siso(State &begin){
    ll ret=jou(begin);
    while(1){
        if(*begin=='+'){
            begin++;
            ret+=jou(begin);
        }else if(*begin=='-'){
            begin++;
            ret-=jou(begin);
        }else{
            break;
        }
    }
    return ret;
}

int main(){fastio
    //freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    
    ll n;cin>>n;cin.ignore();
    while(n--){
        string s;
        getline(cin,s);
        State b=s.begin();
        cout<<siso(b)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e6 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, k, ans;

int main () {
    ios;
    cin >> n >> k;
    for(llong i = k + 1; i <= n; i++){
        for(llong j = 0; (j * i) + k <= n; j++){
            ans += min((j + 1) * i - 1, n) - max((j * i + k), 1LL) + 1;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

// E と W の出現数の累積和
VI E(N+1, 0), W(N+1, 0); 
rep(i, 0, N){
    if (S[i] == 'W') W[i+1] = W[i] + 1;
    else W[i+1] = W[i];
    if (S[i] == 'E') E[i+1] = E[i] + 1;
    else E[i+1] = E[i];
}
// rep(i, 0, N+1){ cout << W[i];}
// cout << "\n";
// rep(i, 0, N+1){ cout << E[i];}
// cout << "\n";

int mini = 1e9;

rep(i, 0, N){ // 文字上のループ
    mini = min(mini, W[i] + E[N] - E[i+1]);
}
cout << mini << "\n";

return 0;
}

// 境界，出力文字列 チェック



Measured memory_bytes: 2948
#include <stdio.h>

int main(void)
{
    int a,b,x,e,f;
    scanf("%d%d%d",&x,&a,&b);
    if (a - x > 0 ) {
        e=a-x;
    }else{
        e=x-a;
    }
    if (b - x > 0 ) {
        f=b-x;
    }else{
        f=x-b;
    }
    if(e<f){
        printf("A\n");
    }else{
        printf("B\n");
    }
    return 0;
}

Measured memory_bytes: 128