akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

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

			String s = scan.next();
			Character[]S = new Character[s.length()];
			for(int i = 0;i<s.length();i++) {
				S[i] = s.charAt(i);
			}

			Arrays.sort(S);


			String t = scan.next();
			Character[]T = new Character[t.length()];
			for(int i = 0;i<t.length();i++) {
				T[i] = t.charAt(i);
			}

			Arrays.sort(T,Collections.reverseOrder());


			/*
			for(int i = 0;i<S.length;i++)System.out.print(S[i]);
			System.out.println();
			for(int i = 0;i<T.length;i++)System.out.print(T[i]);
			*/



			int ok = 1;
			int i = 0;
			int a = Math.min(S.length, T.length);
			while(true) {
				if(S[i]==T[i]) {
					i++;
					if(i==a)break;
				}else if(S[i]<T[i]) {
					break;
				}else {
					ok=0;
					break;

				}
			}

			if(ok==0) {
				System.out.println("No");
			}else {
				if(i==a) {
					if(S.length<T.length) {
						System.out.println("Yes");
					}else {
						System.out.println("No");
					}

				}else {
					System.out.println("Yes");
				}

			}








		}


	}


}


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

using namespace std;

int main(void)
{
    int N, K;
    cin >> N >> K;
    long long a = 0;
    long long b = 0;
    for(int i = 1; i <= N; i++){
      if(i % K == 0){
        a++;
      }
      if(K % 2 == 0 && i % K == K / 2){
        b++;
      }
    }

    cout << (long long)(a * a * a) + (long long)(b * b * b) << endl;
}

Measured memory_bytes: 764
N = int(input())
H = list(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(H[i] - H[i-1]), dp[i-2] + abs(H[i] - H[i-2]))

print(dp[N-1])


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

using namespace std;

int main()
{
    int n,k;
    char x;
    char dis[15]={};
    string s;
    cin>>n>>k;
    while(k--){
        cin>>x;
        dis[x]=1;
    }
    int i=n;
    while(true){
        stringstream ss;
        ss<<i;
        ss>>s;
        //cout<<s<<endl;
        int flag=0;
        for(auto p:s){
            if(dis[p]==1){
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<s<<endl;
            return 0;
        }

i++;
}

    return 0;
}


Measured memory_bytes: 256
// べき乗 ( 繰り返し二乗法 )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cassert>

#include<vector>
#include<queue>
#include<set>

using namespace std;

typedef unsigned long long ullong;

// 繰り返し自乗法を実施する関数
// x : 基数
// n : 指数
// M : 割る数
ullong power(ullong x, ullong n, ullong M)
{
	ullong res = 1;

	if( n > 0 )
	{
		res = power(x, n / 2, M);

		if( n % 2 == 0 )
		{
			// 指数が偶数の時
			res = ( res * res ) % M;
		}
		else
		{
			// 指数が奇数の時
			res = ( ( ( res * res ) % M ) * x ) % M;
		}
	}

	return res;
}

int main(void)
{
	long m, n;

	cin >> m >> n;

	cout << power(m, n, 1000000007) << endl;

	return 0;
 }



Measured memory_bytes: 3132
#include<cstdio>
using namespace std;
char a[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'},b[17];
int s;
int main(){
    scanf("%s",&b);
    for(int i=0;i<16;++i){
        if(a[i]!=b[i]){
            ++s;
        }
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;



int main(){
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
 	return 0;
 }




Measured memory_bytes: 256
import math
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]

for i in range(n):
    for j in range(1+math.floor(math.log(a[i]+0.1)/math.log(2))):
        b.append(a[i]//(2**j)-a[i]//(2**(j+1)))
        
b.sort()
bb=b
b=[bb[len(b)-1-i] for i in range(len(bb))]


print(sum(a)-sum(b[0:m]))

Measured memory_bytes: 145996
import java.util.Scanner;

public class Main {
	  public static void main(String args[]){
	  	Scanner sc = new Scanner(System.in);
	    String s = sc.next();
	    
	    if(s.length() < 5) System.out.println("No");
	    
	    else if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
	    	System.out.println("Yes");
	    } else {
	    	 System.out.println("No");
	    }
	  }
	}


Measured memory_bytes: 22228
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int s = stdIn.nextInt();
		int w = stdIn.nextInt();
		
		if(w>=s) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
		
		
	}

}


Measured memory_bytes: 35764
s = gets.chomp
up = s.slice(0,2).to_i
down = s.slice(2,2).to_i
yymm = 1 <= down && down <= 12
mmyy = 1 <= up && up <= 12

if yymm && !mmyy
	puts "YYMM"
elsif !yymm && mmyy
	puts "MMYY"
elsif yymm && mmyy
	puts "AMBIGUOUS"
else
	puts "NA"
end



Measured memory_bytes: 14204
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
print(len(uf.roots())-1)


Measured memory_bytes: 12928
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lld n,m;
	cin >> n >> m;
	lld ans=0;
	if(m<=2*n)
	{
		ans=(m/2);
	}
	else
	{
		ans=n;
		m-=(2*n);
		ans+=(floor((double)m/4));
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  rep(i,5){
    int x;
    cin >> x;
    if(x==0) cout << i + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3516
//
// Created by Debajyoti Dasgupta on 11-04-2020.
//

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fr(i, n) for(int i=0;i<n;i++)
#define frr(i, n) for(int i=n;i>=0;i--)
#define fra(i, a, n) for(int i=a;i<n;i++)
#define frra(i, a, n) for(int i=a;i>=n;i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define endl '\n'

typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef set<int> si;
typedef unordered_map<int, int> uii;
typedef unordered_set<int> usi;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int inf = LONG_LONG_MAX;

using point = pair<pii, pii>;

void solve() {
    //CODE BEGIN
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                ans += __gcd(__gcd(i + 1, j + 1), k + 1);
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    for (int i = 0; i < t; ++i) {
//        cout << "Case #" << i + 1 << ": " << endl;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
import sys

sys.setrecursionlimit(10**9)

n , m = map(int,input().split())

g = [[] for i in range(n)]

dp = [-1] *n
for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)
  
# finding longest path for vertice i
def dfs(i):
  if dp[i]!=-1:
    return dp[i]
  temp = 0
  for nv in g[i]:
    temp = max(temp, dfs(nv)+1)
  
  dp[i]=temp
  return temp
  
# finding overall longest path  
res = 0  
for i in range(n):
  res = max(res, dfs(i))
  
print(res)


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

#include <cmath>
#include <iomanip>
#include <vector>

using namespace std;
#define int ll
#define ll long long

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

signed main() {
  int M, T, P, R;
  while(cin >> M >> T >> P >> R, M||T||P||R){
    struct Team{
      vector<int> cnt;
      vector<int> acTime;
      int sum, time;
      int idx;

      Team(int p) : cnt(p, 0), acTime(p, -1), sum(-1), time(-1), idx(-1) {}
      void calc(){
        if(sum != -1) return;
        sum = time = 0;
        REP(i, cnt.size()) {
          if(acTime[i] == -1) continue;
          ++sum;
          time += acTime[i] + 20 * cnt[i];
        }
      }

      bool operator<(const Team& r) const {
        if(sum != r.sum) return sum > r.sum;
        if(time != r.time) return time < r.time;
        return idx > r.idx;
      }
      bool operator==(const Team& r) const {
        return sum == r.sum && time == r.time;
      }
    };

    vector<Team> teams(T, Team(P));
    REP(i, T) teams[i].idx = i + 1;
    REP(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      --t; --p;
      if(j == 0) {
        teams[t].acTime[p] = m;
      }else {
        teams[t].cnt[p]++;
      }
    }

    REP(i, T) teams[i].calc();
    std::sort(ALL(teams));

    Team pre(0);
    REP(i, T) {
      if(i != 0) {
        if(pre == teams[i]) {
          cout << '=';
        }else {
          cout << ',';
        }
      }
      cout << teams[i].idx;
      pre = teams[i];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register ll i=(a);i<=(b);i++)
#define For(i,a,b) for (register ll i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register ll j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pb push_back
#define pii pair<ll,ll>
#define MP make_pair
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,m,q,a[N],b[N],c[N],bian=0,kuai,fa[N];
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(ll x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
inline ll getfa(ll x) {return (x==fa[x])?x:fa[x]=getfa(fa[x]);}
inline void merge(ll x,ll y)
{
	ll fx=getfa(x),fy=getfa(y);
	if (fx==fy) return;
	kuai--;
	bian++;
	fa[fx]=fy;
	return;
}
inline void no()
{
	printf("No\n");
	exit(0);
}
int main()
{
	n=read(),m=read(),q=read();
	kuai=n;
	FOR(i,1,q) a[i]=1+read(),b[i]=1+read(),c[i]=read();
	if (m<n) 
	{
		FOR(i,1,q) if (c[i]) no();
		printf("Yes\n");
		return 0;
	}
	FOR(i,1,n) fa[i]=i;
	FOR(i,1,q) if (!c[i]) merge(a[i],b[i]);
	FOR(i,1,q) if (c[i])
	{
		ll fa=getfa(a[i]),fb=getfa(b[i]);
		if (fa==fb) no();
	}
	if (m<bian+kuai||m>bian+kuai*(kuai-1)/2) no();
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力 : S
S = input()

N = len(S)

if S == S[::-1] and S[0:int((N-1)/2)] == S[0:int((N-1)/2)][::-1] and S[int((N+3)/2-1):N] == S[int((N+3)/2-1):N][::-1]:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>

using namespace std;

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

int main() {
  string s, d[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  cin >> s;
  int r;
  rep(i,7) if(d[i] == s) r = 7-i;
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

const int MAX = 100010;
const ll mod = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[0]=inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}


int main(){
    ll n,k;cin>>n>>k;
    if(k==0){
        cout<<0<<endl;
        return 0;
    }
    ll a[100010];
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    ll an=0;
    init();
    rep(i,k-1,n){
        an+=(((a[i]*fac[i])%mod*finv[k-1])%mod*finv[i-k+1])%mod;
    }
    rep(i,0,n-k+1){
        an-=(((a[i]*fac[n-i-1])%mod*finv[k-1])%mod*finv[n-i-k])%mod;
    }
    an=(an+mod)%mod;
    cout<<an<<endl;
}
    









Measured memory_bytes: 3328
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);
const nin=()=>{const r = input[0];input.shift();return Number(r)};
const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};
const sin=()=>{const r = input[0];input.shift();return String(r)}
const out=(...a)=>{console.log(...a)}
const floor=(a)=>{return Math.floor(a)}
const abs=(a)=>{return Math.abs(a)}
const min=(...a)=>{return Math.min(...a)}
const max=(...a)=>{return Math.max(...a)}
const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}}
const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};
const permutation = ({ result = [], pre = [], post, n = post.length }) => {
  if (n > 0) {
    post.forEach((_, i) => {
      const rest = [...post];
      const elem = rest.splice(i, 1);
      permutation({ result, pre: [...pre, ...elem], post: rest, n: n - 1});
    });
  } else {
    result.push(pre);
  }
  return result;
}
const main = ()=>{
  let t = -1;
  let ans = 'Yay!';
  permutation({post:nrin(5), n:2}).some(a=>{
    if(t == -1) t=nin();
    if(abs(a[0] - a[1]) > t){ans = ':('; return true;}
  });
  out(ans);
}
main();

Measured memory_bytes: 7500
import java.util.Scanner;
  public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int S = N % 10;
      if(S == 3){
        System.out.println("bon");
        } else if (S == 2 || S == 4 || S == 5 || S == 7 || S == 9) {
        System.out.println("hon");
        } else if (S == 0 || S == 1 || S == 6 || S == 8) {
        System.out.println("pon");
      }
    }
  }

Measured memory_bytes: 35752
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scanf("%d %d %d", &n, &a, &b)
	// fmt.Println(n, a, b)

	sum := 0
	for i := 1; i <= n; i++ {
		dsum := digitSum(i)
		if a <= dsum && dsum <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}

func digitSum(num int) int {
	sum := 0
	for num > 0 {
		sum += (num % 10)
		num /= 10
	}
	return sum
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n, m, k;
    cin >> n >> m >> k;
    set<int> s;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            s.insert(m * i + n * j - 2 * j * i);
        }
    }
    if (s.find(k) != s.end())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 13056
import java.util.Scanner;

public class Main {

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

		for(int i = 0;i<m;i++) {
			n -= sc.nextInt();
		}
		if(n<0) {
			System.out.println(-1);
		}
		else {
			System.out.println(n);
		}
	}

}

Measured memory_bytes: 46308
#include <iostream>
#include <string>
#include <iterator>
#include <map>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long ll;


ll ans;
ll n;

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

    cin >> n;
    vector<int> h(n);
    vector<int> dp(n, INT32_MAX);
    for (ll i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;

    for (int i = 0; i < n-1; i++) {
        int first = abs(h[i+1]-h[i]);
        if (dp[i] + first < dp[i+1]) {
            dp[i+1] = dp[i] + first;
        }
        if (i < n - 2) {
            int second = abs(h[i+2]-h[i]);
            if (dp[i] + second < dp[i+2]) {
                dp[i+2] = dp[i] + second;
            }
        }
    }



    cout << dp[n-1] << '\n';
    return 0;
}

Measured memory_bytes: 1024
def cal_puddle(puddle):
    depth = 0
    score = 0
    for s in puddle:
        if s == "\\":
            score += depth + 0.5
            depth += 1
        elif s == "/":
            depth -= 1
            score += depth + 0.5
        elif s == "_":
            score += depth

        if depth == 0:
            return int(score)
    return int(score)

def get_puddles(diagram):
    hight = 0
    top_list = []
    in_puddle = True
    for index, s in enumerate(diagram + "\\"):
        if s == "/":
            in_puddle = True
            hight += 1
        if s == "\\":
            if in_puddle:
                in_puddle = False
                top_list.append([hight, index])
            hight -= 1

    puddles = []
    prev_hight = 0
    hight_list = [h for h, i in top_list]
    i = 0
    while i < len(top_list) - 1:
        cur_top = top_list[i]
        next_tops = list(filter(lambda top:cur_top[0] <= top[0], top_list[i + 1:]))
        #print(next_tops)
        if next_tops:
            next_top = next_tops[0]
            puddles.append((cur_top[1], next_top[1]))
            i = top_list.index(next_top)
        else:
            cur_top[0] -= 1
            cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1
    #print(hight_list)
    #print(top_list)
    #print(puddles)
    return puddles

def main():
    diagram = input()
    result = []
    for s,e in get_puddles(diagram):
        result.append(cal_puddle(diagram[s:e]))
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(i) for i in result]))
if __name__ == "__main__":
    main()

Measured memory_bytes: 8284
D,G=map(int,input().split())
pc=[[0,0] for i in range(D)]
ans=[]
for i in range(D):
    pc[i][0],pc[i][1]=map(int,input().split())

def solve(index,total):
    res=0
    g=0
    for i in reversed(range(D)):
        if i in index:
            x=(pc[i][0]-1)*(i+1)*100
            if x<total:
                total-=x
                res+=pc[i][0]-1
            elif x==total:
                res+=pc[i][0]-1
                g=1
                break
            else:
                res+=(pc[i][0]-1)-(x-total)//((i+1)*100)
                g=1
                break
    if g==1:
        return res
    else:
        return 10**20

for i in range(2**D):
    f=0
    index=[]
    total=0
    problem=0
    while 1<<f <= i:
        if i & 1<<f:
            index.append(f)
        f+=1
    for a in reversed(range(D)):
        if not(a in index):
            total+=pc[a][0]*(a+1)*100+pc[a][1]
            problem+=pc[a][0]
    if total<G:
        total=G-total
        ans.append(problem+solve(index,total))
    else:
        ans.append(problem)
print(min(ans))


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N, K; cin >> N >> K;
    vector<int> l(N); REP(i, N) cin >> l[i];

    sort(all(l), greater<int>());

    int cnt = 0;
    for(int i = 0; i < K; ++i) {
        cnt += l[i];
    }

    cout << cnt << endl;
}

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

namespace mondai0038
{
	class Program
	{
		static void Main(string[] args)
		{
			while( true ) {
				var	str	= Console.ReadLine();
				if( str == null ) {
					break;
				}
				
				var	card	= Array.ConvertAll( str.Split( ',' ), s => int.Parse( s ) );
				for( int i = 0; i < 5; i++ ) {
					if( card[ i ] == 1 ) {
						card[ i ]	= 14;
					}
				}
				Array.Sort( card );

				bool	one_pair	= is_one_pair( card );
				bool	two_pair	= is_two_pair( card );
				bool	three_card	= is_three_card( card );
				bool	straight	= is_straight( card );
				bool	full_house	= three_card && one_pair;
				bool	four_card	= is_four_card( card );
				if( four_card ) {
					Console.WriteLine( "four card" );
				} else if( full_house ) {
					Console.WriteLine( "full house" );
				} else if( straight ) {
					Console.WriteLine( "straight" );
				} else if( three_card ) {
					Console.WriteLine( "three card" );
				} else if( two_pair ) {
					Console.WriteLine( "two pair" );
				} else if( one_pair ) {
					Console.WriteLine( "one pair" );
				} else {
					Console.WriteLine( "null" );
				}
			}
		}


		static bool is_one_pair( int[] card )
		{
			int	pair_cnt	= 0;
			for( int i = 0; i < 5; i++ ) {
				int	cnt	= 0;
				for( int j = 0; j < 5; j++ ) {
					if( card[ j ] == card[ i ] ) {
						cnt++;
					}
				}
				if( cnt == 2 ) {
					pair_cnt++;
				}
			}
			if( pair_cnt == 2 ) {	// 全カード検索するのでペアは2つ検出される
				return( true );
			} else {
				return( false );
			}
		}

		static bool is_two_pair( int[] card )
		{
			int	pair_cnt	= 0;
			for( int i = 0; i < 5; i++ ) {
				int	cnt	= 0;
				for( int j = 0; j < 5; j++ ) {
					if( card[ j ] == card[ i ] ) {
						cnt++;
					}
				}
				if( cnt == 2 ) {
					pair_cnt++;
				}
			}
			if( pair_cnt == 4 ) {	// 全カード検索するのでペアは4つ検出される
				return( true );
			} else {
				return( false );
			}
		}

		static bool is_three_card( int[] card )
		{
			int	pair_cnt	= 0;
			for( int i = 0; i < 5; i++ ) {
				int	cnt	= 0;
				for( int j = 0; j < 5; j++ ) {
					if( card[ j ] == card[ i ] ) {
						cnt++;
					}
				}
				if( cnt == 3 ) {
					pair_cnt++;
				}
			}
			if( pair_cnt == 3 ) {	// 全カード検索するのでペアは3つ検出される
				return( true );
			} else {
				return( false );
			}
		}

		static bool is_straight( int[] card )
		{
			int	min	= card[ 0 ];
			int	i;
			for( i = 0; i < 5; i++ ) {
				if( card[ i ] != (min + i) ) {
					break;
				}
			}
			if( i >= 5 ) {
				return( true );
			} else {
				if( (card[ 0 ] == 2) && (card[ 1 ] == 3) && (card[ 2 ] == 4) && (card[ 3 ] == 5) && (card[ 4 ] == 14) ) {
					return( true );
				} else {
					return( false );
				}
			}
		}

		static bool is_four_card( int[] card )
		{
			int	max	= 0;
			for( int i = 0; i < 5; i++ ) {
				int	cnt	= 0;
				for( int j = 0; j < 5; j++ ) {
					if( card[ j ] == card[ i ] ) {
						cnt++;
					}
				}
				if( cnt > max ) {
					max	= cnt;
				}
			}
			if( max == 4 ) {
				return( true );
			} else {
				return( false );
			}
		}
	}
}

Measured memory_bytes: 5504
from heapq import heappush, heappop, heapify
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A = -A
A = list(A)
heapify(A)
for _ in range(M):    
    s = heappop(A)
    heappush(A, -(-s // 2))
A = np.array(A)
print(-int(np.sum(A)))

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

int main() {
  string O,E;
  cin >> E;
  cin >> O;
  for(int i=0; i<E.size();i++){
    cout << E[i];
    if(i < O.size()){
      cout << O[i];
    }
  }
  return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 71132
#include<stdio.h>
#include<math.h>
#define int long long

int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int main()
{ // dp array mein store kar ki n tak pahuchne mein ek pt se kitte paise lagenge
	int n;
	scanf("%lld",&n);

	int l=n+1;
	int h[l];
	int dp[l];

	for(int i=1;i<=n;i++)
	{scanf("%lld",&h[i]);}
	dp[1]=0;
	dp[2]=fabs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
	{
		dp[i]=min((fabs(h[i]-h[i-1])+dp[i-1]),(fabs(h[i]-h[i-2])+dp[i-2]));
	}
	printf("%lld",dp[n]);
	return 0;
}


		



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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    ll A;
    long double B;
    cin >> A >> B;
    cout << (ll)(A*B) << endl;
}


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

int a, b;
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> a >> b;
	if (a >= 6 && a <= 12) b /= 2;
	else if (a <= 5)b = 0;
	cout << b;
    return 0;
}


Measured memory_bytes: 256
object Main {
    def main(args: Array[String]): Unit = {
      val lines = io.Source.stdin.getLines().toSeq
      println(solve(lines))
    }

    def solve(lines: Seq[String]): String = {
      val Array(n, k) = lines.head.split(" ").map(_.toInt)
      val s = lines.tail.head.split("").filter(_.length > 0).take(n)
      debug(n, k, s)

      val str = s.map(v => v).toArray
      str(k - 1) = str(k - 1).toLowerCase()
      str.mkString("")
    }

    private def debug(x: Any): Unit = {
      if (System.getenv("LOCAL_DEBUG") != null) println(x)
    }
  }

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

int n, m, sum, nTime[110];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &nTime[i]);
        sum += nTime[i];
    }
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
    	int p, x;
        scanf("%d%d", &p, &x);
        printf("%d\n", sum - nTime[p] + x);
    }
    return 0;
}

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

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

	int a[100];
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	int minValue = INT32_MAX;
	int sum = 0;
	for (int j = -1000; j <= 1000; j++)
	{
		sum = 0;
		for (int i = 0; i < N; i++)
		{
			int x = a[i] - j;
			sum += x * x;
		}
		minValue = min(minValue, sum);
	}

	cout << minValue << endl;
	return 0;
}

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

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

    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];

    for(int i=a.size()-1; i>=0; --i) {
        cout << a[i];
        if (i != 0) cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3100
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		long ans=1;
		int flag=0;
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		for(int i=0;i<n;i++)
		{
			long a=in.nextLong();
			if(a==0)
			{
				flag=-1;
				ans=ans*a;
				break;
			}			
			if(ans>(long)1e18/a)
			{
				flag=1;
			}
			ans=ans*a;
		}
		if(flag==1)
		{
			ans=-1;
		}
		System.out.println(ans);
	}
}
	

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

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  
  long count=0;
  for (long i=0; i<S.size(); i++) {
    if (S[i]!=T[i]) {
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

    int N;
    string S;
    cin >> N >> S;
    vector<int> R, G, B;
    REP(i, N) {
        if (S[i] == 'R')
            R.emplace_back(i);
        else if (S[i] == 'G')
            G.emplace_back(i);
        else
            B.emplace_back(i);
    }
    ll r = R.size(), g = G.size(), b = B.size();
    ll res = r * g * b;

    REP(i, N - 2) {
        for (int j = 1; i + 2 * j < N; ++j) {
            if (S[i] != S[i + j] && S[i + j] != S[i + 2 * j] &&
                S[i + 2 * j] != S[i]) {
                --res;
            }
        }
    }
    cout << res << endl;

    return 0;
}


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

bool can[81][81][12801];
int a[81][81], b[81][81];

signed main () {
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j)
			cin >> a[i][j];
	}
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j)
			cin >> b[i][j];
	}
	can[1][1][abs(a[1][1] - b[1][1])] = 1;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			for (int k = 0; k <= 12800; ++k) {
				if (can[i][j][k]) {
					if (i != h) {
						can[i + 1][j][k + abs(a[i + 1][j] - b[i + 1][j])] = 1;
						can[i + 1][j][abs(k - abs(a[i + 1][j] - b[i + 1][j]))] = 1;
					}
					if (j != w) {
						can[i][j + 1][k + abs(a[i][j + 1] - b[i][j + 1])] = 1;
						can[i][j + 1][abs(k - abs(a[i][j + 1] - b[i][j + 1]))] = 1;
					}
				}
			}
		}
	}
	for (int k = 0; k <= 80; ++k) {
		if (can[h][w][k]) {
			cout << k << '\n';
			return 0;
		}
	}
}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int a[3];
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    
    sort(a, a + 3);
    cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO") << '\n';
    return 0;
}


Measured memory_bytes: 256
// Last Change: 02/24/2019 21:06:19.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  string S;
  cin >> S;
  int year, month, day;
  year = stoi(S.substr(0, 4));
  month = stoi(S.substr(5, 2));
  // day = stoi(S.substr(7, 2));

  string ans = "Heisei";
  if (year > 2019) {
    ans = "TBD";
  } else if (year == 2019) {
    if (month > 4) {
      ans = "TBD";
    }
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;
int n,m,x[N],a[N],p[N],s[N],cnt;
long long k;
int be[N],num[N],v[N];
vector<int>q[N];
void dfs(int x,int dep)
{
    num[x]=dep;v[x]=1;be[x]=cnt;
    q[cnt].push_back(x);
    if(!v[p[x]])dfs(p[x],dep+1);
}
signed main()
{
    memset(v,0,sizeof(v));
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<n;i++)s[i]=x[i+1]-x[i];
    cin>>m>>k;
    for(int i=1;i<n;i++)p[i]=i;
    for(int i=1;i<=m;i++){cin>>a[i];swap(p[a[i]],p[a[i]-1]);}
    for(int i=1;i<n;i++)if(!v[i])cnt++,dfs(i,0);
    cout<<x[1]<<endl;
    int now=x[1];
    for(int i=1;i<n;i++)
    {
        now+=s[q[be[i]][(num[i]+k)%q[be[i]].size()]];
        cout<<now<<endl;
    }
    return 0;
}

Measured memory_bytes: 13044
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
issafe = [1] * (n + 1)
for i in range(m):
    issafe[a[i]] = 0
mod = 10**9 + 7
dp = [0] * (n + 1)
dp[0] = 1
if issafe[1]:
    dp[1] = 1
for i in range(2, n + 1):
    if issafe[i - 1]:
        dp[i] += dp[i - 1]
    if issafe[i - 2]:
        dp[i] += dp[i - 2]
    dp[i] %= mod
print(dp[n])

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 998244353;

const int MAXN = 4e3 + 5;

char s[MAXN];
char mn[MAXN], mx[MAXN];
ll mn_val, mx_val;

ll dp[MAXN][MAXN];

int lower[MAXN], upper[MAXN];
int cnt_1;

int cnt[MAXN][2];
int n;

void process(char *res, int pref) {
	cnt_1 = 0;
	REP(i, 0, n) {
		cnt[i][0] = '2' - s[i];
		cnt[i][1] = 2 - cnt[i][0];
		cnt_1 += cnt[i][1];
		
		//printf("%d: %d %d\n", i, cnt[i][0], cnt[i][1]);
	}
	int top = 0;
	REP(i, 0, 2 * n) {
		if (cnt[0][pref] > 0) {
			res[top] = pref;
		} else {
			res[top] = pref ^ 1;
		}
		cnt[0][res[top]]--;
		top++;
		REP(j, 1, n) {
			if (cnt[j][pref] > 0) {
				cnt[j][pref]--;
				cnt[j - 1][pref]++;
			} else if (cnt[j][pref ^ 1] > 0) {
				cnt[j][pref ^ 1]--;
				cnt[j - 1][pref ^ 1]++;
			}
		}
		
		/*REP(j, 0, n) {
			printf("%d: %d %d\n", j, cnt[j][0], cnt[j][1]);
		}*/
	}
}

void solve(){
	scanf("%s", &s[0]);
	n = strlen(s);
	
	process(mn, 0);
	process(mx, 1);
	
	int offset_mn = 0, offset_mx = 0;
	REPN(i, 0, 2 * n) {
		lower[i] = INF;
		upper[i] = -1;
	}
	lower[0] = upper[0] = 0;
	REP(i, 0, 2 * n) {
		if (mn[i]) {
			offset_mn++;
		}
		if (mx[i]) {
			offset_mx++;
		}
		int ind_mn = i + 1 - offset_mn;
		int ind_mx = i + 1 - offset_mx;
		lower[ind_mn] = min(lower[ind_mn], offset_mn);
		upper[ind_mx] = max(upper[ind_mx], offset_mx);
	}
	
	int cnt_0 = 2 * n - cnt_1;
	REPN(i, 0, cnt_0) {
		REPN(j, 0, cnt_1) {
			if (lower[i] <= j && j <= upper[i]) {
				if (!i && !j) {
					dp[i][j] = 1;
				} else if (!i) {
					dp[i][j] = dp[i][j - 1];
				} else if (!j) {
					dp[i][j] = dp[i - 1][j];
				} else {
					dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
				}
			}
		}
	}
	
	printf("%lld\n", dp[cnt_0][cnt_1]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 123520
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <vector>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 40;

int sp[(1 << 24) + 5], pa[(1 << 24) + 5];

int encode(const int *arr) {
    int code = 0;
    for (int i = 0; i < 8; i++) {
        code <<= 3;
        code |= arr[i];
    }
    return code;
}

void decode(int *arr, int code) {
    for (int i = 7; i >= 0; i--) {
        arr[i] = code & 7;
        code >>= 3;
    }
}

queue<int> q;

void extend(const int *p, int step, int pre) {
    int code = encode(p);
    if (sp[code] != -1) return;
    sp[code] = step;
    pa[code] = pre;
    q.push(code);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int p[8] = {0, 1, 2, 3, 4, 5, 6, 7}, init = encode(p);
    memset(sp, -1, sizeof(sp));
    sp[init] = 0;
    q.push(init);
    while (!q.empty()) {
        int code = q.front(), step = sp[code] + 1;
        q.pop();
        decode(p, code);
        for (int i = 0; i < 8; i++) {
            if (p[i] != 0) continue;
            if (i % 4 != 3) {
                swap(p[i], p[i + 1]);
                extend(p, step, code);
                swap(p[i], p[i + 1]);
            }
            if (i % 4 != 0) {
                swap(p[i], p[i - 1]);
                extend(p, step, code);
                swap(p[i], p[i - 1]);
            }
            if (i < 4) {
                swap(p[i], p[i + 4]);
                extend(p, step, code);
                swap(p[i], p[i + 4]);
            }
            if (i >= 4) {
                swap(p[i], p[i - 4]);
                extend(p, step, code);
                swap(p[i], p[i - 4]);
            }
        }
    }

    while (cin >> p[0]) {
        for (int i = 1; i < 8; i++) cin >> p[i];
        cout << sp[encode(p)] << "\n";
    }
}



Measured memory_bytes: 92092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<int> x, y;

int main()
{
    int n, m, X, Y;
    cin>>n>>m>>X>>Y;
    REP(i,n) {
        int tmp;
        cin>>tmp;
        x.push_back(tmp);
    }
    REP(i,m) {
        int tmp;
        cin>>tmp;
        y.push_back(tmp);
    }
    SORT(x);
    SORT(y);
    if (x[n-1] >= X && Y >= y[0] && x[n-1] < y[0]) {
        cout<<"No War"<<endl;
    } else
        cout<<"War"<<endl;

    return 0;
}


Measured memory_bytes: 256
a,b,c,d = list(map(int,input().split()))

l_ab = []
l_cd = []
for i in range(a,b+1):
    l_ab.append(i)
for i in range(c,d+1):
    l_cd.append(i)


print(max(0,len(set(l_ab)&set(l_cd))-1))

Measured memory_bytes: 3060
s = input()
q = int(input())
count = 0
top = ""
end = ""
ans = s
for i in range(q):
    tmp = input()
    if tmp[0] == "1":
        count += 1
    else:
        _, f, c = map(str, tmp.split())
        if (count % 2 == 0 and f == "1") or (count % 2 == 1 and f == "2"):
            top = c + top
        else:
            end = end + c

ans = top + ans + end
ans = ans[::-1] if count % 2 == 1 else ans
print(ans)


Measured memory_bytes: 4384
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int target=0;
        int tmpNow;
        if(a==1) {
        	target=Math.abs(scanner.nextInt()-b);
        }else {
        	for(int i=0;i<a;i++) {
            	tmpNow=Math.abs(scanner.nextInt()-b);
            	if(i!=0) {
            		target=saidaikouyaku(target,tmpNow);
            	}else {
            		target=tmpNow;
            	}
            }
        }

        System.out.println(target);

    }

    public int saidaikouyaku(int x,int y) {
    	int tmp1;
    	int tmp2;
    	if(x>y) {
    		tmp1 = y;
    		tmp2 = x;
    	}else if(y>x){
    		tmp1 = x;
    		tmp2 = y;
    	}else {
    		return x;
    	}
    	int tmp3;
    	while ((tmp3 = tmp2 % tmp1) != 0) {
            tmp2 = tmp1;
            tmp1 = tmp3;
        }
    	return tmp1;
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 36692
def num(v):
	try:
		return int(v)
	except Exception:
		return v

ALL_calc = []
while True:
	N =  input().split(' ')
	if N[1] == '?':
		break
		
	N_calc = []
	for i in range(len(N)):
		N_calc.append(num(N[i]))
	ALL_calc.append(N_calc)
	
for i in range(len(ALL_calc)):
	if ALL_calc[i][1] == '+':
		print(ALL_calc[i][0] + ALL_calc[i][2])
	elif ALL_calc[i][1] == '-':
		print(ALL_calc[i][0] - ALL_calc[i][2])
	elif ALL_calc[i][1] == '*':
		print(ALL_calc[i][0] * ALL_calc[i][2])
	elif ALL_calc[i][1] == '/':
		print(ALL_calc[i][0] // ALL_calc[i][2])

Measured memory_bytes: 7788
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back

     
using namespace std;
using ll = long long;


ll MOD = 998244353;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = (node[i*2+1] + node[i*2+2]) % MOD;
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
            node[k] %= MOD;
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr) % MOD;
    }
};

using P = pair<ll, ll>;
int main(){
    ll n, k;
    cin >> n >> k;
    vector<P> p(k);
    rep(i, k){
        ll l, r;
        cin >> l >> r;
        p[i] = P(l, r);
    }
    
    LazySegmentTree seg(vector<ll> (n, 0));
    seg.add(0, 1, 1);
    rep(i, n){
        rep(j, k){
            ll now = seg.getsum(i, i + 1);
            seg.add(i + p[j].first, i + p[j].second + 1, now);
        }
    }
    //rep(i, n)cout << seg.getsum(i, i + 1) << endl;
    cout << seg.getsum(n - 1, n) << endl;
}





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

int main() {
  vector<int> vec(3);
  for (int i=0; i<3; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if(vec.at(0)==5 && vec.at(1)==5 && vec.at(2)==7){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
  return 0;
}
  
  
  

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

int N;
int T[1010];
int A[1010];

int main()
{
	cin >> N;
	for (int i = 0; i < N; ++i)
		cin >> T[i] >> A[i];
	ll t = 1, a = 1;
	for (int i = 0; i < N; ++i) {
		auto n = max((t + T[i] - 1) / T[i], (a + A[i] - 1) / A[i]);
		t = T[i] * n;
		a = A[i] * n;
	}
	cout << t + a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int ns[510][3];
int main()
{
    int n;
    int i,j;
    scanf("%d",&n);
    n--;
    for(i=0;i<n;i++)
        scanf("%d%d%d",&ns[i][0],&ns[i][1],&ns[i][2]);
    for(i=0;i<n;i++)
    {
        int ti=0;
        ti = ns[i][1]+ns[i][0];
        for(j=i+1;j<n;j++)
        {
            if(ti < ns[j][1])
                ti = ns[j][1];
            if(ti%ns[j][2] != 0)
            {
                ti += (ns[j][2]-ti%ns[j][2]);
            }
            ti += ns[j][0];
        }
        printf("%d\n",ti);
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256