akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ATriangle {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int S;
        cin >> S;

        int m = 1000000000;
        int x2 = (S + m - 1) / m;
        int y2 = m - (S % m);
        if (y2 == m) y2 = 0;
        cout << 0 << " " << 0 << " ";
        cout << 1 << " " << m << " ";
        cout << x2 << " " << y2 << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ATriangle solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int lim=100005;

int n,m,a,b;

int wyn[lim];

vector<int>g[lim];

void dfs(int x){
	
	if(g[x].empty()) wyn[x]=1;
	for(int i=0;i<g[x].size();i++){
		if(!wyn[g[x][i]]) dfs(g[x][i]);
		wyn[x]=max(wyn[x],wyn[g[x][i]]+1);
	}
	
}

int odp;
int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	
	while(m--){
		cin>>a>>b;
		g[a].pb(b);
	}
	
	for(int i=1;i<=n;i++){
		if(!wyn[i]){
			dfs(i);
			odp=max(odp,wyn[i]);
		}
		
	}
	cout<<odp-1;
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>

using namespace std;

int dp[20][20];

int main(){
	int a,b;
	while(cin>>a>>b && a&&b){
		int n;
		cin>>n;
		for(int i=0;i<20;i++)for(int j=0;j<20;j++)dp[i][j]=0;
		for(int i=0;i<n;i++){
			int x,y;
			cin>>x>>y;
			dp[y][x]=-1;
		}
		dp[1][1]=1;
		for(int i=1;i<=b;i++){
			for(int j=1;j<=a;j++){
				if(i==1 && j==1)continue;
				if(dp[i][j]!=-1){
					dp[i][j]=dp[i][j-1]+dp[i-1][j];
				}
				else dp[i][j]=0;
			}
		}

		cout<<dp[b][a]<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
using P = pair<int,int>;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

struct UnionFind {
    vector<int> d;
    UnionFind(int n) : d(n, -1) {}
    int find(int x) {
        if(d[x]<0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x==y) return false;
        if(d[x]>d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x)==find(y);}
    int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n){
        int ans = uf.size(i) - 1 - deg[i];
        for(int u: to[i]) {
            if(uf.same(i,u)) ans--;
        }
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    return 0;
}

/*
int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> friends[n];
    vector<int> ban[n];
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    rep(i,k){
        int c,d;
        cin >> c >> d;
        c--; d--;
        ban[c].push_back(d);
        ban[d].push_back(c);
    }
    rep(i,n){
        int a;
        int ans = 0;
        queue<int> q;
        vector<int> e(n, INF);
        vector<int> f(n, INF);
        vector<int> b(n, INF);
        e[i] = 0;
        f[i] = 0;
        for(auto a: friends[i]) f[a] = 0;
        for(auto a: ban[i]) b[a] = 0;
        q.push(i);
        while(!q.empty()){
            a = q.front(); q.pop();
            for(auto s: friends[a]){
                if(e[s]!=INF) continue;
                e[s] = 0;
                q.push(s);
                if(f[s]!=INF) continue;
                if(b[s]!=INF) continue;
                ans++;
            }
        }
        cout << ans << " ";
    }
    cout << "" << endl;
    return 0;
}
*/

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

 

//(a+b)%c=(a%c+b%c)%c
//(a*b)%c=((a%c)*(b%c))%c
/*ll binaryToDecimal(ll n) 
{ 
    ll num = n; 
    ll dec_value = 0; 
  
    
    ll base = 1; 
  
    ll temp = num; 
    while (temp) { 
        ll last_digit = temp % 10; 
        temp = temp / 10; 
  
        dec_value += last_digit * base; 
  
        base = base * 2; 
    } 
  
    return dec_value; 

}    
ll countSetBits(ll n) 
{ 
    if (n == 0) 
        return 0; 
    else
        return 1 + countSetBits(n & (n - 1)); 
} */
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
	

    string s;
    cin>>s;int a=0;int b=0;
    for(int i=0;i<3;i++){
        if(s[i]=='A')a++;
    }
    for(int i=0;i<3;i++){
        if(s[i]=='B')b++;
    }
    if(a*b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    }
    
    
    
	

Measured memory_bytes: 256
a, b = map(int, input().split())
min_a = a//0.08
max_a = (a+1)//0.08
min_b = b//0.1
max_b = (b+1)//0.1
a_array = set(range(int(min_a)+1, int(max_a)))
b_array = set(range(int(min_b)+1, int(max_b)))
common = a_array & b_array
print("-1" if len(common) == 0 else min(common))


Measured memory_bytes: 38768
#include<iostream>
using namespace std;
int main()
{
	int N,unit;
  cin>>N;
  unit=N%10;
  if(unit==2 || unit==4 || unit==5 || unit==7 || unit==9)
  {
  	cout<<"hon"<<endl;
  }
  	else if(unit==3 )
  {
  	cout<<"bon"<<endl;
  }
   if(unit==0 || unit==1  || unit==6 || unit==8)
  {
  	cout<<"pon"<<endl;
  }
 
 
return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define NOT_FOUND 0
int A[100000];
int n;
int binarySearch(int key){
  int mid,left=0,right = n;
  while(left<right){
    mid = (left + right) /2;
    if(A[mid]==key){
      return 1;
    }else if(key<A[mid]){
      right = mid;
    }else {
      left = mid + 1;
    }
  }
  return NOT_FOUND;
}
int main(){
  int i,key,a,cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&key);
    if(binarySearch(key)) cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 988
#include<stdio.h>
int main() {
    int h, w, i, j,flag,flag2;
    char s[60][60],sc[60];
    scanf("%d%d", &h, &w);
    for (i = 1; i <= h; i++) {
        scanf("%*c");
        scanf("%s", sc);
        for (j = 1; j <= w; j++)
            s[i][j] = sc[j-1];
    }
    flag2 = 1;
    for (i = 1; i <= h; i++) {
        for (j = 1; j <= w; j++) {
            flag = 0;
            if (s[i][j] == '#') {
                if (i != 1 && s[i - 1][j] == '#')
                    flag = 1;
                if (i != h && s[i + 1][j] == '#')
                    flag = 1;
                if (j != 1 && s[i][j - 1] == '#')
                    flag = 1;
                if (j != w && s[i][j + 1] == '#')
                    flag = 1;
            }
            else
                flag = 1;
            if (flag == 0)
                flag2 = 0;
        }
    }
    if (flag2 == 1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int cnt = 0;
	int rem = 0;
	for (int i = 0; i < s.size(); i++) {
		if (cnt > 0 && s[i] == 'T') {
			rem += 2;
			cnt--;
		} else if (s[i] == 'T') {
			cnt = 0;
		} else if (s[i] == 'S') cnt++;
	}
	cout << s.size() - rem << endl;
	return 0;
}

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

#define ll long long int
#define ld long double
#define pb push_back

ll mod = 1000000007;

using namespace std;

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 int n,k;
	 cin>>n>>k;
	 string str;
	 cin>>str;

	 int ans = 0;

	 for (int i = 1; i < n; ++i)
	 {
	 	if(str[i-1] == str[i])
	 		ans++;
	 }

	 cout<<min(n-1,ans+k*2);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

int main() {
  ll n;
  cin >> n;
  if (n & 1) cout << 0;
  else {
    n /= 10;
    ll ans = n;
    while (n) {
      ans += n / 5;
      n /= 5;
    }
    cout << ans;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(){
  int n, m;
  cin >> n;
  string s[n];
  map<string, int> bcnt;
  for(int i=0; i<n; i++){
    cin >> s[i];
    bcnt[s[i]]++;
  }

  cin >> m;
  string t[m];
  map<string, int> rcnt;
  for(int i=0; i<m; i++){
    cin >> t[i];
    rcnt[t[i]]++;
  }

  int ans=0;
  for(int i=0; i<n; i++){
    ans=max(ans, bcnt[s[i]]-rcnt[s[i]]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int i,j;

	for(i = 1;i <= 9;i++){
		for(j = 1;j <= 9;j++){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1112
#include <cstdio>
#include <algorithm>

using namespace std;

#define rep(i,x) for(int i=0;i<(x);++i)

int mp[10][10000];
bool f[10];

signed main()
{
	int R, C;
	while (scanf("%d%d", &R, &C), R || C) {
		rep(i, R) rep(j, C) {
			scanf("\n%d", &mp[i][j]);
		}

		int ma = 0;

		rep(i, 1 << R) {
			fill_n(f, R, 0);
			rep(j, R) {
				if (i >> j & 1) f[j] = 1;
			}

			int sum = 0;

			rep(k, C) {
				int cnt = 0;
				rep(l, R) {
					if (mp[l][k] == f[l]) cnt++;
				}

				sum += max(cnt, R - cnt);
			}

			ma = max(ma, sum);
		}

		printf("%d\n", ma);
	}
}

Measured memory_bytes: 1416
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,q=map(int,input().split())
s=input().rstrip()
ac=[0]*(n+1)
for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        ac[i+1]=ac[i]+1
    else:
        ac[i+1]=ac[i]
for i in range(q):
    l,r=map(int,input().split())
    print(ac[r-1]-ac[l-1])

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

using namespace std;

#define int long long

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

typedef pair<int, int> PII;

//--------

vector<PII> vec;

bool comp(PII a, PII b){
    return a.first < b.first;
}

signed main(){  
    int N, M;
    cin >> N >> M;

    REP(i, N){
        int a, b;
        cin >> a >> b;
        vec.push_back({a, b});
    }
    sort(vec.begin(), vec.end(), comp);

    int bought = 0;
    int much = 0;

    for(int i = 0; i < vec.size(); i++){
        //cout << vec[i].first << endl;
        if(bought + vec[i].second > M){
            vec[i].second = M - bought;
        }
        bought += vec[i].second;
        much += vec[i].second * vec[i].first;
    }

    cout << much << endl;

    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int lazy[N*3];
int n;
int A[N];
int B[N];
int f[N],l[N];
int C[N];

void update(int node,int l,int r,int b,int e)
{
    if(e<l||r<b)
        return;
    if(b<=l&&r<=e)
    {
        lazy[node]=1;
        return;
    }
    update(node*2,l,(l+r)/2,b,e);
    update(node*2+1,(l+r)/2+1,r,b,e);
    return;
}
int query(int node,int l,int r,int p,int c=0)
{
    if(p<l||r<p)
        return 1;
    c|=lazy[node];
    if(l==r)
    {

        return c==0;
    }
    return query(node*2,l,(l+r)/2,p,c)*query(node*2+1,(l+r)/2+1,r,p,c);
}


main()
{
    memset(f,-1,sizeof f);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        if(f[A[i]]==-1) f[A[i]]=i;
        l[A[i]]=i;
    }
    for(int i=0;i<n;i++)
    {
        cin>>B[i];
        if(f[B[i]]!=-1)
        {

            int g,h;
            if(f[B[i]]>=i)
            {
                g=f[B[i]]-i;
            }
            else
            {
                g=n-i+f[B[i]];
            }

            if(l[B[i]]>=i)
            {
                h=l[B[i]]-i;
            }
            else
            {
                h=n-i+l[B[i]];
            }
            if(g<=h)
            {
                update(1,0,n-1,g,h);
            }
            else
            {
                update(1,0,n-1,g,n-1);
                update(1,0,n-1,0,h);
            }
           // cout<<"G: "<<g<<' '<<h<<endl;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(query(1,0,n-1,i,0))
        {
            //cout<<i<<endl;
            for(int j=0;j<n;j++)
            {
                C[(j+i)%n]=B[j];
            }
            cout<<"Yes\n";
            for(int j=0;j<n;j++)
                cout<<C[j]<<' ';
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 9252
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << ' ' <<  X << ' ' << Y << endl;
    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct C
{
	int P, Y, i;
};
vector<C> city;
int num[100010];

string Sub(int n)
{
	string S = to_string(n);
	string res;
	rep(i, 0, 6 - SZ(S))
	{
		res += "0";
	}
	res += S;
	return res;
}

string F(int P, int x)
{
	return Sub(P) + Sub(x);
}

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

	int N, M, P, Y;
	cin >> N >> M;
	rep(i, 0, M)
	{
		cin >> P >> Y;
		city.push_back({ P,Y,i });
	}

	sort(all(city), [](const C& a, const C& b) {return a.Y < b.Y; });

	vector<pair<int, string>> id;
	rep(i, 0, SZ(city))
	{
		id.push_back(mp(city[i].i, F(city[i].P, num[city[i].P] + 1)));
		num[city[i].P]++;
	}

	sort(all(id));

	for (auto& p : id)
	{
		cout << p.second << endl;
	}

	return 0;
}

Measured memory_bytes: 12272
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

bool used[100010];
bool usedt[100010];
ll maxi[100010];

int main(){
    ll n,k;cin>>n>>k;
    ll t[n],d[n];
    vector<l_l> p;
    vector<vector<ll>> v(100010);
    
    rep(i,0,n-1){
        cin>>t[i]>>d[i];
        p.pb(make_pair(d[i],t[i]));
        v[t[i]].pb(d[i]);
    }
    sort(p.begin(),p.end(),greater<l_l>());
    ll ans=0;
    ll sum=0;
    ll c=0;
    vector<ll> out;
    vector<l_l> in;
    rep(i,0,k-1){
        ans+=p[i].first;
        used[i]=true;
        if(usedt[p[i].second]==false){
            usedt[p[i].second]=true;
            c++;
            maxi[p[i].second]=p[i].first;
        }else{
            if(maxi[p[i].second]>p[i].first){
                out.pb(p[i].first);
            }else{
                out.pb(maxi[p[i].second]);
                maxi[p[i].second]=p[i].first;
            }
        }
    }
    ans=ans+c*c;
    sum=ans;
    rep(i,1,n){
        if(usedt[i]==false){
            if(v[i].size()!=0){
                rep(j,0,v[i].size()-1){
                    in.pb(make_pair(v[i][j],i));
                }
            }
        }
    }
    sort(out.begin(),out.end());
    sort(in.begin(),in.end(),greater<l_l>());
    ll j=0;
    bool b;
    sum=ans;
    
    if(in.size()!=0 && out.size()!=0){
    
    rep(i,0,out.size()-1){
        
        
        b=true;
        sum=sum-out[i];
        while(b){
            if(usedt[in[j].second]){
                j++;
                if(j>=in.size()){
                    break;
                }
            }else{
                sum=sum+in[j].first;
                usedt[in[j].second]=true;
                sum=sum-c*c;
                j++;
                c++;
                sum=sum+c*c;
                ans=max(sum,ans);
                if(j>=in.size()){
                    break;
                }
                b=false;
            }
        }
        if(b){
            break;
        }
    }
        
    }
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 11760
#include<stdio.h>
int main(void)
{
	int a,b,c,s;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a==b){
	s=c;
	}
	if(c==b){
	s=a;
	}
	if(a==c){
	s=b;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define v_in(v) for(auto&& i : v) cin >> i
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;


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

    ll n = (ll)s.size();
    ll ans = 1000000000;
    rep(i,n-2){
        string x = s.substr(i,3);
        assign_min(ans,(ll)abs(753 - stoi(x)));
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
  string s;
  cin >> s;
  int leng = s.length();
  vector<int> child(leng,0);
  int j = 0,k1 = 0,k2 = 0,sw = 0;
  froop1(0,leng - 1){
    if(s[i] == 'R' && s[i + 1] == 'L'){
      k1 = i;k2 = i + 1;sw = 1;
      child.at(k1) = 1;child.at(k2) = 1;
    }else if(s[i] == 'L' && s[i + 1] == 'R'){
      int l = i; 
      child.at(k1) += (k1 - j) / 2 + (l - k1) / 2;
      child.at(k2) += (k2 - j) / 2 + (l - k2) / 2;
      j = i + 1;
      sw = 0;
    }
  }
  if(s[leng - 2] == 'R' && s[leng - 1] == 'L'){
    child.at(leng - 2) = 1;
    child.at(leng - 1) = 1;
  }
  if(sw == 1){
	  child.at(k1) += (k1 - j) / 2 + (leng - 1 - k1) / 2;
      child.at(k2) += (k2 - j) / 2 + (leng - 1 - k2) / 2;
  }
froop1(0,leng){
cout << child.at(i);
  if(i != leng - 1){
    cout << " ";
  }else{
    cout << endl;
  }
  }
}

Measured memory_bytes: 3788
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

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")
}

fn main() {
    let ai: Vec<u32> = (0..3).map(|_| read()).collect();


    let uniq: HashSet<u32> = ai.into_iter().collect();
    if uniq.len() == 2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
	int n,s;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s;
		cout << "Case " << i + 1 << ":" << endl;
		for(int j = 0;j < 10;j++){
			s = (s * s / 100) % 10000;
			cout << s << endl;
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> cnt(13);
    for(int i = 0; i < n; i++){
        int d;
        cin >> d;
        cnt[d]++;
    }
    vector<int> aa;
    aa.push_back(0);
    if(cnt[0] || cnt[12] >= 2){
        cout << 0 << endl;
        return 0;
    }
    if(cnt[12] == 1)
        aa.push_back(12);
    int ans = 0;
    for(int b = 0; b < (1 << 11); b++){
        vector<int> a = aa;
        for(int i = 0; i < 11; i++){
            int j = i+1;
            if(cnt[j] == 1){
                if(b >> j & 1)
                    a.push_back(j);
                else
                    a.push_back(24-j);
            } else if(cnt[j] == 2){
                a.push_back(j);
                a.push_back(24-j);
            } else if(cnt[j] >= 3){
                cout << 0 << endl;
                return 0;
            }
        }
        int mn = 24;
        a.push_back(24);
        sort(a.begin(), a.end());
        for(int i = 0; i+1 < a.size(); i++){
            if(mn > a[i+1]-a[i]) mn = a[i+1]-a[i];
        }
        if(ans < mn) ans = mn;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
 int a,c,d;
  cin>>a>>c;
  for(int i=0;i<2;i++){
     if(a<c){
       d+=c;
         c--;
     }
  else{
 d+=a;
   a--;
  }
    }
       cout<<d<<endl;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Array.IO

data DisjointSet = DS { parent :: Int
                      , rank :: Int
                      } deriving (Show)

type DisjointForest = IOArray Int DisjointSet

main = do
        [n,q] <- map read.words<$>getLine
        qs <- replicateM q $ map read.words<$>getLine
        dsf <- newListArray (0,n-1) $ map (\x -> DS x 0) [0..n-1]
        execStateT (sequence_ $ map inpToQuery qs) dsf

inpToQuery [c,x,y]
    | c == 0 = unite x y
    | c == 1 = same x y

modifyArray :: Ix i => IOArray i a -> i -> (a -> a) -> IO ()
modifyArray arr ix f = do
        e <- readArray arr ix
        writeArray arr ix (f e)

makeSet :: Int -> StateT DisjointForest IO ()
makeSet x = get >>= \arr -> liftIO $ modifyArray arr x (\_ -> DS x 0)


findSet :: Int -> StateT DisjointForest IO Int
findSet x = do
        f <- get
        x' <- liftIO $ parent<$>readArray f x
        if x == x' then return x
                   else findSet x'

findSet' :: [Int] -> Int -> StateT DisjointForest IO Int
findSet' acc x = do
        f <- get
        x' <- liftIO $ parent<$>readArray f x
        if x == x' then do
                    liftIO $ mapM_ (\a -> modifyArray f a (\ds -> ds {parent = x'})) acc
                    return x'
                   else findSet' (x:acc) x'

union :: Int -> Int -> StateT DisjointForest IO ()
union x y = do
        f <- get
        liftIO $ modifyArray f x (\ds -> ds {parent = y})
        liftIO $ modifyArray f x (\ds -> ds {rank = rank ds + 1})

union' x y = do
        f  <- get
        x' <- findSet' [] x
        y' <- findSet' [] y
        liftIO $ unionIO f x' y'

unionIO arr x y = do
        rankX <- rank<$>readArray arr x
        rankY <- rank<$>readArray arr y
        case rankX `compare` rankY of
            GT -> modifyArray arr y (\ds -> ds {parent = x})
            EQ -> modifyArray arr x (\ds -> ds {parent = y, rank = rank ds+1})
            LT -> modifyArray arr x (\ds -> ds {parent = y})


same :: Int -> Int -> StateT DisjointForest IO ()
same x y = do
        x' <- findSet' [] x
        y' <- findSet' []  y
        f <- get
        if x' == y' then liftIO $ putStrLn "1"
                    else liftIO $ putStrLn "0"

unite :: Int -> Int -> StateT DisjointForest IO ()
unite x y = do
        x' <- findSet' [] x
        y' <- findSet' [] y
        union' x' y'

Measured memory_bytes: 81004
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


string s;

bool ispa(string s){
  int N = s.size();
  for(int i = 0; i < N/2;i++){
    if(s[i] != s[N-i-1]){
      return false;
    }
  }
  return true;
}




int main(){
  cin >> s;
  int si = s.size()/2;
  string t = s.substr(0,si);
  string u = s.substr(si+1,si);
  if(ispa(t) && ispa(u) && ispa(s)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <deque>
#include <vector>

using namespace std;

struct Query {
	int t, f;
	char c;
};

class Solution {
public:
	string stringFormation(const string& s, const vector<Query>& queries) {
		deque<char> buf;
		for (char c : s)
			buf.push_back(c);

		bool reversed = false;
		for (const auto& query : queries) {
			if (query.t == 1) {
				reversed = !reversed;
			} else {
				if (reversed) {
					if (query.f == 1)
						buf.push_back(query.c);
					else
						buf.push_front(query.c);
				} else {
					if (query.f == 1)
						buf.push_front(query.c);
					else
						buf.push_back(query.c);
				}
			}
		}

		string ans;
		for (char c : buf)
			ans.push_back(c);
		if (reversed)
			reverse(ans.begin(), ans.end());
		return ans;
	}
};

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

	vector<Query> queries(q);
	for (int i = 0; i < q; ++i) {
		cin >> queries[i].t;
		if (queries[i].t == 2)
			cin >> queries[i].f >> queries[i].c;
	}

	Solution sol;
	const string ans = sol.stringFormation(s, queries);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3720
#include <cstdio>
using namespace std;
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
    
    if(a < b && b < c)
    {
	    printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}

Measured memory_bytes: 2584
#include "bits/stdc++.h"
#include <unordered_map>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int n;
	cin >> n;

	unordered_map<string, int> cnt;


	REP(i, n)
	{
		string s;
		cin >> s;

		if (cnt.count(s) == 0)
		{
			cnt[s] = 0;
		}

		cnt[s]++;
	}

	cout << cnt.size();

	return 0;
}

Measured memory_bytes: 17700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 200105;
ll pre[maxn];
ll inv[maxn];
ll prei[maxn];
void build(int n){
    pre[1] = pre[0] = 1, inv[1] = inv[0] = 1, prei[1] = prei[0] = 1;
    for(int i = 2 ; i <= n ; i++){
        pre[i] = pre[i-1] * i % mod;
        inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
        prei[i] = prei[i-1] * inv[i] % mod;
    }
}
ll C(int n, int k){
   return pre[n] * prei[k] % mod * prei[n-k] % mod;
}
ll P(int n, int k) {
    return pre[n] * prei[n - k] % mod;
}
ll pm(int n,int p){
    ll ret = 1;
    ll now = n;
    while(p){
        if(p & 1){
            ret *= now;
            ret %= mod;
        }
        now *= now;
        now %= mod;
        p >>= 1;
    }
    return ret;
}

void go() {
	int h, w, n;
	cin >> h >> w >> n;
	build(h+w+5);
	vector<pair<int,int>>v;
	ll ans[n] = {};
	f(n) {
		int x, y;
		cin >> x >> y;
		v.pb({x, y});
	}
	sort(all(v));
	f(n) {
		ans[i] = C(v[i].F + v[i].S - 2, v[i].F - 1);
		fr(j,0,i) {
			if (v[j].F <= v[i].F && v[j].S <= v[i].S) {
				ans[i] -= ans[j] * C(v[i].F - v[j].F + v[i].S - v[j].S, v[i].F - v[j].F) % mod;
				ans[i] += mod;
				ans[i] %= mod;
			}
		}
	}
	ll tot = C(w + h - 2, w - 1);
	f(n) {
		tot -= ans[i] * C(h-v[i].F + w - v[i].S, h - v[i].F) % mod;
		tot += mod;
		tot %= mod;
	}
	cout << tot << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 8412
#include<stdio.h>
int ara[101];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    while(k--){
    int p,temp;
    scanf("%d",&p);
    while(p--){
    scanf("%d",&temp);
    ara[temp]++;
    }}
    int i=n;
    int count=0;
    while(i!=0){
    if(ara[i]==0)
    count++;
    i--;
    }
    printf("%d",count);
    
   
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int n;
  cin >> n;
  int table[100002] = {0};
  
  REP(i,n){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    table[a]++;
    table[b+1]--;
  }

  // シミュレート
  for (int i = 0; i < 100002; i++){
    if (0 < i) table[i] += table[i - 1];
  }
  // 最大値を調べる
  int M = 0;
  for (int i = 1; i <= n; i++) {
    if(table[i] >= i){
      M = max(i,M);
    }
    else{
      //M = max(table[i],M);
    }
  }
  cout << M << endl;
  return 0;
}



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

using namespace std;

int main() {
  int H, W;
  for (;;) {
    cin >> H >> W;
    if (!H && !W)
      break;

    for (int i = 0; i < H; ++i) {
      const char c = i % 2 == 0 ? '#' : '.';
      const char d = c == '#' ? '.' : '#';
      for (int j = 0; j < W; ++j) {
        if (j % 2 == 1)
          printf("%c", d);
        else
          printf("%c", c);
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3060
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;

int N;

long double dp[305][305][305];

long double rec(int i, int j, int k) {
    if (i == 0 && j == 0 && k == 0) return dp[0][0][0];
    if (dp[i][j][k] != 0) return dp[i][j][k];

    long double res = 0.0;
    if (i > 0)res += rec(i - 1, j, k) * i;
    if (j > 0)res += rec(i + 1, j - 1, k) * j;
    if (k > 0)res += rec(i, j + 1, k - 1) * k;

    res += (long double) N;
    res /= (long double) (i + j + k);
    dp[i][j][k] = res;
    return res;

}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        cin >> N;
        int one = 0, two = 0, three = 0;
        for (int i = 0; i < N; i++) {
            int x; cin >> x;
            if (x == 1) one++;
            else if (x == 2) two++;
            else three++;
        }
        memset(dp, 0, sizeof(dp));

        long double ans = rec(one, two, three);
        cout << setprecision(20) << ans << endl;

    }
    return 0;

}



Measured memory_bytes: 443648
import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.HashMap

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  br.readLine()

  val map = hashMapOf<Int, Int>()
  br.readLine().split(" ").map { it.toInt() }
    .forEach { key ->
      val v = map.getOrElse(key) {0}
      map.put(key, v + 1)
    }

  val ans = map.entries.fold(0L) { acc, entry ->
    val(k, v) = entry
    if(k > v) acc + v else acc + (v - k)
  }

  println(ans)
}

Measured memory_bytes: 61708
n,a,b,c,d = map(int, input().split())
s = input()

if '##' in s[a-1:c] or '##' in s[b-1:d]:
    print('No')
else:
    if c<d:
        print('Yes')
    else:
        if '...' in s[b-2:d+1]:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 9260
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

void solve() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> a(n * n, -1);
  set<int> free_places;
  for (int i = 0; i < n * n; i++) {
    free_places.insert(i);
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    --x[i];
    a[x[i]] = i;
    free_places.erase(x[i]);
    res += i;
  }
  auto no = []() {
    cout << "No" << endl;
    exit(0);
  };
  while (free_places.size() > res) {
    auto it = free_places.end();
    --it;
    free_places.erase(it);
  }
  for (int i = 0; i < n; i++) {
    int on_left = i;
    while (on_left--) {
      auto it = free_places.lower_bound(x[i]);
      if (it == free_places.begin()) {
        no();
      }
      --it;
      a[*it] = i;
      free_places.erase(it);
    }
  }
  free_places.clear();
  for (int i = 0; i < n * n; i++) {
    free_places.insert(i);
  }
  for (int i = 0; i < n * n; i++) {
    if (a[i] == -1) {
      continue;
    }
    free_places.erase(i);
  }
  for (int i = 0; i < n; i++) {
    int on_right = n - i - 1;
    while (on_right--) {
      auto it = free_places.lower_bound(x[i]);
      if (it == free_places.end()) {
        no();
      }
      a[*it] = i;
      free_places.erase(it);
    }
  }
  cout << "Yes\n";
  for (auto x : a) {
    cout << x + 1 << " ";
  }
  cout << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5, maxK = 10; int n, k;
pair<int, int> lr[maxK];

vector<int> s[maxK];
const lli mod = 998244353;
lli memo[maxN];

int lowerBound(int j, int target)
{
  int lo = 0, hi = s[j].size() - 1;
  while (lo < hi)
  {
    int mid = (lo + hi + 1) >> 1;
    if (s[j][mid] <= target) lo = mid;
    else hi = mid - 1;
  }
  return s[j][lo] <= target ? lo : -1;
}

struct Data
{
  lli value;
  Data operator+(const Data &other)
  {
    return Data{(value + other.value) % mod};
  }
};
const Data nil = Data{0LL};

// DON'T FORGET TO DEFINE THE NIL!!!
template<class T>
struct Segtree
{
  int size;
  T nil;
  vector<T> data;
  vector<T> st;
  Segtree() { }
  Segtree(int size, T nil) : size(size), nil(nil)
  {
    data.resize(size);
    st.resize(4*size);
  }
  Segtree(vector<T> &data, T nil) : size(data.size()), data(data), nil(nil)
  {
    st.resize(4*size);
    build();
  }
  void build() { build(1, 0, size - 1); }
  T query(int qlo, int qhi) { return query(qlo, qhi, 1, 0, size - 1); }
  void update(int pos, T value) { update(pos, value, 1, 0, size - 1); }
  void build(int i, int lo, int hi)
  {
    if (lo == hi)
    {
      st[i] = data[lo];
      return;
    }
    int mid = (lo + hi) >> 1;
    build(2*i, lo, mid), build(2*i + 1, mid + 1, hi);
    st[i] = st[2*i] + st[2*i + 1];
  }
  T query(int qlo, int qhi, int i, int lo, int hi)
  {
    if (hi < qlo || lo > qhi) return nil;
    if (lo >= qlo && hi <= qhi) return st[i];
    int mid = (lo + hi) >> 1;
    return query(qlo, qhi, 2*i, lo, mid) + query(qlo, qhi, 2*i + 1, mid + 1, hi);
  }
  void update(int pos, T &value, int i, int lo, int hi)
  {
    if (lo == hi)
    {
      st[i] = (st[i] + value);
      return;
    }
    int mid = (lo + hi) >> 1;
    if (pos <= mid) update(pos, value, 2*i, lo, mid);
    else update(pos, value, 2*i + 1, mid + 1, hi);
    st[i] = st[2*i] + st[2*i + 1];
  }
};
Segtree<Data> segtree;

int main()
{
  while (scanf("%d %d", &n, &k) != EOF)
  {
    for (int i = 0; i < k; i++)
    {
      s[i].clear();
      scanf("%d %d", &lr[i].first, &lr[i].second);
      for (int j = 0, end = lr[i].second - lr[i].first + 1; j < end; j++)
        s[i].push_back(lr[i].first + j);
    }
    segtree = Segtree<Data>(n + 1, nil);
    for (int i = 0; i <= n; i++)
      segtree.data[i].value = 0;
    segtree.build();

    // memset(memo, 0, sizeof(memo));
    // memo[0] = 1;
    segtree.update(0, Data{1LL});
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < k; j++)
      {
        int last = lowerBound(j, i);
        if (last >= 0)
        {
          Data got = segtree.query(i - s[j][last], i - s[j][0]);
          // for (int jj = 0; jj <= last; jj++)
          //   segtree.update(i, segtree.query(i - s[j][jj], i - s[j][jj]));
            // memo[i] = (memo[i] + memo[i - s[j]]) % mod;
          segtree.update(i, got);
        }
      }

    lli ans = segtree.query(n - 1, n - 1).value;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 11972
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 100010
#define MAX 2156
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;
 
ll a[N],cube[MAX];
int primes[N],prime[MAX],sq[MAX];
unordered_map <ll, ll> conjugate;
unordered_map <ll, int> vis,cnt;
 
int make()
{
	int i,j,k=0,cnt;
	FILL(primes,0);
	primes[0]=1;
	primes[1]=1;
	for(i=2;i<N;i++)
	{
		if (primes[i]) continue;
		if (i<MAX) prime[k++]=i;
		for(j=2*i;j<N;j+=i) primes[j]=1;
	}
	return k;
}
 
int main()
{
	ll n,ans=0,x,y,z,a2,flag,a1,b=1ll*(N-10)*(N-10);
	a2=make();
	scanf("%lld",&n);
	REP(i,MAX)
	{
		cube[i]=1ll*i*i*i;
		sq[i]=1ll*i*i;
	}
	REP(i,n)
	{
		scanf("%lld",&a[i]);
		//printf("%d %d\n",i,n);
		REP(j,a2)
		{
			if (a[i]<cube[prime[j]]) break;
			while (a[i]%cube[prime[j]]==0) a[i]/=cube[prime[j]];
		}
		cnt[a[i]]++;
		if (vis[a[i]]) continue;
		vis[a[i]]=1;
		x=a[i];
		if (x==1)
		{
			conjugate[x]=1;
			continue;
		}
		z=1;
		flag=0;
		REP(j,a2)
		{
			a1=sq[prime[j]];
			if (x%a1==0)
			{
				z*=prime[j];
				x/=a1;
				if (z>b) {flag=1; break;}
				if (x==1) break;
			}
			else if (x%prime[j]==0)
			{
				z*=a1;
				x/=prime[j];
				if (z>b) {flag=1; break;}
				if (x==1) break;
			}
		}
		if (flag) conjugate[a[i]]=-1;
		else
		{
			if (x>1)
			{
				if (x<(N-10)&&!primes[x])
				{
					z*=x;
					if (z>b)
						conjugate[a[i]]=-1;
					else
					{
						z*=x;
						if (z>b)
							conjugate[a[i]]=-1;
						else conjugate[a[i]]=z;
					}
				}
				else
				{
					y=sqrt(x);
					if (y*y!=x) conjugate[a[i]]=-1;
					else
					{
						z*=y;
						if (z>b) conjugate[a[i]]=-1;
						else conjugate[a[i]]=z;
					}
				}
			}
			else conjugate[a[i]]=z;
		}
	}
	//REP(i,n) printf("%lld %lld\n",a[i],conjugate[a[i]]);
	REP(i,n) vis[a[i]]=0;
	REP(i,n)
	{
		if (vis[a[i]]) continue;
		vis[a[i]]=1;
		a1=conjugate[a[i]];
		if (a1==-1) ans+=cnt[a[i]];
		else
		{
			vis[a1]=1;
			ans+=max(cnt[conjugate[a[i]]],cnt[a[i]]);
		}
	}
	if (cnt[1]) ans-=(cnt[1]-1);
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 19252
# -*- coding: utf-8 -*-

r, c = map(int, raw_input().split())
mat = {}
for i in range(1, r+1):
    col = map(int, raw_input().split())
    for j in range(1, c+1):
        mat[(i, j)] = col[j-1]

for i in range(1, r+1):
    mat[(i, c+1)] = 0
    for j in range(1, c+1):
        mat[(i, c+1)] += mat[(i, j)]

for j in range(1, c+2):
    mat[(r+1, j)] = 0
    for i in range(1, r+1):
        mat[(r+1, j)] += mat[(i, j)]

for i in range(1, r+2):
    buf = ""
    for j in range(1, c+1):
        buf += str(mat[(i, j)]) +" "
    buf += str(mat[(i, c+1)])
    print buf

Measured memory_bytes: 7684
using System;
using System.Collections.Generic;
using System.Linq;

class Program
    {
        static void Main(string[] args){
            List<int> n = new List<int>();
            int r,i;
            string s;
            while (true) {
                s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                n.Add(int.Parse(s));
            }
            foreach (int n1 in n)
            {
                r = 0;
                for (i = 1; i <= n1; i++)
                {
                    if (IsPrime(i)) r++;
                }
                Console.WriteLine(r);
            }
            Console.ReadLine();
        }

        static bool IsPrime(int x) {
            bool b=true;
            if (x < 2) return false;
            if (x == 2) return true;
            if (x % 2 == 0) return false;
            for (int i = 3; i < 1000; i+=2) {
                if (x % i == 0&&x/i>1) {b=false; break;}
            }
            return b;
        }

    }

Measured memory_bytes: 9088
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
S=list(map(int,input().split()))
S.sort()
sl=[S.pop()]
for _ in range(N):
    stack=[]
    for i in range(len(sl)):
        x=sl[i]
        while S:
            y=S.pop()
            if y<x:
                sl.append(y)
                break
            else:
                stack.append(y)
        else:
            print('No')
            exit()
    S.extend(stack[::-1])
    sl.sort(reverse=1)
print('Yes')

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


int main() {
	string s;
	cin >> s;
	vector<char> d;
  int t =s.size();
  for (int i = 0; i <t; ++i) {
    if(s[i]=='B'){
		if(d.size()){
			d.pop_back();}
			}
    else{d.push_back(s[i]);}
  }
  for(auto x:d){cout << x;}
}

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

int main() {
	ll k;
	cin >> k;
	ll ans = 0;
	for (ll i = 1; i <= k; ++i) {
		for (ll j = 1; j <= k; ++j) {
			for (ll h = 1; h <= k; ++h) {
				ans += gcd(gcd(i, j), h);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#define mod 1000000007
using namespace std;



int main()
{
    int m,n,o=0,i,j,k;
    int sum=0,range=0;
    //long long int m,n,o,i,j,k;
    //vector <int> v;
    //float f,g,h;
    //char c,d;
    //string a;
    cin>>n>>k;
    int *height=new int [n];
    for(i=0;i<n;i++) cin>>height[i];
    sort(height,height+n);
    range=height[k-1]-height[0];
    for(i=1;i<=n-k;i++)
    {
        range=min(range,height[i+k-1]-height[i]);
    }
    cout<<range;
    //cin>>m>>c>>n>>d>>i;
    //cin>>f>>g;
    //cin>>c;
    delete [] height;
    return 0;
}





Measured memory_bytes: 640