akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;

int n,p[101],q[101],r[101],b[101];
bool flg[101]; //上からつるされているかのフラグ

//最大公約数
int gcd(int a,int b){
  return b == 0 ? a : gcd(b,a%b);
}

//最小公倍数
int lcm(int a,int b){
  return a / gcd(a,b) * b;
}

int solve(int idx){
  int res = 0;

  int rcost = r[idx] ? solve(r[idx]) : 1;
  int bcost = b[idx] ? solve(b[idx]) : 1;
  int l = lcm(p[idx] * rcost, q[idx] * bcost);

  return l / p[idx] + l / q[idx];
}

int main(void){
  while(cin>>n, n){
    memset(flg,0,sizeof(flg));
    for(int i=1;i<=n;i++){
      cin>>p[i]>>q[i]>>r[i]>>b[i];
      flg[r[i]] = flg[b[i]] = true; //上からつるされている棒をtrueにする
    }

    for(int i=1;i<=n;i++){
      //上からつるされていない棒ならば, ルートノード
      if(!flg[i]){
        cout<<solve(i)<<endl;
        break;
      }
    }
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    while (x%2 == 0) {
      ans ++;
      x /= 2;
    }
  }

  cout << ans << endl;
}

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int K;
        string S;
        cin >>K >>S;
        if (K>=S.size())
                cout <<S <<endl;
        else
                cout <<S.substr(0, K) <<"..." <<endl;
        return 0;
}

Measured memory_bytes: 3624
// 17:15
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)
#define STRING(str) #str
#define DEBUG 1
#if DEBUG
    #define dump(var) dump2(STRING(var), var)
#else
    #define dump(var)
#endif

template <typename T>
void dump2(const string& name, const T& value)
{
    cerr << name << ": " << value << endl;
}
void dump2(const string& name, const tuple<ll,ll,ll>& value)
{
    ll a,b,c;
    tie(a,b,c) = value;
    cerr << name << ": (" << a << ", " << b << ", " << c << ")" << endl;
}

void solve()
{
    string S;
    cin >> S;
    vector<bool> exist(26, false);
    for (char c : S) {
        exist[c - 'a'] = true;
    }
    if (S.length() < 26) {
        cout << S;
        for1(i,26) {
            if (!exist[i]) {
                string a{(char)('a'+i)};
                cout << a << endl;
                return;
            }
        }
    }
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return;
    }
    while (true) {
        char last = S.back();
        dump(last);
        last -= 'a';
        S = S.substr(0, S.length() - 1);
        dump(S);
        exist[last] = false;
        for2(i,last+1,26) {
            if (!exist[i]) {
                string a{(char)('a'+i)};
                cout << S << a << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 256
#line 1 "main.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#line 29 "main.cpp"

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

using ll=long long;

#line 2 "/mnt/c/Users/Imperi/Documents/cp-library/lib/PotentialUnionFind.cpp"

#line 6 "/mnt/c/Users/Imperi/Documents/cp-library/lib/PotentialUnionFind.cpp"

template<typename Group>
class PotentialUnionFind{
  public:
  using value_t=typename Group::value_t;
  using size_t=std::size_t;
  private:
  size_t group;
  std::vector<size_t> par,sz;
  std::vector<value_t> df; //val[par]=val[x]+df[x]

  value_t fold_to_root(size_t x){
    value_t ret=Group::id;
    while(par[x]!=x){
      df[x]=Group::op(df[x],df[par[x]]);
      par[x]=par[par[x]];
      ret=Group::op(ret,df[x]);
      x=par[x];
    }
    return ret;
  }

  public:
  PotentialUnionFind(size_t n=0):group(n),par(n),sz(n,1),df(n,Group::id){
    std::iota(par.begin(),par.end(),0);
  }

  size_t root(size_t x){
    while(par[x]!=x){
      df[x]=Group::op(df[x],df[par[x]]);
      par[x]=par[par[x]];
      x=par[x];
    }
    return x;
  }

  bool same(size_t a,size_t b){return root(a)==root(b);}
  size_t size(){return par.size();}
  size_t groups(){return group;}
  size_t group_size(size_t x){return sz[root(x)];}

  // unite A=B+value
  bool unite(size_t a,size_t b,value_t value){
    size_t aroot=root(a),broot=root(b);
    if(aroot==broot)return false;
    group--;
    if(sz[aroot]<sz[broot]){
      std::swap(aroot,broot);
      std::swap(a,b);
      value=Group::inv(value);
    }
    sz[aroot]+=sz[broot];
    value=Group::op(value,fold_to_root(a));
    value=Group::op(Group::inv(fold_to_root(b)),value);
    df[broot]=value;
    par[broot]=aroot;
    return true;
  }

  // return diff  such as A=B+diff
  value_t diff(size_t a,size_t b){
    assert(same(a,b));
    return Group::op(fold_to_root(b),Group::inv(fold_to_root(a)));
  }
};
#line 38 "main.cpp"

struct Group{
  using value_t=ll;
  static constexpr value_t id=0;
  static constexpr value_t op(value_t a,value_t b){
    return a+b;
  }
  static constexpr value_t inv(value_t a){return -a;}
};

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll n,m;
  std::cin>>n>>m;

  PotentialUnionFind<Group> uni(n);

  while(m--){
    ll l,r,d;
    std::cin>>l>>r>>d;
    l--;r--;
    if(uni.same(l,r)){
      if(uni.diff(r,l)!=d){
        std::cout<<"No\n";
        return 0;
      }
    }else{
      uni.unite(r,l,d);
    }
  }

  std::cout<<"Yes\n";

  return 0;
}


Measured memory_bytes: 2560
def main():
    N=int(input())
    #print(N)
    if N == 1:
        print('a')
        return

    a=['a']
    for k in range(1,N):
        b=[]
        for t in a:
            s = set(t)
            not_in_set = True
            for i in range(k+1):
                add_char = chr(ord('a')+i)
                if add_char in s:
                    b.append(t + add_char)
                else:
                    if not_in_set:
                        b.append(t + add_char)
                        not_in_set = False
        a=b
    for s in a:
        print(s)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 12984
import sys
readline=sys.stdin.readline

N,K = map(int,readline().split())
A=list(map(int,readline().split()))

# K + 1 ～ Nについて、i - K < iであればYes

for i in range(K, N):
  if A[i - K] < A[i]:
    print("Yes")
  else:
    print("No")


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

lli n;

int main(void){
    cin >> n;
    lli p = 0;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        if(x == y) p++;
        else p = 0;
        if(p >= 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
s=input()
t=input()
flag="EQUAL"
if len(s)>len(t):
  print("GREATER")
elif len(s)<len(t):
  print("LESS")
else:
  for i in range(len(s)):
    if int(s[i])>int(t[i]):
      flag="GREATER"
      break
    elif int(s[i])<int(t[i]):
      flag="LESS"
      break
  print(flag)

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



int main(){
  int N;
  cin >> N;
  int a[N],b[N][30],T[30];
  for(int i=0;i<N;i++){
    cin >> a[i];
    
    for(int j=0;j<30;j++){
      b[i][j] = a[i]%2;
      a[i] = a[i]/2;
    }
    a[i]=0;
  }
  
  for(int j=0;j<30;j++){
    T[j]=0;
    for(int i=0;i<N;i++){
      T[j] = T[j] + b[i][j];
      if(T[j]==2){
        T[j]=0;
      }
    }
  }
  
int x;
  for(int i=0;i<N;i++){
    x = 1;
    for(int j=0;j<30;j++){
      if(T[j]+b[i][j]==1){
        a[i]=a[i]+x;
      }
      x = x*2;
    }
    cout << a[i] << endl;
  }
  

  
  return 0;
}


Measured memory_bytes: 27792
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	int k,m=0;
	cin>>k;
	for(;k--;)
	{
		int b;cin>>b;m|=1<<b;
	}
	for(int i=0;i<1<<n;i++)
	{
		if(i&~m)continue;
		cout<<i<<":";
		for(int j=0;j<n;j++)if(i>>j&1)cout<<" "<<j;
		cout<<endl;
	}
}



Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000000
#define IOS ios_base::sync_with_stdio(0); cin.tie(0) //making cin faster
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR_R(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define REP_R(i,n)   FOR_R(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SIZ(x) ((int)(x).size())
//int IsPrime(int Nvrbl){int i;if(Nvrbl<2){return 0;}else if(Nvrbl==2){return 1;}else if(Nvrbl%2==0){return 0;}for(i=3;i<=sqrt(Nvrbl);i+=2){if(Nvrbl%i==0){return 0;}}return 1;} // 1 for prime, 0 for not prime


int main(void)
{
  int n;

  scanf("%d\n",&n);
  

  int mn;
  int dR = - INF;
  int R;
  
  scanf("%d\n",&R);
  mn = R;
  
  
  REP(i,n-1)
    {
      

      scanf("%d\n",&R);
      	 
      if( R - mn > dR )
	{
	  dR = R - mn;
	  
	}

        mn = min( mn , R);
      
      
    }

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



Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll a, b, c;
  cin >> a >> b >> c;

  cout << ((a+b==c || b+c==a || c+a==b) ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 256
# -*- coding: UTF-8 -*-
# ABC066_C

N = int(input())
tmp = input()
list = []
list = tmp.split()

if (N % 2 == 0):
    for i in range(N - 1, -1, -2):
        print(list[i], end=" ")
    for i in range(0, N, 2):
        print(list[i], end=" ")
else:
    for i in range(N - 1, -1, -2):
        print(list[i], end=" ")
    for i in range(1, N, 2):
        print(list[i], end=" ")


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, h=0;
  cin >> a >> b;
  for(int i=1; i<=(b-a-1); i++) h+=i;
  cout << h-a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=3e5+5,mo=1e9+7,ch[2][7]={{5,3,2,4,3,6,5},{1,2,2,1,3,0,5}};
int i,j,f[N][7];
char c[N];
inline void add(int&x,const int&y){x+=y-mo;x+=x>>31&mo;}
int main(){
	scanf("%s",c+1);f[0][0]=1;
	for(i=1;c[i];++i)for(j=0;j<7;++j){
		if(c[i]!='0')add(f[i][ch[1][j]],f[i-1][j]);
		if(c[i]!='1')add(f[i][ch[0][j]],f[i-1][j]);
	}
	printf("%d\n",(f[i-1][1]+f[i-1][2])%mo);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n], sum=0;
  for (int i = 0; i<n; i++) cin >> a[i];
  for (int i = 0; i<n; i++) sum+= a[i];
  if (sum%2==0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int N, M;
int ai[100010];
int x, y;
vector<vector<int> > G(100010);
long long res;
int curg;
int grp[100010];
struct data{
	int val;
	int seq;
	int sz;
};
struct cmp_pq {
	bool operator() (const struct data a, const struct data b) const {
		return a.val > b.val;
	}
};
struct cmp_pq_s {
	bool operator() (const struct data a, const struct data b) const {
		//return a.sz < b.sz;
		if(a.sz < b.sz)
			return true;
		else if(a.sz > b.sz)
			return false;
		else
			return a.val > b.val;
	}
};
vector<priority_queue<struct data, vector<struct data>, cmp_pq > > V(100010);
priority_queue<struct data, vector<struct data>, cmp_pq_s > pq;
int curV[100010];

void dfs(int u)
{
	int i, v;
	for(i=0; i<G[u].size(); i++){
		v = G[u][i];
		if(grp[v]==-1){
			grp[v] = curg;
			dfs(v);
		}
	}
}

bool cmp(int aa, int bb)
{
	return ai[aa] < ai[bb];
}

int solve()
{
	int i, j, k;
	for(i=0; i<N; i++){
		grp[i] = -1;
	}
	curg = 0;
	for(i=0; i<N; i++){
		if(grp[i]==-1){
			grp[i] = curg;
			dfs(i);
			curg ++;
		}
	}
	struct data d, d2, d3;
	for(i=0; i<N; i++){
		d.seq = i;
		d.val = ai[i];
		V[grp[i]].push(d);
	}
	//for(i=0; i<curg; i++){
	//	sort(V[i].begin(), V[i].end(), cmp);
	//}
	for(i=0; i<curg; i++){
		d = V[i].top();
		V[i].pop();
		d.sz = V[i].size();
		pq.push(d) ;
	}
	for(i=0; i<curg-1; i++){
		d = pq.top();
		pq.pop();
		if(pq.empty() )
			return 0;
		d2 = pq.top();
		pq.pop();
		res += d.val + d2.val ;
		if(V[grp[d.seq]].size() < V[grp[d2.seq]].size() ){
			j = grp[d.seq];
			k = grp[d2.seq];
			while(!V[j].empty() ){
				d3 = V[j].top();
				V[j].pop();
				V[k].push(d3);
				grp[d3.seq] = k;
			}
		}
		else{
			k = grp[d.seq];
			j = grp[d2.seq];
			while(!V[j].empty() ){
				d3 = V[j].top();
				V[j].pop();
				V[k].push(d3);
				grp[d3.seq] = k;
			}
		}
		if(i==curg-2)
			break;
		if(V[k].empty() )
			return 0;
		d = V[k].top();
		V[k].pop();
		d.sz = V[k].size();
		pq.push(d) ;
		/*if(curV[grp[d.seq] ] < V[grp[d.seq]].size()){
			d3.seq = V[grp[d.seq]][ curV[grp[d.seq] ] ];
			d3.val = ai[d3.seq];
			pq.push(d3) ;
		}
		if(curV[grp[d2.seq] ] < V[grp[d2.seq]].size()){
			d3.seq = V[grp[d2.seq]][ curV[grp[d2.seq] ] ];
			d3.val = ai[d3.seq];
			pq.push(d3) ;
		}*/
	}
	return 1;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d%d", &N, &M);
	for(i=0; i<N; i++)
		scanf("%d", &ai[i]);
	for(i=0; i<M; i++){
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	if(solve() == 0)
		printf("Impossible\n");
	else
		printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 12408
H, W = map(int, input().split())
N = int(input())
a = list(map(int,input().split()))

g = [[1]*(W+2)]
for i in range(H):
    g.append([1] + [0]*W + [1])
g.append([1]*(W+2))

temp = [[1, 1]]
g[1][1] = 1
c, cnt = 1, 0
while temp:
    p = temp.pop()
    for y, x in [[0, 1], [0, -1], [1, 0]]:
        if g[p[0]+y][p[1]+x] == 0:
            temp.append([p[0]+y, p[1]+x])
            if c == a[cnt]:
                cnt += 1
                c = 1
            else: c += 1
            g[p[0]+y][p[1]+x] = cnt+1
            break
for gg in g[1:-1]:
    print(*gg[1:-1])

Measured memory_bytes: 3920
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>

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

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll n, m;
    cin >> n >> m;
    vector<P> vec(m);
    rep(i, m) {
        ll t;
        string str;
        cin >> t >> str;
        ll s = str == "AC" ? 1 : 0;
        vec[i] = make_pair(--t, s);
    }
    vector<bool> acs(n, false);
    vector<ll> was(n, 0);

    ll ac_count = 0;
    ll wa_count = 0;
    rep(i, m) {
        P p = vec[i];
        if (acs[p.first]) {
            continue;
        }
        if (p.second) {
            ++ac_count;
            wa_count += was[p.first];
            acs[p.first] = true;
        } else {
            ++was[p.first];
        }
    }
    cout << ac_count << " " << wa_count << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

ll factorial(ll N) {
    if(N==0) return 1;
    return (N * factorial(N-1))%MOD;
}

int main() {
    ll n,m; cin >> n >> m;
    ll ans = 0;
    if(abs(n-m)==1) ans = (factorial(n) * factorial(m))%MOD;
    if(abs(n-m)==0) ans = (factorial(n) * factorial(m) * 2)%MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    string s, t; cin >> s >> t;
    int ans = 0;
    fo(i, s.size()) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int month1 = sc.nextInt();
        int date1 = sc.nextInt();
        int month2 = sc.nextInt();
        
        if (month1 != month2) {
            System.out.println(1);
            return;
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 23508
A, B, K = map(int, input().split())
max_AB = max(A, B)
l = []

for i in range(max_AB):
    if A % (i + 1) == 0 and B % (i + 1) == 0:
        l.append(i+1)

l.reverse()
print(l[K-1])

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

int main() {
    int n, ans;
    cin >> n;
    if(n < 600) ans = 8;
    else if(n < 800) ans = 7;
    else if(n < 1000) ans = 6;
    else if(n < 1200) ans = 5;
    else if(n < 1400) ans = 4;
    else if(n < 1600) ans = 3;
    else if(n < 1800) ans = 2;
    else ans = 1;

    cout << ans << '\n';
}


Measured memory_bytes: 3632
//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 100005

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K;

int main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s1, s2;
	cin >> s1 >> s2;
	cout << s2 << s1;






	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


//型とその型での最小値
template <typename T, const T id>
class convex_hull_trick {
    struct line {
        T a, b;
        line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
        T get(T x) { return a * x + b; }
    };
    struct node {
        line l;
        node *lch, *rch;
        node(line l_) : l(l_), lch(nullptr), rch(nullptr) {}
        ~node() {
            if (lch) delete lch;
            if (rch) delete rch;
        }
    };

private:
    const int n;
    const vector<T> pos;
    node *root;

public:
    convex_hull_trick(const vector<T>& pos_) : n(pos_.size()), pos(pos_), root(nullptr) {}
    ~convex_hull_trick() {
        if (root) delete root;
    }
    void insert(T a, T b) {
        line l(a, b);
        root = modify(root, 0, n - 1, l);
    }
    T get(T x) const {
        int t = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
        assert(t < n && pos[t] == x);
        return sub(root, 0, n - 1, t);
    }

private:
    node* modify(node *p, int lb, int ub, line& l) {
        if (!p) return new node(l);
        if (p->l.get(pos[lb]) >= l.get(pos[lb]) && p->l.get(pos[ub]) >= l.get(pos[ub])) return p;
        if (p->l.get(pos[lb]) <= l.get(pos[lb]) && p->l.get(pos[ub]) <= l.get(pos[ub])) {
            p->l = l;
            return p;
        }
        int c = (lb + ub) / 2;
        if (p->l.get(pos[c]) < l.get(pos[c])) swap(p->l, l);
        if (p->l.get(pos[lb]) <= l.get(pos[lb]))
            p->lch = modify(p->lch, lb, c, l);
        else
            p->rch = modify(p->rch, c + 1, ub, l);
        return p;
    }
    T sub(node *p, int lb, int ub, int t) const {
        if (!p) return id;
        if (ub - lb == 0) return p->l.get(pos[t]);
        int c = (lb + ub) / 2;
        if (t <= c) return max(p->l.get(pos[t]), sub(p->lch, lb, c, t));
        return max(p->l.get(pos[t]), sub(p->rch, c + 1, ub, t));
    }
};


int main(){
    int N;
    LL C;
    cin >> N >> C;
    vector<LL> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    convex_hull_trick<LL,LLONG_MIN> cht(h);
    vector<LL> dp(N,0);
    for (int i = 0; i < N; i++) {
        if(i) dp[i] = -cht.get(h[i])+h[i]*h[i]+C;
        cht.insert(2*h[i],-(dp[i]+h[i]*h[i]));
    }
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
#define PI 3.1415926535

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

char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}

char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}

const ll INF = 1000000000000000000;

//input
int N,M;
int A[105];


//processing
int hoge,ans;


//dpTable
//int dp[100050];

int main(){
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        hoge += A[i];
    }
    hoge = (hoge + 4 * M - 1) / (4 * M);
    for (int i = 0; i < N; i++){
        if (A[i] >= hoge) ans++; 
    }
    cout << (ans >= M ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,i,j,k,l,c=0;
    while(cin >> n)
    {
        for(i=0; i<10; i++)
            for(j=0; j<10; j++)
                for(k=0; k<10; k++)
                    for(l=0; l<10; l++)
                        if((i+j+k+l)==n)
                            c++;
        cout << c << endl;
        c=0;
    }
    return 0;
}

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


int main() {
  long n;
  cin>>n;
  vector<long>a(n);
  vector<long>b(1001001);
  vector<long>c[1001001];
  rep(i,n){
    cin>>a.at(i);
    b[a.at(i)]++;
    for(long j=1;j*j<=a.at(i);j++){
      if(a.at(i)%j==0){
        c[i].push_back(j);
        c[i].push_back(a.at(i)/j);
      }
    }
  }
  int ans=0;
  rep(i,n){
    bool ex=true;
    rep(j,c[i].size()){
      if((c[i].at(j)!=a.at(i)&&b[c[i].at(j)]>0)||(c[i].at(j)==a.at(i)&&b[c[i].at(j)]>1)){
        ex=false;
      }
    }
    if(ex){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}



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

int main() {
    int n; cin >> n;
    int u, k;
    int M[110][110] = {0};

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            M[u - 1][v - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j != n - 1) cout << M[i][j] << " ";
            else cout << M[i][j] << endl;
    }
    }
}


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

int     main() {
        string S, T;
        cin >>S >>T;
        if (S.size()<T.size()) {
                cout <<"UNRESTORABLE" <<endl;
                return 0;
        }
        for (int i=S.size()-T.size(); i>=0; i--) {
                bool OK=true;
                for (int j=0; j<T.size(); j++) {
                        if('?'==S.at(i+j))
                                continue;
                        if (T.at(j) != S.at(i+j)) {
                                OK=false;
                                break;
                        }
                }
                if (OK) {
                        for (int j=0; j<i; j++)
                                if (S.at(j)=='?')
                                        cout <<'a';
                                else
                                        cout <<S.at(j);
                        cout <<T;
                        for (int j=i+T.size(); j<S.size(); j++)
                                if (S.at(j)=='?')
                                        cout <<'a';
                                else
                                        cout <<S.at(j);
                        cout <<endl;
                        return 0;
                }
        }
        cout <<"UNRESTORABLE" <<endl;
        return 0;
};

Measured memory_bytes: 256
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
a[n + 1] = 0
local buycost = 1000000007

local money = 1000
local kabu = 0

for i = 1, n do
  local needbuy = false
  local needsell = false
  for j = i + 1, n do
    if a[i] < a[j] then
      needbuy = true
    end
  end
  for j = i + 1, n do
    if a[i] > a[j] then
      needsell = true
      for k = i + 1, j - 1 do
        if a[i] < a[k] then
          needsell = false
          break
        end
      end
      break
    end
  end
  if i == n then needsell = true end
  if needsell then
    money = money + kabu * a[i]
    kabu = 0
  elseif needbuy then
    kabu = kabu + money // a[i]
    money = money % a[i]
  end
  -- print(i, money, kabu)
end
print(money)


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

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
	int n;
	cin >> n;
	bool ok = true;
	int a = 0, b = 0, ab = 0;
	rep(i,n) {
		string s;
		cin >> s;
		if(s[0]=='B') b++;
		if(s[s.length()-1]=='A') a++;
		if((s[0]=='B')^(s[s.length()-1]=='A')) ok = false;
		rep(j,s.length()-1){
			if(s.substr(j,2)=="AB") ab++;
		}
	}
	int ans = ab+min(a,b)-(a!=0&&a==b&&ok?1:0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    vi dp(n,inf);
    dp[0]=0;
    REP(i,1,n){
        chmin(dp[i],dp[i-1]+abs(v[i]-v[i-1]));
        if(i>1)chmin(dp[i],dp[i-2]+abs(v[i]-v[i-2]));
    }
    out(dp[n-1]);
}

Measured memory_bytes: 4764
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def mat_mul(A, B):
	n = len(A)
	C = [[0 for __ in range(n)] for _ in range(n)]
	for i in range(n):
		for j in range(n):
			for k in range(n):
				C[i][k] = (C[i][k] + (A[i][j]*B[j][k])) % MOD
	return C

def mat_exp(M, k):
	n = len(M)
	ans = [[0 for __ in range(n)] for _ in range(n)]
	for i in range(n): ans[i][i] = 1
	while k:
		if k % 2 == 1: ans = mat_mul(ans, M)
		k //= 2
		M = mat_mul(M, M)
	return ans

def main():
	n, k = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	M = mat_exp(A, k)
	ans = 0
	for i in range(n):
		for j in range(n):
			ans += M[i][j]
			ans %= MOD
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 75144
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;
 
  
Vi getdivisors(int n) 
{
  Vi v;
    // Note that this loop runs till square root 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) 
	      v.pb(i);
  
            else // Otherwise print both 
	      v.pb(i), v.pb(n / i); 
        } 
    }
    return v;
}


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

  int n;
  cin >> n;
  int ans = getdivisors(n - 1).size() - 1;
  Vi v = getdivisors(n);
  
  for (int i = 0; i < v.size(); i++){
    if (v[i] == 1)
      continue;
    int l = 0, r = (int)log2(n);
    while(l < r){
      int mid = (l + r) / 2;
      int mid_ans = pow(v[i], mid);
      if (n % mid_ans == 0){
	if (l == mid)
	  break;
	l = mid;
      }
      else{
	if (r == mid)
	  break;
	r = mid;
      }
    }
    int temp = (int)pow(v[i], r);
    if (n % temp == 0)
      temp = r;
    else
      temp = l;
    if ((int)(n / (int)pow(v[i], temp)) % v[i] == 1){
      ans ++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  int ans=0;
  for(int i=0;i<n-1;i++){
    if(vec.at(i)==vec.at(i+1)){
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100000+5;

int n;
int m;
int d[N];
int a[N];
int c[N];
map<string, int> id;

int main(){
	ri(n);
	string s;
	int len = 1;
	for(int i=1; i<=n; i++){
		cin >> s;
		ri(d[i]);
		if(id.count(s)) c[i] = id[s];
		else{
			c[i] = id[s] = len++;
		}
	}
	ri(m);
	for(int i=1; i<=m; i++){
		cin >> s;
		a[i] = id[s];
	}
	vector<int> p(n);
	iota(all(p),1);
	sort(all(p),[&] (int i, int j){
		return d[i] > d[j];
	});
	int pos = m;
	int last = -1;
	for(auto i : p){
		if(pos == 0) break;
		if(a[pos] == c[i]){
			if(last == -1 or d[last] > d[i]){
				last = i;
				pos -= 1;
			}
		}
	}
	puts(pos == 0? "Yes": "No");
	return 0;
}


Measured memory_bytes: 18508
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=1e18,MOD=1e9+7,MAX=1e6+5;
int n,dp[MAX][2][2],a[MAX];

int sol(int idx,bool zero,bool nine){
    if(idx==n){
        if(zero&&nine)
            return 1;
        else
            return 0;
    }
    int &ret=dp[idx][zero][nine];
    if(~ret)
        return ret;
    ret=0;
    lp(i,0,10)
        ret+=sol(idx+1,zero|(i==0),nine|(i==9)),ret%=MOD;
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS
    cin>>n;
    lp(i,0,n)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<sol(0,0,0);
}

Measured memory_bytes: 81732
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
typedef long long ll;
int H, W, h, w;
int A[505][505];
#define INF 1000
//-----------------------------------------------------------------------------------
void _main() {
    cin >> H >> W >> h >> w;

    rep(y, 0, H) rep(x, 0, W) {
        if (y % h == h - 1 && x % w == w - 1) A[y][x] = -(h * w - 1) * INF - 1;
        else A[y][x] = INF;
    }

    ll sm = 0;
    rep(y, 0, H) rep(x, 0, W) sm += A[y][x];
    
    if (sm <= 0) {
        printf("No\n");
        return;
    }
 
    printf("Yes\n");
    rep(y, 0, H) {
        rep(x, 0, W) {
            if (0 < x) printf(" ");
            printf("%d", A[y][x]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct data{int l,r,lv,rv;};

int n,m,p,q,r;
vector< data > t;

void func(){
  int u[3]={0,0,1e9},id=0;
  cin>>u[0]>>u[1];
  vector< data > A[3];

  for(int i=0;i<(int)t.size();i++){
    data a=t[i];
    if(a.l==u[id]+1)id++;
    if(a.r<=u[id])A[id].push_back(a);
    else{
      int nrv=a.lv+u[id]-a.l;
      A[id].push_back((data){0,0,a.lv,nrv});
      a.l=u[id]+1;
      a.lv=nrv+1;
      t[i]=a;
      i--;
      id++;
    }
  }
  t.clear();
  int sum=0;
  for(int i=2;i>=0;i--){
    for(int j=0;j<(int)A[i].size();j++){
      data a=A[i][j];
      a.l=sum+1;
      a.r=a.l+(a.rv-a.lv);
      sum=a.r;
      t.push_back(a);
    }
  }
}

int main(){
  while(cin>>n&&n){
    cin>>m>>p>>q>>r;
    t.clear();
    t.push_back((data){1,n,1,n});
    for(int i=0;i<m;i++)func();
    int ans=0;
    for(int i=0;i<(int)t.size();i++){
      data  a=t[i];
      //cout<<a.l<<" "<<a.r<<" "<<a.lv<<" "<<a.rv<<" "<<ans<<endl;
      if(r<a.lv || q<a.l || a.r<p)continue;
      int L=max(p,a.l);
      int R=min(a.r,min(q,a.l+(r-a.lv)));
      ans+=(R-L+1);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  vector<int> l(2*n); cin >> l;
  sort(whole(l));
  ll res = 0;
  rep(i, n)res += l[2*i];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC082A_cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            Console.WriteLine((int)Math.Ceiling(ab.Average()));
        }
    }
}


Measured memory_bytes: 13396
T = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(T[K - 1])


Measured memory_bytes: 3064
#include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-8;
const int INF = 1e8;
const D PI = acos(-1);

int v; //ク&#12441;ラフの頂点数
vector<int> G[1100]; //ク&#12441;ラフの隣接リスト表現
int match[1100]; //マッチンク&#12441;のヘ&#12442;ア
bool use[1100];
bool dfs(int u){
  use[u] = true;
  rep(i,G[u].sz){
    int t = G[u][i], w = match[t];
    if(w<0 || (!use[w] && dfs(w))){
      match[u] = t;
      match[t] = u;
      return true;
    }
  }
  return false;
}

int biparticle_matching(){
  int res = 0;
  memset(match,-1,sizeof(match));
  rep(u,v){
    if(match[u]<0){
      INIT(use);
      if(dfs(u))res++;
    }
  }
  return res;
}

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int m,n;
int b[1000],r[1000];

int main(){
  while(cin >> m >> n, m){
    rep(i,m)G[i].clr, cin >> b[i];
    rep(i,n)G[m+i].clr, cin >> r[i];

    rep(i,m){
      rep(j,n){
	if(gcd(b[i],r[j]) != 1){
	  G[i].pb(m+j); G[m+j].pb(i);
	}
      }
    }

    v = m+n;
    cout << biparticle_matching() << endl;
  }
}

Measured memory_bytes: 3380
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

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

  cout << s[0]<<s[1]<<s[2];
}

Measured memory_bytes: 3628
h, w, n = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }

B = 10**9+7
blacks = Hash.new(false)
ab.each do |a, b|
  k = a*B+b
  blacks[ k ]=true
end

count_array = [0]*10
square = Hash.new(0)
ab.each do |a, b|
  [a-2, a-1, a].each do |ca|
    next if ca<1 || ca > h-2
    [b-2, b-1, b].each do |cb|
      next if cb < 1 || cb > w-2

      k = ca*B + cb
      square[ k ] += 1
    end
  end
end

counters = square.values.flatten
ans = (1..9).map {|num| counters.count(num) }

all_count = (h-2)*(w-2)
ans.unshift(all_count - ans.inject(:+))
puts ans


Measured memory_bytes: 95708
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n,i;
  int A[250];

  scanf("%d",&n);

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

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i!=1)
      printf("parent key = %d, ",A[i/2]);
    if(2*i <= n)
      printf("left key = %d, ",A[i*2]);
    if(2*i+1 <= n)
      printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N < 1000)System.out.println("ABC");
		else System.out.println("ABD");
	}

}


Measured memory_bytes: 22996