akhauriyash/Code-Regression huggingface dataset:
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define MSG(msg1,msg2,flag) cout<<((flag)? msg1:msg2);

#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
template <class T> map<T,int> 
count_same_elements(const vector<T>& v){map<T,int>cmap; for_each(v.begin(),v.end(),[&cmap](auto x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
int n,T;
vector<pii> c;
void input(){
    cin>>n>>T;
    c.resize(n);
    rep(i,n){
        cin>>c[i].first>>c[i].second;
        if(c[i].second>T){c[i].first=1e8;}
    }
}
void src(){
    if((*min_element(c.begin(),c.end())).first==1e8){
        cout<<"TLE";
    }else{
        cout<<(*min_element(c.begin(),c.end())).first;
    };
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
program ABC144C
    implicit none
    integer(8)::N,i,result

    read*,N

    do i=1,int(sqrt(real(N)))
        if(i==1) then
            result=N-1
        else if(mod(N,i)==0.and.N/i+i-2<result) then
            result=N/i+i-2
        end if
    end do

    print'(i0)',result
    
end program ABC144C

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
ll dp[90];
int main(){
    int N;
    cin >> N;
    dp[0] = 2;
    dp[1] = 1;
    for (int i = 2; i <= N;++i){
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    cout << dp[N] << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n) ; i++)
using namespace std;
typedef long ll;
int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  vector<int> b(n);
  rep(i,n+1){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  long ans=0;
  rep(i,n){
    int left = min(a[i],b[i]);
    ans += left;
    a[i] -= left;
    b[i] -= left;
    //cout << "left" << left << endl;
    int right = min(a[i+1],b[i]);
    ans += right;
    a[i+1] -= right;
    b[i] -= right;
    //cout << "right" << right << endl;
    //cout << "ans" << ans << endl;
  }
  
  
  cout << ans << endl;
}
    

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

int main(){
	string s;
	deque<char>ans;
	cin>>s;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]!='B')ans.push_back(s[i]);
		else if(!ans.empty())ans.pop_back();
	}
	for(auto i:ans)cout<<i;


}
//solved  problems for today:4


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int dp[N],a[N];
int main(){
    //srand(time(NULL)+clock());
    int ca=0,T,k,i,j,m=0,K,n;
    double start=clock();
    scanf("%d%d",&n,&K);
    rep(i,0,n)scanf("%d",&a[i]);
    rep(i,1,n)dp[i]=inf;
    rep(i,1,n){
        rep(j,1,K+1){
            if(i-j>=0)Min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
    printf("%d\n",dp[n-1]);
    cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n;
    cin >> n;

    vi l(n);
    forn(i, n) cin >> l[i];

    sort(all(l));

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (l[i] == l[j]) continue;
            for (int k = j + 1; k < n; k++) {
                if (l[j] == l[k]) continue;

                if (l[i] + l[j] > l[k]) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>

int	main(void)
{
	long long int n;
	long long int a;	
	long long int b;
	long long int x;
	long long int y;

	scanf("%lld %lld %lld", &n, &a, &b);
	if (a == 0)
	{
		printf("0");
		return (0);
	}
	x = n - a - b;
	if (x == 0)
	{
		printf("%lld", a);
		return (0);
	}
	x = n % (a + b);
	x = (x > a) ? (a) : (x);
	y = n / (a + b);
	x = x + (y * a);
	printf("%lld", x);
	return (0);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int n, a, b, c, d, cnt;
	char instr[80];
	
	while (fgets(instr, sizeof(instr), stdin) != NULL) {
		sscanf(instr, "%d", &n);
		cnt=0;
		
		for (a=0; a<10; a++) {
			for (b=0; b<10; b++) {
				for (c=0; c<10; c++) {
					for (d=0; d<10; d++) {
						if (a+b+c+d == n) cnt++;
					}
				}
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n;
    cin >> n;
    if (n < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
int a[MAXN],b[MAXN],n;
bool check(int x,int y,int z)
{
	if(b[x]<=b[y]&&b[y]<=b[z]||b[y]<=b[z]&&b[z]<=b[x]||b[z]<=b[x]&&b[x]<=b[y])return true;
	return false;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[a[i]]=i;
	int sum=0,fi=-1;
	for(int i=n-1,tf=0,nxt;i>=1;i=nxt-1)
	{	
		nxt=i;
		if(!tf)
		{
			while(!tf&&b[nxt]<=b[nxt+1]&&nxt)--nxt;
			if(!nxt)break;tf=1,++sum,fi=nxt+1;
		}
		else
		{
			if(check(fi,i,i+1))continue;
			else ++sum,fi=i+1;
		}
	}pr2(sum);
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

#define MAX_S 100000
#define MAX_T 50000

void insertionSort(int *b,int k){
  int i,j,v;
  
  for(i = 1; i < k; i++){
    v = b[i];
    j = i - 1;
    while(j >= 0 && b[j] > v){
      b[j + 1] = b[j];
      j--;
    }
    b[j + 1] = v;
  }

}

int binarySearch(){
  int n,q,count,i,j,mid,r,l,a,b,c;
  int s[MAX_S],t[MAX_T];

  count = 0;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&s[i]);
  insertionSort(s,n);
  scanf("%d",&q);
  for(i = 0; i < q; i++)
    scanf("%d",&t[i]);

  

   
  for(i = 0; i < q; i++){
    a = 0;
    b = n / 2;
    c = n - 1;
    l = s[a];
    mid = s[b];
    r = s[c];

    while(1){
      if(mid >= t[i]){ 
	c = b;
	b = (a + c)/2;
      }
      else {
	a = b + 1;
	b = (a + c)/2;
      }
      
      l = s[a];
      mid = s[b];
      r = s[c];
    
 
      
      if(mid == t[i]){

	count++;
	break;
      }
      if(l == r)
	break;
      else if(l > r)
	break;
    }
  }
  
  return count;
}

int main(){

  printf("%d\n",binarySearch());
  
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define INF 1e9+5
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(i,a,b) for(ll i=a;i<(ll)b;i++)
#define ff first
#define ss second
int32_t main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	ll ans=0;
	ans+=(n)*(n-1);
	ans/=2;
	ans+=(m*(m-1))/2;
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;

int main()
{
//    freopen("int.txt","r",stdin);

    int a,b;
    while(cin>>a>>b&&(a||b))
    {
        if(a>b)
        swap(a,b);
        cout<<a<<" "<<b<<endl;
    }
}



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


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

#define int long long

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

int N;
int A[100001];

signed main() {
    cin >> N;
    int x = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        x += A[i];
    }
    if (x % (N * (N + 1) / 2) != 0) {
        cout << "NO" << endl;
        return 0;
    }
    x /= (N * (N + 1) / 2);
    A[N] = A[0];
    int y = 0;
    for (int i = 1; i <= N; i++) {
        int cur = A[i] - A[i - 1];
        if (cur > x || (x - cur) % N != 0) {
            cout << "NO" << endl;
            return 0;
        }
        y += (x - cur) / N;
    }
    if (x != y) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}


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

int x[10000]={};

int main(){
	int a;
	cin>>a;
	for (int i=0;i<a;i++)cin>>x[i];
	reverse(x,x+a);
	cout<<x[0];
	for (int i=1;i<a;i++)cout<<" "<<x[i];
	cout<<endl;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll unsigned long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e9
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se*b.fi + b.se > b.se*a.fi + a.se) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}
 
int main()
{
    string s;
    cin >> s;

    if(s == "MON") cout << 6 << "\n";
    else if(s == "TUE") cout << 5 << "\n";
    else if(s == "WED") cout << 4 << "\n";
    else if(s == "THU") cout << 3 << "\n";
    else if(s == "FRI") cout << 2 << "\n";
    else if(s == "SAT") cout << 1 << "\n";
    else if(s == "SUN") cout << 7 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll A, B, C, K, ans0, ans1;
    cin >> A >> B >> C >> K;
    ans0 = A - B;
    ans1 = B - A;
    if(K%2 == 0)
        cout << ans0 << endl;
    else
        cout << ans1 << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

tmp = 0
for i in range(len(S)-len(T)+1):
    cnt = 0
    bubun = S[i:i+len(T)]
    for j in range(len(T)):
        if bubun[j] == T[j]:
            cnt += 1
    
    tmp = max(tmp,cnt)

print(len(T)-tmp)

Measured memory_bytes: 67648
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

int wie,kol;
int t[505][505];
pair<int,int>wcz;
int np,wyn;
bool wziete;
vector<pair<pair<int,int>,pair<int,int> > >w;
int main()
{
    ios::sync_with_stdio(0);
    cin>>wie>>kol;
    for(int i=1;i<=wie;++i)
    {
        for(int j=1;j<=kol;++j)
        {
            cin>>t[i][j];
            if(t[i][j]%2==1)++np;
        }
    }
    for(int i=1;i<=wie;++i)
    {
        if(i%2==1)
        {
            for(int j=1;j<=kol;++j)
            {
                if(wziete==1)
                {
                    ++wyn;
                    w.push_back(make_pair(make_pair(wcz.ff,wcz.ss),make_pair(i,j)));
                    if(t[i][j]%2==1)
                    {
                        wziete=0;
                        np-=2;
                    }
                }
                else if(t[i][j]%2==1)
                {
                    if(np>1)wziete=1;
                    else break;
                }
                wcz.ff=i;
                wcz.ss=j;
            }
        }
        else
        {
            for(int j=kol;j>=1;--j)
            {
                if(wziete==1)
                {
                    ++wyn;
                    w.push_back(make_pair(make_pair(wcz.ff,wcz.ss),make_pair(i,j)));
                    if(t[i][j]%2==1)
                    {
                        wziete=0;
                        np-=2;
                    }
                }
                else if(t[i][j]%2==1)
                {
                    if(np>1)wziete=1;
                    else break;
                }
                wcz.ff=i;
                wcz.ss=j;
            }
        }
    }
    cout<<wyn<<endl;
    for(int i=0;i<w.size();++i)cout<<w[i].ff.ff<<" "<<w[i].ff.ss<<" "<<w[i].ss.ff<<" "<<w[i].ss.ss<<endl;
}


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

using namespace std;



int main()
{
  
  
    
    long int n,i,cnt=1,cnt1=0;
    scanf("%ld",&n);
    long int a[n];
    for(i=0;i<n;++i)
       scanf("%ld",&a[i]);
     
       
    sort(a,a+n);
    if(n==1)
     {
         if(a[0]==1)
            printf("0");
            
         else
           printf("1");
     }
     
     else
     {
    for(i=1;i<n;++i)
      {
          if(a[i]==a[i-1])
             cnt++;
             
          else
            {
                if(cnt!=a[i-1])
                {
                   if(cnt>a[i-1])
                      cnt1+=cnt-a[i-1];
                      
                   else
                     cnt1+=cnt;
                 
                }
                cnt=1;
            }
      }
      if(cnt==a[i-1])
         cnt1+=0;
         
      else
       {
                  if(cnt>a[i-1])
                      cnt1+=cnt-a[i-1];
                      
                   else
                     cnt1+=cnt;
       }
     
     printf("%ld",cnt1);
     }
     
    
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int64 get_jou(int64 v, int64 i) {
  int64 j;
  int64 r;

  if (i == 0) return 1;
  
  r = 1;
  for (j=1; j<=i; j++) {
    r = r*v;
  }
  return r;
}

int64 check_val (int64 N, int64 K, int64 max) {
  int64 j,v;

  v = 1;
  for (j=1; j<=max; j++) {
    v = v*K;
    if ((N / v) > 0) {
      continue;
    } else {
      return 0;
    }
  }
  return 1;
}

int main()
{
  int64 N,K,r;
  int64 max, i, j;

  max = 31;

  get_NK(&N, &K);

  for (i=max; i>0; i--) {
    if (check_val(N, K, i)) {
      printf("%lld", (i+1));
      return 0;
    }
  }

  printf("%lld", (i+1));
  return 0;
}







Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
//i ll be the king
int main()
{
	sync;
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]==s[1]&&s[3]==s[2]&&s[1]!=s[2])
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pb push_back
#define F first
#define S second
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

# define M_PIl          3.141592653589793238462643383279502884L /* pi */

const ll M=1e9+7;
const int MaxM=100005;


void SieveOfEratosthenes(int n)                                   //all prime <= n
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}


bool isPowerOfTwo (int x)
{
    return x && (!(x&(x-1)));
}



bool comp(pair<int,int> a,pair<int,int> b){
  if(a.F==b.F){
    return a.S>b.S;
  }
  return a.F<b.F;
}




void solve(){

   string s,t;cin>>s>>t;
   string ans="";
int n=s.size();
int m=t.size();

      int dp[n+1][m+1];
      for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
        for(int i=0;i<=m;i++){
        dp[0][i]=0;
      }

      for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){

                if(s[i-1]==t[j-1]){dp[i][j]=1+dp[i-1][j-1];}
                else{dp[i][j]=max(dp[i-1][j],dp[i][j-1]);}               
        
        }

      }
      int z=dp[n][m];
      
while(n && m ){
    if(s[n-1]==t[m-1]){
        ans+= s[n-1];
        n--;m--;
        z--;
    }
    else if(dp[n-1][m]>dp[n][m-1]){
        n--;
    }
    else{m--;}
   // if(z==0){break;}
}

reverse(ans.begin(),ans.end());

cout<<ans;



}

int main(){


   int t=1;
//  cin>>t;
   while(t--){
      solve();
       }

 }


Measured memory_bytes: 38772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int l,r,d;cin>>l>>r>>d;
  int ans=0;
  for(int i=l;i<=r;i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3492
#include <stdio.h>
int main(void){
  long long N[1001], i, j, x=0,ans=1;
  scanf("%d", &N[0]);
  for(i=1; i<=N[0]; i++){
    j=2;
    x=i;
    N[i]=0;
	while(x!=1){
      if(x%j==0){
        x=x/j;
        N[j]++;
        j=2;
      }else{j++;}
    }
  }
  for(i=1;i<=N[0];i++){
    ans=(ans%1000000007)*((N[i]+1)%1000000007);
  }
  printf("%lld", ans%1000000007);
}

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

int main(){
	int d,g;
	cin>>d>>g;
	vector<pair<int,int>>pc(d);
	for(int i=0;i<d;++i)cin>>pc.at(i).first>>pc.at(i).second;
	int ans=0x40000000;
	for(int i=0,tmp,tn;i<(1<<d);++i){
		tmp=0,tn=0;
		vector<bool>used(d,false);
		for(int j=0;j<d;++j){
			if(i&(1<<j)){
				tn+=pc.at(j).first;
				tmp+=pc.at(j).first*100*(j+1)+pc.at(j).second;
				used.at(j)=true;
			}
		}
		if(tmp<g){
			for(int i=d-1;i>=0;--i){
				if(used.at(i)==false){
					for(int j=0;j<pc.at(i).first;++j){
						++tn;
						tmp+=(i+1)*100;
						if(tmp>=g)goto loopbreak;
					}
				}
			}
		}
		loopbreak:
		if(tmp>=g)ans=min(ans,tn);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
<?php
	$n = fgets(STDIN);
	$a = explode(" ",fgets(STDIN));
	for($i=0;$i < $n;$i++){
    	$a[$i] = intval($a[$i]);
    }
$ans = 0;
$endflag = false;
while(true){
	for($i=0;$i < $n;$i++){
    	if($a[$i] % 2 == 0){
        	$a[$i] /= 2;
        }else{
          	$endflag = true;
        }
    }
  if($endflag)break; 
  $ans++;
}
 
echo $ans;
?>

Measured memory_bytes: 3700
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    br.readLine()!!
        .fold(0) { acc, v -> acc + if (v == '+') 1 else -1 }
        .let(out::println)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34184
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
// constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

class UnionFind {
    struct UFNode {
        int par;
        int rank;
        UFNode() {}
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        //return nodes[x].par == x ? x : nodes[x].par = root(nodes[x].par);
        return nodes[x].par == x ? x : root(nodes[x].par);
        // return nodes[x].par == x ? x : (nodes[x].par = root(nodes[x].par));
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    LL n,m;
    cin >> n >> m;
    UnionFind u(n);
    VI p(n);
    REP(i,0,n) cin >> p[i];
    int x,y;
    REP(i,0,m) {
        cin >> x >> y;
        u.unite(x,y);
    }
    VI v(n);
    int cnt = 0;
    REP(i,0,n) {
        if (u.same(i+1, p[i])) ++cnt;
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0]==s[1]&&s[2]==s[3]&&s.size()==4&&s[0]!=s[2])cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;


int main(int argc,char* argv[])
{
    int n;
    cin>>n;
    int a[n],sum=0;
    rep(i,n)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    cout<<sum-a[n-1]/2<<endl;
    
    return 0;
}


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

int main()
{
    // 整数の入力
    long long  N,V,L,i,j;
    double T;
    double totalQ;
    cin >> N >> L;
    deque<int> VList;
    deque<double> TList;

    cin >> T >> V;
    TList.push_front(T);
    VList.push_front(V);
    totalQ = T*V;
    cout << fixed << T << endl;
    for (i=1;i<N;i++){
        cin >> T >> V;
        int tempV = V;
        while (tempV> 0){
            if (tempV >= VList.back()){
                tempV = tempV- VList.back();
                totalQ = totalQ - VList.back() * TList.back();
                VList.pop_back();
                TList.pop_back();
            }else{
                VList.back() = VList.back() - tempV;
                totalQ = totalQ - tempV * TList.back();
                tempV = 0;
            }
        }

        if (VList.size() == 0){
            TList.push_front(T);
            VList.push_front(V);
            totalQ = T*V;
        }else{
            totalQ += T*V;
            while (!TList.empty() && T <= TList[0]){
                T = (T*V+TList[0]*VList[0])/(V+VList[0]);
                V = V+VList[0];
                TList.pop_front();
                VList.pop_front();
            }
            TList.push_front(T);
            VList.push_front(V);
        }

        cout << fixed << totalQ/L << endl;
    }

    return 0;
}

Measured memory_bytes: 14720
#include <cstdio>
int n, m, a, b;
char c[1005][1005];
int main() {
	scanf("%d%d%d%d", &n, &m, &a, &b);
	int i, j;
	for(i=1; i<=n; i++) for(j=1; j<=m; j++) c[i][j] = '.';
	if(m&1) for(i=1; i<n && b; i+=2) {
		c[i][m] = '^';
		c[i+1][m] = 'v';
		b--;
	}
	if(n>1 && m>2 && n&1 && b&1) {
		c[n-1][m-2] = '^';
		c[n][m-2] = 'v';
		b--;
	}
	for(i=1; i<n; i++) for(j=1; j<=m-(m&1) && b; j++) {
		if(c[i][j]=='.' && c[i+1][j]=='.') {
			c[i][j] = '^';
			c[i+1][j] = 'v';
			b--;
		}
	}
	for(i=1; i<=n; i++) for(j=1; j<m && a; j++) {
		if(c[i][j]=='.' && c[i][j+1]=='.') {
			c[i][j] = '<';
			c[i][j+1] = '>';
			a--;
		}
	}
	if(a+b==0) {
		puts("YES");
		for(i=1; i<=n; i++) puts(c[i]+1);
	} else puts("NO");
	return 0;
}

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (n == 1 && a != b) {
    cout << 0 << endl;
    return 0;
  }
  
  if (a > b) {
    cout << 0 << endl;
    return 0;
  }
  cout << ((n-1)*b+a) - ((n-1)*a+b) + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int n, m;
int a[50], b[50];

bool graph[50][50]; //隣接行列
bool visited[50];

void dfs(int v)
{
    visited[v] = true;
    for (int nv = 0; nv < n; nv++)
    {
        if (graph[v][nv] == false)
            continue;
        if (visited[nv] == true)
            continue;
        dfs(nv);
    }
}

void bfs(int v)
{
    queue<int> q;
    visited[v] = true;
    q.push(v);
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        rep(i, n)
        {
            if (graph[x][i])
                if (!visited[i])
                {
                    q.push(i);
                    visited[i] = true;
                }
        }
    }
}

int main()
{
    int ans = 0;
    cin >> n >> m;
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    rep(i, m)
    {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        rep(j, n)
        {
            visited[j] = false;
        }
        bfs(0);
        bool bridge = false;
        rep(j, n)
        {
            if (visited[j] == false)
                bridge = true;
        }
        if (bridge)
            ans += 1;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[0]*9<e[1]or e[4]-e[0]<5],'one pair','two pair','three card','full house',0,'four card'][sum(e.count(s)for s in e)//2-2])


Measured memory_bytes: 5608
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> A(n);
    for (int &a: A)
        scanf("%d", &a),
        a--;

    vector<vector<int>> T1(m), T2(m);
    for (int i=1; i<n; i++)
        T1[A[i-1]].push_back(i),
        T2[A[i]].push_back(i);
    long long c = 0;
    int x = 0;
    for (int i=1; i<n; i++)
    {
        int t = A[i-1]<=A[i] ? A[i-1] : A[i-1]-m;
        if (t<0)
            c += 1 + A[i],
            x++;
        else
            c += A[i] - t;
    }

    long long ans = c;
    for (int i=1; i<m; i++)
    {
        for (int t: T2[i-1])
        {
            x--;
            c += (A[t] - A[t-1] + m) % m - 1;
        }
        for (int t: T1[i-1])
        {
            x++;
            c++;
        }
        c -= x;
        ans = min(ans, c);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <int, vector<int>, greater<int> > min_heap;
const ll mod=1000000007;
const ll inf=1e9;
const ll N=5e5+10;

#define emp mp(-1,-1)

mypair inter(mypair a, mypair b)
{
    mypair ans=mp(max(a.ff,b.ff),min(a.ss,b.ss));
    if(ans.ff>ans.ss) return emp;
    else return ans;
}

int len(mypair a)
{
    if(a==emp) return 0;
    return a.ss-a.ff+1;
}

int main()
{
    boost;
    int n;
    cin>>n;
    mypair a[n],pref[n],suff[n];
    for(auto &i:a) cin>>i.ff>>i.ss;
    sort(a,a+n);
    //for(auto i:a) cout<<i.ff<<" "<<i.ss<<endl;
    pref[0]=a[0];
    for(int i=1;i<n;i++) pref[i]=inter(pref[i-1],a[i]);
    //for(auto i:pref) cout<<i.ff<<" "<<i.ss<<endl;    
    suff[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) suff[i]=inter(suff[i+1],a[i]);
    int ans=0;    
    for(int i=1;i<n;i++)
    {
        ans=max(ans,len(pref[i-1])+len(suff[i]));
    }    
    for(int i=1;i<n-1;i++)
    {
        ans=max(ans,len(inter(pref[i-1],suff[i+1]))+len(a[i]));
    }
    ans=max(ans,len(a[0])+len(suff[1]));
    ans=max(ans,len(a[n-1])+len(pref[n-2]));
    cout<<ans;
    

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>

#define N 1001

void compare(char *, char *);

int count = 0;

int main() {
    char in[N], end[12], w[N];

    strcpy(end, "END_OF_TEXT");

    scanf("%s", w);

    while(1) {
        scanf("%*c%s", in);

        if (strcmp(end, in) == 0) break;

        compare(in, w);
    }

    printf("%d\n", count);

    return 0;
}


void compare(char *in, char *w) {
    int i, len;

    len = strlen(w);

    for (i = 0; i <= len; i++) {
        if (w[i] != in[i] && w[i] != (in[i] + 32) ) break;
    }

    if (i == len + 1) count++;

}


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


int main(void)
{
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n-i; j++) {
			int sum = 10000*i + 5000*j;
			if (sum+1000*(n-i-j) == y) {
				cout << i << " " << j << " " << n-i-j << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
	return 0;
}


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

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static String[] a;
    static String[] b;
    static String temp;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        a = scanner.nextLine().split(" ");
        b = scanner.nextLine().split(" ");
        char[] c = {'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S'};

        boolean flag = false;
        for (int i = 0; i < 3; i++) {
            for (char d : c) {
                roll(d);
                if (Arrays.equals(a, b)) {
                    flag = true;
                    break;
                }
            }
        }
        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void roll(char c) {
        switch (c) {
            case 'E':
                temp = a[0];
                a[0] = a[3];
                a[3] = a[5];
                a[5] = a[2];
                a[2] = temp;
                break;
            case 'N':
                temp = a[0];
                a[0] = a[1];
                a[1] = a[5];
                a[5] = a[4];
                a[4] = temp;
                break;
            case 'W':
                temp = a[0];
                a[0] = a[2];
                a[2] = a[5];
                a[5] = a[3];
                a[3] = temp;
                break;
            default:
                temp = a[0];
                a[0] = a[4];
                a[4] = a[5];
                a[5] = a[1];
                a[1] = temp;
                break;

        }
    }
}



Measured memory_bytes: 26296
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n;
  long long k;
  cin>>n>>k;
  long long a[n];
  long long s = 0;
  REP(i,n){
    cin>>a[i];
    s += a[i];
  }
  vector<long long> candg;
  for(long long i=1;i<=sqrt(s);i++){
    if(s%i == 0){
      candg.push_back(i);
      candg.push_back(s/i);
    }
  }
  sort(ALL(candg), greater<long long>());
  
  int m = candg.size();
  long long ans;
  REP(i,m){
    long long temp[n];
    long long g = candg[i];
    long long sg = 0;
    REP(j,n){
      temp[j] = a[j]%g;
      sg += temp[j];
    }
    sort(temp,temp+n,greater<long long>());
    long long gcnt = sg/g;
    long long cnt = 0;
    REP(j,n){
      if(j>=gcnt)break;
      cnt += g - temp[j];
    }
    
    if(cnt<=k){
      ans = g;
      break;
    }
  }
    
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << "Hello World" << endl;
    return 0;
  }
  int a,b;
  cin >> a >> b;
  cout << a + b << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >>N;
  int S=0;
  int p;
  int n=N;
  for(int i=0;i<8;i++)
  {
  p=n%10;
  n=n/10;
  S=S+p;
  if(n==0)break;
  }
if(N%S==0)cout<<"Yes"<<endl;else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
 
	// ??????????????\??????????????°?????\???????????°
	int last, total;
	
	// ?????°?????\???
	while(1) {
		
		scanf("%d %d", &last, &total);
		
		if(last == 0 && total ==0)
			break;
		
		// 1??????last?????§?????°????????\????????????
		int seq[last];
		
		for(int cnt = 0; cnt < last; cnt++) {
			
			seq[cnt] = cnt +1;
			
		}
		// ????¨????total?????????????????????????????°?????\???????????°
		int sum = 0;
		
		for(int cnt1 = 0; cnt1 < last; cnt1++) {
			
			for(int cnt2 = cnt1 +1; cnt2 < last; cnt2++) {
				
				for(int cnt3 = cnt2 +1; cnt3 < last; cnt3++) {
					
					if(seq[cnt1] + seq[cnt2] + seq[cnt3] == total) {
						
						sum++;
					}
				}
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1756
s = input()
t = input()

dp = [[0] * (len(t)+1) for i in range(len(s)+1)] #dp[n][m]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1)
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1])

ans = ''
i = len(s)
j = len(t)
while (i > 0 and j > 0):
    if dp[i][j] == dp[i-1][j]:
        i -=1
    elif dp[i][j] == dp[i][j-1]:
        j -=1
    elif dp[i][j] == dp[i-1][j-1] + 1:
        ans = s[i-1] + ans
        i -=1
        j -=1

print(ans)

Measured memory_bytes: 113628