akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int h, w; cin >> h >> w;
    char a[h][w]; rep(i, h) rep(j, w) cin >> a[i][j];
    int c = 0;
    int reached[1001][1001] = {0};
    queue<pii> q;
    rep(i, h) rep(j, w) if (a[i][j] == '#') q.push({i, j});
    while (!q.empty()) {
        int y = q.front().first, x = q.front().second;
        q.pop();
        rep(k, 4) {
            int ny = y + dy[k], nx = x + dx[k];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (a[ny][nx] == '#') continue;
            reached[ny][nx] = reached[y][x] + 1;
            a[ny][nx] = '#';
            q.push({ny, nx});
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) chmax(ans, reached[i][j]);
    cout << ans << endl;
    //rep(i, h) {rep(j, w) cout << reached[i][j] << " "; cout << endl;}
}


Measured memory_bytes: 13328
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int r = stdIn.nextInt();

        if(n >= 10){
            System.out.println(r);
        }else{
            System.out.println(r + 100 * (10 - n));
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>

int main(){
	int i,H;

	scanf("%d",&H);

	int A[H+1];

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

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

		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
const double PI=3.14159;
#define rep(i, n) for (int i = 0; i < n; i++)

int main(){
  
  int r;
  cin>>r;
  double circle=r*2*PI;
  cout<<circle<<endl;
  return 0;
}

Measured memory_bytes: 3784
#include <stdio.h>
#define N 10000
#define Q 500
int linearSearch(int);
int n,S[N];
int main() {
  int i,q,c=0,T[Q],k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++) {
    k=linearSearch(T[i]);
    if(k > 0) c++;
  }
  printf("%d\n",c);
return 0;
}

int linearSearch(int key){
  int i;
  i=0;
  S[n]=key;
  while(S[i] != key) {
    i++;
    if(i == n) return 0;
  }
  return 1;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;
const int mod = 1e9+7;

int a[N];
int fact[N];

int binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

int nCr(int n, int k) {
  return 1LL * fact[n] * binpow(fact[k], mod-2) % mod * binpow(fact[n-k], mod-2) % mod;
}

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  fact[0] = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    if (i) {
      fact[i] = 1LL*fact[i-1]*i%mod;
    }
  }
  sort(a, a+n);
  long long ans = 0;
  for (int i = n-1; i >= k-1; --i) {
    ans = (ans + 1LL * a[i] * nCr(i, k-1) % mod) % mod;
  }
  for (int i = 0; i <= n-k; ++i) {
    ans = (ans - (1LL * a[i] * nCr(n-i-1, k-1)) % mod + mod) % mod;
  }
  printf("%lld", ans);
}

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


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


int main() 
{
    int N;
    cin>>N;
    constexpr int max=10001;
    vector<int>ans(max,0);
    for (int x = 1; x < 101; x++)
    {
        for (int y = 1; y < 101; y++)
        {
            for (int z = 1; z < 101; z++)
            {
                int v=x*x+y*y+z*z+x*y+y*z+z*x;
                if(v<10001)
                {
                    ++ans[v];
                }
            }
        }
    }
    
    for(int i=0;i<N;++i)
    {
        cout<<ans[i+1]<<endl;
    }

    return 0;   
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define f first
#define s second

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<pair<ll, ll>> points (N);
	F0R(i, N) {
		ll x, y; cin >> x >> y;
		points[i] = {x, y};
	}

	bool par = (points[0].first^points[0].second)&1;
	F0R(i, N) if (((points[i].first^points[i].second)&1) != par) {
		print(-1); return 0;
	}

	vll sizes;
	vector<string> ans (N);

	if (!par) {
		F0R(i, N) points[i].second++;
		sizes.push_back(1);
		F0R(i, N) ans[i] += "D";
	}

	R0F(d, 32) {
		sizes.push_back(1ll << d);
		F0R(i, N) {
			ll x = points[i].first;
			ll y = points[i].second;
			if (y >= x && y >= -x) {
				ans[i] += "U";
				points[i].second -= 1ll << d;
			} else if (y >= x && y < -x) {
				ans[i] += "L";
				points[i].first += 1ll << d;
			} else if (y < x && y >= -x) {
				ans[i] += "R";
				points[i].first -= 1ll << d;
			} else if (y < x && y < -x) {
				ans[i] += "D";
				points[i].second += 1ll << d;
			}
		}
	}
	F0R(i, N) {
		assert (points[i].first==0 && points[i].second==0);
	}

	print(sizes.size());
	for (ll x : sizes) cout << x << " "; cout << endl;
	F0R(i, N) print(ans[i]);
}

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

using namespace std;


int main() {
	int x1, y1, x2, y2, x, y;
	cin >> x1 >> y1 >> x2 >> y2;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	int ly = min(y1, y2), ry = max(y1, y2);
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> a;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		if (x1 <= x && x <= x2 && ly <= y && y <= ry) {
			if (y1 > y2)
				y = -y;
			a.push_back({x, y});
		}
	}
	sort(a.begin(), a.end());
	int m = a.size(), t, inf = 1e9, ans 	= 0;
	vector<int> b(m), dp(m + 2, inf);
	dp[0] = -inf;
	for (int i = 0; i < m; i++)
		b[i] = a[i].second;
	for (int i = 0; i < m; i++) {
		t = lower_bound(dp.begin(), dp.end(), b[i]) - dp.begin();
		dp[t] = b[i];
		ans = max(ans, t);
	}
	double dist = (long long) (x2 - x1 + ry - ly) * 100 - ans * (20 - acos(-1) * 5);
	if (ans == x2 - x1 + 1 || ans == ry - ly + 1)
		dist += acos(-1) * 5;
	printf("%.15lf\n", dist);
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int l = 0;
    int r = 0;
    int sum = a[0];
    int xo = a[0];
    ll ans = 0;
    while (r<n) {
        if (sum==xo) {
            ans += (r-l+1);
            r++;
            sum += a[r];
            xo ^= a[r];
        }
        else {
            sum -= a[l];
            xo ^= a[l];
            l++;
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#include<cstdio>
#include<vector>
#include<utility>
#include<queue>

typedef vector<pair<int, int> > adj;

struct current_cost
{
    int index, cost;
    bool operator < (const current_cost &cur) const
    {
        return cost > cur.cost;
    }
};

current_cost init(int i, int c)
{
    current_cost cur;
    cur.index = i, cur.cost = c;
    return cur;
}

int main()
{
    int i, j, k, n, m, r, next, cost;
    scanf("%d %d %d", &n, &m, &r);
    adj *adlist;
    adlist = new adj [n];

	for(int k = 0; k < m; k++){
		scanf("%d %d %d", &j, &next, &cost);
		adlist[j].push_back(make_pair(next, cost));
	}

    int *d;
    d = new int [n];
    for(i = 0; i < n; i++){ d[i] = -1; }
	d[r] = 0;

    priority_queue<current_cost> C;
    current_cost cur = init(r, 0);
    C.push(cur);

    int size;
    bool *check;
    check = new bool [n];
    for(i = 0; i < n; i++){ check[i] = false; }

    while(!C.empty())
    {
        cur = C.top(); C.pop();
		i = cur.index;
        if(check[i]) continue;
        check[i] = true;
 
        size = adlist[i].size();
        for(int j = 0; j < size; j++){
            int k = adlist[i][j].first;
            if(d[k] < 0 || d[i] + adlist[i][j].second < d[k]){
                d[k] = d[i] + adlist[i][j].second;
                C.push(init(k, d[k]));
            }
        }
    };
    for(i = 0; i < n; i++){
		(check[i] ? printf("%d\n", d[i]) : printf("INF\n"));
	}
    return 0;
}

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

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> xs(n);
	for (auto &x : xs)
	{
		cin >> x;
	}
	vector<int64_t> as, bs;
	bs.emplace_back(0);
	for (auto &x : xs)
	{
		if (x < 0)
		{
			as.emplace_back(-x);
		}
		else
		{
			bs.emplace_back(x);
		}
	}
	as.emplace_back(0);
	reverse(as.begin(), as.end());
	int64_t ans = numeric_limits<int64_t>::max();
	for (int i = 0; i <= k; i++)
	{
		if (as.size() <= i)
		{
			break;
		}
		if (bs.size() <= k - i)
		{
			continue;
		}
		ans = min(ans, 2 * as[i] + bs[k - i]);
		ans = min(ans, as[i] + 2 * bs[k - i]);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

// chmax, chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll N = 55555;

vector<bool> isp(N+1, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}

int main() {
    int X;
    cin >> X;
    
    sieve();
    int count = 0;
    for ( int i = 1; i <= N; ++i){
        if ( isp[i] and i % 5 == 1 ){
            cout << i << " " ;
            ++count;
            if ( count == X ) break;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num = 0;

  bool flag = true;
  
  vector<int> a(5);
  int k;
  for (int i = 0; i < a.size(); ++i) cin >> a[i];
  cin >> k;

  for (int i = 0; i < a.size(); ++i) {
    for (int j = i + 1; j < a.size(); ++j) {
      if (a[j] - a[i] > k) flag = false;
    }
  }

  if (flag) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  
  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>

using  namespace std;

int main() {

    long long n;
    cin >> n;
    long long keep = 0;
    string final;
    string total;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";


    while (n > 26){
        keep = n%26;

       if (keep == 0){
           keep = 26;
       }

        n -= keep;

       final += alphabet[keep - 1];
       n/= 26;
    }

    if (n < 26){
        final += alphabet[n - 1];
    } else if (n == 26 || n == 0){
        final += 'z';
    }

    for (int i = 1; i <= final.length(); i++){
        total += final[final.length() - i];
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <locale>
using namespace std;

int main() {
	string text;
	locale loc;
	int size = 0;
	char c;

	getline(cin, text);
	size = text.size();
	for (int i = 0; i < size; i++) {
		c = text[i];
		if(65 <= c && c <=90 ) {
			c = c + 32;
		} else if(97 <= c && c <= 122) {
			c = c - 32;
		}
		cout << static_cast <char> (c);
	}
	cout << endl;
}



Measured memory_bytes: 3160
import sys

n, y = map(int, input().split())
y = y // 1000

for i in range(n + 1):
    for j in range(n + 1 - i):
        if i * 10 + j * 5 + (n - i - j) * 1 == y:
            print(i, j, n - i - j)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

struct node{
	int s,e,m;
	ll val=0,lazy=0;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			val=min(l->val,r->val);
		}
		else{
			val=s;
		}
	}
	
	void propo(){
		if (lazy){
			val+=lazy;
			if (s!=e){
				l->lazy+=lazy;
				r->lazy+=lazy;
			}
			lazy=0;
		}
	}
	
	void update(int i,int j,ll k){
		if (s==i && e==j) lazy+=k;
		else{
			if (j<=m) l->update(i,j,k);
			else if (m<i) r->update(i,j,k);
			else l->update(i,m,k),r->update(m+1,j,k);
			
			l->propo(),r->propo();
			val=min(l->val,r->val);
		}
	}
	
	ll query(int i,int j){
		propo();
		
		if (s==i && e==j) return val;
		else if (j<=m) return l->query(i,j);
		else if (m<i) return r->query(i,j);
		else return min(l->query(i,m),r->query(m+1,j));
	}
} *root;

int n;
vector<ii> l,r;

ll memol[200005],memor[200005];


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int TC;
	cin>>TC;
	while (TC--){
		l.clear();
		r.clear();
		
		cin>>n;
		
		rep(x,0,n+1) memol[x]=memor[x]=0;
		
		ll ans=0;
		
		int a,b,c;
		rep(x,0,n){
			cin>>a>>b>>c;
			
			if (a==n) ans+=b;
			else if (b>c) l.push_back(ii(b-c,a)),ans+=c;
			else r.push_back(ii(c-b,n-a)),ans+=b;
		}
		
		sort(all(l));
		reverse(all(l));
		
		sort(all(r));
		reverse(all(r));
		
		int idx;
		
		root=new node(0,n);
		idx=0;
		
		for (auto &it:l){
			if (root->query(it.se,n)>0){
				root->update(it.se,n,-1);
				memol[idx+1]=memol[idx]+it.fi;
				idx++;
			}
		}
		rep(x,0,n) memol[x+1]=max(memol[x+1],memol[x]);
		
		root=new node(0,n);
		idx=0;
		
		for (auto &it:r){
			if (root->query(it.se,n)>0){
				root->update(it.se,n,-1);
				memor[idx+1]=memor[idx]+it.fi;
				idx++;
			}
		}
		rep(x,0,n) memor[x+1]=max(memor[x+1],memor[x]);
		
		//rep(x,0,n+1) cout<<memol[x]<<" "<<memor[x]<<endl;
		
		ll best=0;
		rep(x,0,n+1) best=max(best,memol[x]+memor[n-x]);
		
		//cout<<ans<<endl;
		cout<<ans+best<<endl;
	}
}


Measured memory_bytes: 59448
ans=float("Inf")
N=int(input())
l=list(input())
W=0
E=l.count("E")
for i in range(N):
   if l[i]=="W":
      ans=min(ans,W+E)
      W+=1
   else:
      E-=1
      ans=min(ans,W+E)
print(ans)

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

int main(){
	ll ans = 0;
	string s; cin >> s;
	ll tmp = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'B') tmp++;
		else ans += tmp;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int inf=1e5+5;
typedef long long ll;
double mx=-123456789;
ll n,m;
vector<double>v;
int main()
{
   cin>>n;
   ll a[n+1];
   ll sum=0;
   ll cnt=0;
   ll mn=123456789125;
   for(ll i=0;i<n;i++){
    cin>>a[i];
    sum+=abs(a[i]);
    if(a[i]<0){
        cnt++;
    }
    mn=min(mn,abs(a[i]));
   }
   //cout<<mn<<endl;
   if(cnt%2==1){
    sum-=2*mn;
   }
   cout<<sum<<endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
int s[2521], t[2521];

ll sm[2521][2521];
ll dp[2521][2521];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,n)scanf("%d",s+i);
    REP(i,m)scanf("%d",t+i);
    dp[0][0] = 1;
    sm[1][1] = 1;
    FOR(i,1,2521)sm[1][i] = sm[i][1] = 1;
    REP(i,n)REP(j,m){
        if(i<n && j<m && s[i]==t[j]){
            dp[i+1][j+1] = sm[i+1][j+1];
        }
        sm[i+2][j+2] = (sm[i+1][j+2] + sm[i+2][j+1] - sm[i+1][j+1] + dp[i+1][j+1] + MOD) % MOD;
    }
    printf("%lld\n",sm[n+1][m+1]);
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
  string n;
  cin >> n;
  int ans = 0;
  rep(i,4){
  if(n[i]==n[i+1]&&n[i+1]==n[i+2])ans=1;
  }
  if(ans==1)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define D long double
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> h;
    for (int i=0; i < n; i++){
        cin >> v[i];
        h[v[i]]++;
    }
    int ans = 0;
    for (int i=0; i < n; i++){
        if (h[v[i]] < v[i]){
            ans += h[v[i]];
            h[v[i]] = 0;
        }
        else{
            ans += h[v[i]] - v[i];
            h[v[i]] = v[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();

    for (char c : s.toCharArray())
      System.out.print((char) (((c + n) - 'A') % 26 + 'A'));

  }
}

Measured memory_bytes: 25684
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define EPS 1e-7
#define INF 0x3f3f3f3f
#define ri register int
#define debug(s, i) (cout << "PARSING THROUGH " << s << " No." << i << endl)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

template <typename T> inline void chkmin(T &a, T b) {a < b ? a : a = b;}
template <typename T> inline void chkmax(T &a, T b) {a < b ? a = b : a;}

namespace fast_IO
{
	#define gets getchar
/*	inline char gets()
	{
		static char buf[100000], *p1, *p2;
		return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
	}*/

	inline int read_int()
	{
		register int ret = 0, f = 1; register char c = gets();
		while(c < '0' || c > '9') {if(c == '-') f = -1; c = gets();}
		while(c >= '0' && c <= '9') {ret = (ret << 1) + (ret << 3) + int(c - 48); c = gets();}
		return ret * f;
	}
	#undef gets
}using namespace fast_IO;

#define MAXN 200005
#define MOD 1000000007

int N;
ll ans = 0;
int a[MAXN];
int pre[MAXN], last[MAXN];
ll f[MAXN][2];
ll sum[MAXN];

inline void init()
{
	N = read_int();
	for(ri i = 1; i <= N; i++)
	{
		a[i] = read_int();
		pre[i] = last[a[i]];
		last[a[i]] = i;
	}
	f[0][0] = 1, ans = 1;
	for(ri i = 1; i <= N; i++)
	{
		f[i][0] = f[i - 1][0] + f[i - 1][1];
		f[i][0] %= MOD;
		if(a[i - 1] == a[i])
			continue;
		if(pre[i] != 0)
			f[i][1] += sum[a[i]], f[i][1] %= MOD;
		sum[a[i]] += f[i][0], sum[a[i]] %= MOD;
	}
	printf("%lld\n", (f[N][0] + f[N][1]) % MOD);
}

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

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define  ll  long long
#define rep(k, n)  for(int i=k; i<n;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
using namespace std;

int main(){
    int h, a, cnt=0;
    cin >> h >> a;

    while(h>0){
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def get_fact(n):
    temp = 1
    fac = [1]
    for i in range(1, n + 1):
        temp *= i
        fac.append(temp)
    return fac
def get_comb(n):  # n C n まで

    fac = get_fact(n)
    com  = [["error" for _ in range(n+1)] for _ in range (n + 1)]
    for i in range(n + 1):
        for j in range(i + 1):
            if  i >= j:
                com[i][j] = fac[i] // (fac[i-j] * fac[j])

    return com

N ,P  =list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
As = list(map(lambda x :x%2 ,As))
one = As.count(1)
zero =As.count(0)
ans = 0
com = get_comb(N)
z = 0
for i  in range(zero + 1):
    z += com[zero][i]
o = 0
if P == 0:
    for i in range(0,one + 1 , 2):
        o += com[one][i]
else:
    for i in range(1,one + 1 , 2):
        o += com[one][i]
print(o * z)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int ans = 0;
		for(int i=1; i<s.length; i++)
			if(s[i]!=s[i-1])
				ans++;

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 14340
r, g, b, n = map(int, input().split())

ans = 0
r_p = n // r
for i in range(n // r + 1):
    tmp = n - r * i
    for j in range(tmp // g + 1):
        remain = tmp - g * j
        if remain % b == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
char data[4] = {'7','5','3','0'};
#define maxn 1005
int sum = 0;
string a;

bool is_ok(string a){
	bool flag1 = false;
	bool flag2 = false;
	bool flag3 = false;
	bool flag4 = true;
	int ss = 0;
	while(a[ss] == '0')
		++ss;
	
	for(int i = ss;i < a.size();++i){
		if(a[i] == '7'){
			flag1 = true;
		}
		if(a[i] == '5'){
			flag2 = true;
		}
		if(a[i] == '3'){
			flag3 = true;
		}
		if(a[i] == '0')
			flag4 = false;
	}
	return (flag1&flag2&flag3&flag4);
}

void dfs(int len,string &tmp){
	if(len == 0){
		if(is_ok(tmp) && tmp <= a) {
			++sum;
			//cout << tmp << endl;  
		}
		return;
	}
	for(int i = 0;i < 4;++i){
		tmp[len-1] = data[i];
		dfs(len-1,tmp);
	}
}





int main()
{
//	freopen("D:\\patin.txt","r",stdin);
	cin >> a;
	string tmp = a;
	dfs(tmp.size(),tmp);
	cout << sum << endl;
	return 0;	
} 

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

using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+2;
int arr[N][3],dp[N][3];
int n,k;


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    
    cin>>n;
    for(int i=0;i<n;i++){
    	for(int j=0;j<3;j++)
    		cin>>arr[i][j];
    }

    for(int i=0;i<3;i++)
    	dp[0][i]=arr[0][i];


    for(int i=1;i<n;i++){
    	dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + arr[i][0];
    	dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + arr[i][1];
    	dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + arr[i][2];
    }
    int ans = -1;
    for(int i=0;i<3;i++)
    	ans = max(ans,dp[n-1][i]);
    cout<<ans;



    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Linq;

namespace _0643
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[,] city = new int[x[0], x[1]];
            for (int i = 0; i < x[0]; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < x[1]; j++) city[i, j] = a[j];
            }
            int ret = int.MaxValue;
            for (int i = 0; i < x[0]; i++)
            {
                for (int j = 0; j < x[1]; j++)
                {
                    int now = 0;
                    for (int k = 0; k < x[0]; k++)
                    {
                        for (int l = 0; l < x[1]; l++)
                        {
                            now += city[k, l] * Math.Min(Math.Abs(i - k), Math.Abs(j - l));
                        }
                    }
                    ret = Math.Min(ret, now);
                }
            }
            Console.WriteLine(ret);
        }
    }
}


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

int main() {
	int x, y, z;

	cin >> x >> y >> z;

	int A, B, C;

	A = y;
	B = x;
	C = z;

	A = z;
	C = y;

	cout << A << " " << B << " " << C << endl;
}

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

using namespace std;
typedef long long ll;

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

int main()
{
    ll a, b, c, d;
    ll ans;
    cin >> a >> b >> c >> d;

    ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

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


Measured memory_bytes: 3628
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Mon Dec 10 23:54:24 2018
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	if N%2 == 0 {
		fmt.Println(N)
		return
	}
	fmt.Println(2 * N)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;

priority_queue<int,vector<int>,greater<int>>ans;
void dfs(int k){
    if(k>=1e10){return;}
    else{
        if(k%10==0){ans.push(k*10);ans.push(k*10+1);dfs(k*10);dfs(k*10+1);}
        else if(k%10==9){ans.push(k*10+8);ans.push(k*10+9);dfs(k*10+8);dfs(k*10+9);}
        else{
            ans.push(k*10+k%10-1);dfs(k*10+k%10-1);
            ans.push(k*10+k%10);dfs(k*10+k%10);
            ans.push(k*10+k%10+1);dfs(k*10+k%10+1);
        }
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;cin>>k;
    for(int i=1;i<=9;i++){
        ans.push(i);
        dfs(i);
    }
    for(int i=0;i<k-1;i++){
        ans.pop();
    }
    cout<<ans.top()<<endl;
}

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

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

using namespace std;

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

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

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

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

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

int N;

void func(int s, int idx, int high,int col)
{
	s *= 10;
	s += idx;

	if (col == N)
	{
		string res;
		rep(i, 0, N)
		{
			res += 'a' + s % 10;
			s /= 10;
		}
		reverse(all(res));
		cout << res << endl;
		return;
	}

	rep(i, 0, high + 2)
	{
		func(s, i, max(i, high), col + 1);
	}
}

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

	cin >> N;

	func(0, 0, 0,1);

	return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N  = sc.nextInt();

        int count = 0;
        for (int A = 1; A<N  ; A++) {//A
            count+= (N-1)/A;
        }


        System.out.println(count);

    }

}


Measured memory_bytes: 35652
N,M = map(int,input().split())
X = list(map(int,input().split()))

X.sort()
Y = []
# それぞれの区間の長さ
for i in range(M - 1):
    Y += [X[i + 1] - X[i]]
Y.sort()
# 担当する区間の個数の和
print(sum(Y[:max(0, M - N)]))

Measured memory_bytes: 57128
#include <iostream>
#include "math.h"
#include <map>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
int main(){
  ll n; 
  cin>>n;
  ll a[n];
  map<ll,ll> m; 
  ll an = 0;
  for(int i=0;i<n;++i){
  	cin>>a[i];
    if(m.find(i-a[i])!=m.end()) an += m[i-a[i]];
    if(m.find(a[i]+i)!=m.end()) m[i+a[i]]++; else m[i+a[i]]=1;
  } 
  cout<<an<<'\n';
  
}


Measured memory_bytes: 17668
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
   ll n,k; cin >> n >> k;
   if(2 * n < k)print(n);
   if(2 * n >= k)print(min(n % k,abs((n % k) - k)));
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
#include <set>
  
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<"+"<<endl;
    }else if(a*b==15){
        cout<<"*"<<endl;
    }else{
        cout<<"x"<<endl;
    }
}

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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int mod = 998244353;
const int N = 200001;
const int V = 1000001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int a[N], s[V], inv[V], mu[V], h[V];
int plen, p[V];
bool v[V];

void getp() {
	mu[1] = 1;
	for(int i = 2; i < V; i++) {
		if(!v[i]) p[++plen] = i, mu[i] = -1;
		for(int j = 1; j <= plen && i * p[j] < V; j++) {
			v[i * p[j]] = 1;
			if(i % p[j] == 0) break;
			mu[i * p[j]] = -mu[i];
		} if(mu[i] < 0) mu[i] = mod + mu[i];
	}
}

int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
int dec(int x, int y) {x -= y; return x < 0 ? x + mod : x;}

int main() {
	int n = read(); getp(); int sum = 0;
	for(int i = 1, x; i <= n; i++) x = read(), s[x] = add(s[x], x), sum = add(sum, x);
	for(int i = 1; i < V; i++) for(int j = i * 2; j < V; j += i) s[i] = add(s[i], s[j]);
	inv[0] = inv[1] = 1; for(int i = 2; i < V; i++) inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i < V; i++) for(int j = i; j < V; j += i) h[j] = add(h[j], (LL)mu[i] * inv[j / i] % mod);
	int ans = 0;
	for(int i = 1; i < V; i++) 
	ans = add(ans, (LL)h[i] * s[i] % mod * s[i] % mod);
	ans = dec(ans, sum), ans = (LL)ans * inv[2] % mod;
	put(ans), puts("");
	return 0;
}


Measured memory_bytes: 17920
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

bool isPrime(int n)
{
	if (n < 2)
	{
		return false;
	}
	if (n == 2)
	{
		return true;
	}
	if (n % 2 == 0)
	{
		return false;
	}

	for (int i = 3; i <= (int)sqrt(n); i += 2)
	{
		if (n%i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int ta;
		cin >> ta;
		a.push_back(ta);
	}

	cout << count_if(a.begin(), a.end(), [&](int _a) {return isPrime(_a); }) << endl;

	return 0;
}

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

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

  int N;
  cin >> N;
  long long A[N];
  long long sum[N] = {};
  rep(i, N){
    cin >> A[i];
    if(i == 0) sum[0] = A[i];
    else sum[i] = sum[i-1] + A[i];
  }  
  long long ans = abs(sum[0] - (sum[N-1] - sum[0]));
  rep(i, N-1){
    ans = min(ans, abs(sum[i] - (sum[N-1] - sum[i])));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
int main(){
    long long N;
    std::cin >> N;
    std::vector<long long> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) std::cin >> a[i] >> b[i] >> c[i];
    long long dp[3][N];//dp[i][j]でj日目にiを選ぶときの最大値とする(i == 0　ならa, 1ならb)
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i< N; i++){
        for(int j = 0; j < 3; j++){
            if(j == 0) dp[j][i] = std::max(dp[1][i - 1] + a[i], dp[2][i - 1] + a[i]);
            else if(j == 1) dp[j][i] = std::max(dp[0][i - 1] + b[i], dp[2][i - 1] + b[i]);
            else dp[j][i] = std::max(dp[1][i - 1] + c[i], dp[0][i - 1] + c[i]);
        }
    }
    long long ans = 0;
    for(int i = 0; i < 3; i++) ans = std::max(ans, dp[i][N - 1]);
    std::cout << ans << std::endl;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main() {
    char c;
    scanf("%c", &c);
    if (c == 'a' ||
        c == 'e' ||
        c == 'i' ||
        c == 'o' ||
        c == 'u')
        puts("vowel");
    else
        puts("consonant");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int power(int b, int p) {
    int res = 1;
    while(p) {
        res *= b;
        p--;
    }
    return res;
}

int main(void) {
    int X;
    cin >> X;
    int ans = 0;
    for(int b=1; b<=35; b++) {
        for(int p=2; p<=10; p++) {
            if(power(b, p) <= X) {
                ans = max(ans, power(b, p));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
import collections


S = input()
T = input()

cnt_S = collections.Counter(S)
cnt_T = collections.Counter(T)
S_values, S_counts = zip(*cnt_S.most_common())
T_values, T_counts = zip(*cnt_T.most_common())
if S_counts == T_counts:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4016
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  if(*(double*)a>*(double*)b) return 1;
  return 0;
}

int main(void){
  double ans=0;
  int n,i;
  scanf("%d",&n);
  double v[n];
  for(i=0;i<n;i++) scanf("%lf",&v[i]);
  qsort(v,n,sizeof(v[0]),cmp);
  ans = (v[0]+v[1])/2.0;
  for(i=2;i<n;i++){
    //printf("ans:%f v[%d]:%f new_ans:%f\n",ans,i,v[i],(ans+v[i])/2);
    ans = (ans+v[i])/2.0;
  }
  printf("%f\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	cout << max(0, min(B, D)-max(A, C)) << endl;
}

Measured memory_bytes: 256
let is_prime = Array.make 55556 true
let primes = begin
  is_prime.(0) <- false; is_prime.(1) <- false;
  for i = 2 to 55555 do
    if is_prime.(i) then begin
      for j = i to 55555 / i do
        is_prime.(i*j) <- false;
      done
    end
  done;

  Array.mapi (fun i b -> i, b) is_prime
  |> Array.fold_left (fun stk (i, b) -> if b then i::stk else stk) []
  |> List.rev
end

let rec take n xs = if n <= 0 then [] else
  match xs with [] -> [] | x::xs' -> x :: take (n-1) xs'

let () =
  Scanf.scanf "%d" @@ fun g ->
  List.filter (fun x -> x mod 5 = 1) primes
  |> take g |> List.iter (Printf.printf "%d ");
  print_newline ()



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int g[52][52];
void solve(int x,int y){
  g[x][y]=0;
  for(int i=-1;i<=1;++i){
    for(int j=-1;j<=1;++j){
      if(g[x+i][y+j]) solve(x+i,y+j);
    }
  }
}
int main(){
  int w,h,cnt;
  while(cin>>w>>h&&w&&h){
    cnt=0;
    for(int i=0;i<=h+1;++i){
      for(int j=0;j<=w+1;++j){
        if(i==0||j==0||i==h+1||j==w+1) g[i][j]=0;
        else cin>>g[i][j];
      }
    }
    for(int i=1;i<=h;++i){
      for(int j=1;j<=w;++j){
        if(g[i][j]){
          solve(i,j);
          ++cnt;
        }
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int NM[200];
	int N;
	cin >> N;
	int Nh[100], Nm[100];
	for (int i = 0; i < N; i++){
		cin >> Nh[i] >> Nm[i];
		NM[i] = Nh[i] * 60 + Nm[i];
	}

	int M;
	cin >> M;
	int Mh[100], Mm[100];
	for (int i = 0; i < M; i++){
		cin >> Mh[i] >> Mm[i];
		NM[N + i] = Mh[i] * 60 + Mm[i];
	}
	sort(NM, NM+N+M);
	for (int i = 0; i < N + M; i++){
		if (NM[i] != NM[i + 1]){
			cout << NM[i] / 60 << ':';
			if (NM[i] % 60 < 10){
				cout << '0' << NM[i] % 60;
			}
			else{
				cout << NM[i] % 60;
			}
			if (N + M - 1 != i){
				cout << ' ';
			}
			else cout << endl;
		}
	}
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())



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



// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }




int main() {

  vint a(5);
  rep(i,5){
    cin >> a[i];
  }

  ll ans = 0;
  ll res = 9;


  rep(i,5){
    ans += (a[i]-1)/10 * 10 + 10;
    res = min(res, (a[i]-1)%10 );
  }

  // cout << res << endl;
  cout << ans+(res+1)-10 << endl;


}

















//


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int INF = 1<<29;
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int H, W, N;
int D[16][16];
string town[1024];
int dist[1024][1024];
P factory[16];
bool cheese[16];

bool in(int r, int c) {
  return 0 <= r && r < H && 0 <= c && c < W;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  fill(cheese, cheese + 10, false);
  REP(i, 10) REP(j, 10) D[i][j] = INF;
  cin >> H >> W >> N;
  REP(i, H) cin >> town[i];
  REP(i, H) REP(j, W) {
    if (town[i][j] == 'S') {
      factory[0] = P(i, j);
      cheese[0] = true;
    } else if (town[i][j] != '.' && town[i][j] != 'X') {
      factory[town[i][j] - '0'] = P(i, j);
      cheese[town[i][j] - '0'] = true;
    }
  }
  assert(cheese[0] && cheese[1]);

  REP(i, 10) {
    if (!cheese[i]) continue;
    REP(r, H) REP(c, W) dist[r][c] = -1;
    int sr = factory[i].first, sc = factory[i].second;
    queue<T> que;
    que.push(T(sr, sc, 0));
    while (!que.empty()) {
      int r, c, d;
      tie(r, c, d) = que.front(); que.pop();
      if (dist[r][c] != -1) continue;
      dist[r][c] = d;
      if (town[r][c] == 'S') {
	D[i][0] = d;
      } else if (town[r][c] != '.' && town[r][c] != 'X') {
	D[i][town[r][c] - '0'] = d;
      }
      REP(j, 4) {
	int nr = r + dr[j], nc = c + dc[j];
	if (in(nr, nc) && town[nr][nc] != 'X' && dist[nr][nc] == -1) {
	  que.push(T(nr, nc, d+1));
	}
      }
    }
  }

  int ans = 0;
  REP(i, N) ans += D[i][i+1];
  cout << ans << endl;      
  return 0;
}

Measured memory_bytes: 6364
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

#define MAX 50000
int n, dif, a[MAX];

int main() {
	cin >> n;
	while (n) {
		dif = 1000000;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);

		for (int i = 0; i < n - 1; i++) {
			if (abs(a[i] - a[i + 1]) < dif) {
				dif = abs(a[i] - a[i + 1]);
			}
		}
		cout << dif << endl;

		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3152
#include <iostream>

int main(){
  int a,b,c,d;
  std::cin >> a >> b >> c >> d;
  if(a + b > c + d)
    std::cout << "Left" << std::endl;
  else if(a + b < c + d)
    std::cout << "Right" << std::endl;
  else
    std::cout << "Balanced" << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, K; cin >> n >> K;
    ll res = 0LL;
    vi cnt(K);
    rep(i, 1, n + 1) cnt[i % K]++;

    rep(A_, 1, n + 1){
        int A = A_ % K;

        int B = (K - A) % K;
        if(B != 0 and 2 * B % K != 0) continue;

        res += 1LL * cnt[B] * cnt[B];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;


int main()
{

    cin>>n;
if(n>=400 && n<=599) cout<<8;
else if(n>=600 && n<=799)cout<<7;
else if(n>=800 && n<=999)cout<<6;
else if(n>=1000 && n<=1199)cout<<5;
else if(n>=1200 && n<=1399)cout<<4;
else if(n>=1400 && n<=1599)cout<<3;
else if(n>=1600 && n<=1799)cout<<2;
else cout<<1;

    return 0;
}
// Happy Coding  (:


Measured memory_bytes: 3632