akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string w;
  cin >> w;
  unordered_map<char, long> mp;
  for (char c: w) mp[c]++;
  for (auto it: mp) {
    if (it.second % 2) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  FIO        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  all(v)     v.begin(),v.end()
#define  rall(v)    v.rbegin(),v.rend()
#define  MEM(a,x)   memset(a,x,sizeof(a))
#define  pi         acos(-1.0)
#define  ll     long long
#define  pb     push_back
#define  mp     make_pair
#define  pii    pair< int,int >
#define  pll    pair< ll,ll >
#define  vii    vector< int >
#define  vll    vector< ll >
#define  vpi    vector< pii >
#define  vpl    vector<pll>
#define  MX     100005
#define  EPS    1e-12
#define  ss     second
#define  ff     first
int cases=1;
#ifdef ppqq
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<"  ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************
int main()
{
   //freopen ("output.txt","w",stdout);
   //freopen ("input.txt","r",stdin);
    FIO;
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=0;i<n-1;i++)
    {
        int x;
        cin>>x;
        m[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<m[i]<<endl;
    }
}


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

int main(){
	int n;
	while(cin >> n,n){
		int a[100],k;
		for(int i = 0;i < n;i++) cin >> a[i];
		cin >> k;
		int low = 0,up = n - 1,cnt = 0;
		while(1){
			cnt++;
			if(up == low) break;
			int mid = (up + low) / 2;
			if(a[mid] == k) break;
			if(a[mid] < k) low = mid + 1;
			else up = mid - 1;
			if(up < low) break;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main() {
	int n = in(), k = in();
	REP(i, pow(2, n)) {
		vector<int>elems;
		int i_copy = i;
		for (int j = 0; i_copy > 0; ++j) {
			if (i_copy % 2 == 1)elems.push_back(j);
			i_copy >>= 1;
		}
		if (elems.size() == k) {
			cout << i << ':';
			REP(j, k)cout << ' ' << elems[j];
			cout << endl;
		}
	}
}


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

int  main()
{
	int k,n;
	cin >>k >>n;
	if (500 * k >= n)
		cout << "Yes\n";
	else
		cout << "No\n";
	return (0);
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int p, int q) {
	while (q != 0) {
		int r = p % q;
		p = q;
		q = r;
	}
	return p;
}
int main(void) {
	int input =0;
	int num = 0;
	int output =0;

	scanf("%d", &input);
	for (int k = 1; k <= input; k++) {
		for (int i = 1; i <= input; i++) {
			for (int j = 1; j <= input; j++) {
				num = num + gcd(gcd(j, i), k);
			}
		}
	}

	output = num;
	printf("%d\n", output);
	return 0;
}

Measured memory_bytes: 1732
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lc (o << 1)
#define rc (o << 1 | 1)
#define mid ((l+r) >> 1)
#define int long long
using namespace std;

inline int read(){
	char ch = getchar(); int x = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9') { x = x*10 + ch-'0'; ch = getchar(); }
	return x;
}
const int maxn = 200009;
int L[maxn<<2], R[maxn<<2], lazyL[maxn<<2], lazyR[maxn<<2], x[maxn];
int n, Q, A, B, cost, ans = 1e18;

void build(int T[], int op, int o, int l, int r){
	if (l == r) { T[o] = abs(l-B) + op*l; return; }
	build(T, op, lc, l, mid); build(T, op, rc, mid+1, r);
	T[o] = min(T[lc], T[rc]);
}

void pushdown(int T[], int lazy[], int o){
	T[lc] += lazy[o]; lazy[lc] += lazy[o];
	T[rc] += lazy[o]; lazy[rc] += lazy[o];
	lazy[o] = 0;
}

void update(int T[], int lazy[], int o, int l, int r, int x, int y){
	if (l == r) { T[o] = min(T[o], y); return; }
	pushdown(T, lazy, o);
	if (x <= mid) update(T, lazy, lc, l, mid, x, y);
	else update(T, lazy, rc, mid+1, r, x, y);
	T[o] = min(T[lc], T[rc]);
}

int query(int T[], int lazy[], int o, int l, int r, int x, int y){
	if (l == x && y == r) return T[o];
	pushdown(T, lazy, o); int res = 1e18;
	if (x <= mid) res = min(res, query(T, lazy, lc, l, mid, x, min(mid, y)));
	if (mid+1 <= y) res = min(res, query(T, lazy, rc, mid+1, r, max(mid+1, x), y));
	return res;
}

signed main(){
	n = read(); Q = read();
	x[0] = A = read(); B = read();
	for (int i=1; i<=Q; i++) x[i] = read();
	build(L, -1, 1, 1, n); build(R, 1, 1, 1, n);
	for (int i=1; i<=Q; i++){
		cost = min(query(L, lazyL, 1, 1, n, 1, x[i]) + x[i],
				   query(R, lazyR, 1, 1, n, x[i], n) - x[i]);
		L[1] += abs(x[i]-x[i-1]); lazyL[1] += abs(x[i]-x[i-1]);
		R[1] += abs(x[i]-x[i-1]); lazyR[1] += abs(x[i]-x[i-1]);
		update(L, lazyL, 1, 1, n, x[i-1], cost-x[i-1]);
		update(R, lazyR, 1, 1, n, x[i-1], cost+x[i-1]);
	}
	for (int i=1; i<=n; i++)
		ans = min(ans, query(L, lazyL, 1, 1, n, i, i) + i);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 24704
o = input()
e = input()
if len(o) >  len(e):
    for i in range(len(e)):
        print(o[i], end = '')
        print(e[i], end = '')
    print(o[-1])
else:
    for i in range(len(o)):
        print(o[i], end = '')
        print(e[i], end = '')
    print()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_080
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nc = ReadInts();
            var stc = new int[nc[0]][];
            for (int i = 0; i < nc[0]; i++)
            {
                stc[i] = ReadInts();
            }
            Array.Sort(stc, (a, b) => a[0] - b[0]);
            var vList = new List<int[]>();
            for(int i = 0; i < stc.Length; i++)
            {
                bool canRec = false;
                for(int j = 0; j < vList.Count; j++)
                {
                    if ((vList[j][1]==stc[i][2]&&vList[j][0]==stc[i][0])
                        ||vList[j][0] < stc[i][0])
                    {
                        vList[j][0] = stc[i][1];
                        vList[j][1] = stc[i][2];
                        canRec = true;
                        break;
                    }
                }
                if (!canRec)
                {
                    vList.Add(new int[2] { stc[i][1], stc[i][2] });
                }
            }
            Console.WriteLine(vList.Count);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

namespace abc141_b
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToCharArray();
            string res = "Yes";

            for (int index = 0; index < s.Length; index++)
            {
                string target = s[index].ToString();

                if (index % 2 == 0)
                {
                    //kisu
                    if (target == "L")
                    {
                        res = "No";
                    }

                }
                else
                {
                    //gusu
                    if (target == "R")
                    {
                        res = "No";
                    }

                }


            }






            Console.WriteLine(res);
        }
    }
}


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

int main()
{
	int n;
	cin >> n;
	if ((n / 10 == 9) || ((n - (n / 10) * 10) == 9)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
    
int main()
{
    int K, A, B;
    cin >> K >> A >> B;

    int result = 0;
    int baisuu = 1;
    while(result < A) {
        result = K * baisuu;
        baisuu++;
    }

    if (A <= result && result <= B) {
        cout << "OK";
    } else {
        cout << "NG";
    }
}


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

using namespace std;

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, q;
long long D;
long long d[N], f[N], g[N];

bool read() {
    if (!(cin >> n >> D))
        return false;

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

    cin >> q;
    return true;
}

void solve() {
    f[0] = D;

    for (int i = 1; i < n; ++i)
        f[i] = min(f[i - 1], abs(f[i - 1] - d[i - 1]));

    g[n] = 1;

    for (int i = n - 1; i >= 0; --i)
        g[i] = (abs(g[i + 1] - d[i]) >= g[i + 1] ? g[i + 1] : d[i] + (2 * g[i + 1] < d[i] ? -1 : 1) * g[i + 1]);

    while (q --> 0) {
        int i;
        cin >> i;

        if (g[i] <= f[i - 1])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 13696
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int a[5];
    int b[5];
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<5;i++){
        b[i]=a[i];
    }
    for(int i=0;i<5;i++){
        while((a[i]%10)!=0){
            a[i]++;
        }
    }
    int min=100000;
    for(int i=0;i<5;i++){
        int sum=0;
        for(int j=0;j<5;j++){
            if(j==i){
                sum+=b[j];
            }else{
                sum+=a[j];
            }
        }
        if(min>sum){
            min=sum;
        }
    }
    printf("%d",min);
}



Measured memory_bytes: 1732
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int a,b;
    char s[15]={},t[15]={},u[15]={};
    scanf("%s %s %d %d %s",s,t,&a,&b,u);
    if(strcmp(s,u)==0){
        printf("%d %d",a-1,b);
        return 0;
    }
    printf("%d %d",a,b-1);
    return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val s = arrayOfNulls<List<Pair<Int, Int>>>(n)
    repeat(n) {
        val a = readLine()!!.toInt()
        val lst = mutableListOf<Pair<Int, Int>>()
        repeat(a) {
            val (x, y) = readLine()!!.split(' ').map { it.toInt() }
            lst.add(x-1 to y)
        }
        s[it] = lst
    }

    var ans = 0

    fun chk(onoff: String) {
        val oncnt = onoff.count { it == '1' }
        if (oncnt <= ans) return
        var success = true
        val state = IntArray(n) { -1 }
        var changed = true
        while (changed && success) {
            changed = false
            for (i in onoff.indices) {
                if (onoff[i] == '1' || state[i] == 1) {
                    state[i] = 1
                    val shogen = s[i]
                    shogen!!.forEach {
                        val target = it.first
                        if (state[target] == -1) {
                            state[target] = it.second
                            changed = true
                        } else {
                            success = success && (state[target] == it.second)
                        }
                    }
                }
            }
        }
        if (success) {
            ans = state.count { it == 1 }
        }
    }

    val max = Math.pow(2.0, n.toDouble()).toInt() -1
    for (i in 0..max) {
        val bStr = String.format("%${n}s", Integer.toBinaryString(i)).replace(" ", "0")
        chk(bStr)
    }

    println(ans)
}


Measured memory_bytes: 104884
N = int(input())
p_list = list(map(int, input().split()))
p_sorted = sorted(p_list)

count = 0
for p1, p2 in zip(p_list, p_sorted):
	if p1 != p2:
		count += 1
if count <= 2:
	print("YES")
else:
	print("NO")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,k[100005],rk[100005],p;
ll c[100005];
ll pw(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=res*x%M;
		x=x*x%M;
		y>>=1;
	}
	return res;
}
ll cm(ll x,ll y){
	return k[x]*rk[x-y]%M*rk[y]%M;
}
int main(void){
    cin>>n;
    n++;
    k[0]=1,rk[0]=1;
    for(ll i=1;i<=n;i++){
		k[i]=k[i-1]*i%M;
		rk[i]=pw(k[i],M-2);
	}
	for(ll i=1;i<=n;i++){
		ll a;
		cin>>a;
		if(c[a]!=0)p=c[a]-1+n-i;
		else c[a]=i;
	}
	for(ll i=1;i<=n;i++){
		ll s=cm(n,i);
		if(p>=i-1)s=(s+M-cm(p,i-1))%M;
		cout<<s<<endl;
	}
}


Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
using namespace std;
const int mod=1e9+7;
int n,m,k,dp[4444][4444],ans;
bool check(int nn,int mm)
{
	return (nn<=n && mm<=m && (n-nn)%(k-1)==0 && (m-mm)%(k-1)==0);
}
int main()
{
	cin>>n>>m>>k;
	dp[0][0]=1;
	for (int i=0;i<n+m;i+=(k-1))
	{
		for (int j=0;j<=m;j++)
		{
			for (int p=0;p<k;p++)
			{
				if (p && check(i-j+p,j+k-p)) ans=(ans+dp[i][j])%mod;
				if (i<n+m-1) dp[i+k-1][j+p]=(dp[i+k-1][j+p]+dp[i][j])%mod;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 69248
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		/*
		int d = 10;
		if(a[0]>d || a[1]>d || a[2]>d)puts("hogehogehoge");
		
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
			puts("YES");
		}else{
			puts("NO");
		}*/
		
		if(a[0]==3 && a[1]==4 && a[2]==5)puts("YES");
		else if(a[0]==6 && a[1]==8 && a[2]==10)puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a+b+c >= 22) {
    puts("bust");
  } else {
    puts("win");
  }
}


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



int main(){
    ll N;
    cin >> N;
    
    //ll sqrt_N = sqrt(N);
    
    vector<pair<ll,int>> fs;
    for(ll i=2; i*i <=N; i++){
        int x=0;
        while(N%i == 0){
            N /= i;
            x++;
        }
        fs.emplace_back(i,x);
    }
    if (N != 1) fs.emplace_back(N,1);
    
    int ans = 0;
    for(auto p :fs){
        int x = p.second;
        int b =1;
        while(b<=x){
            x -= b;
            b++;
            ans++;
        }
    }
    
    cout << ans << endl;
}


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

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

int main() {

    int n, m;
    cin >> n >> m;

    vector<vector<int>> tos(n);
    rep(i, m) {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        tos[from].push_back(to);
    }

    vector<double> expected_values(n);

    for (int from = n - 2; from >= 0; from--) {
        double expected_value = 0.0;
        for (int to : tos[from]) {
            expected_value += expected_values[to];
        }
        expected_value = expected_value / tos[from].size();
        expected_value++;
        expected_values[from] = expected_value;
    }

    double ans = expected_values[0];

    for (int from = 0; from < n - 1; from++) {
        if (tos[from].size() == 1) {
            continue;
        }
        int max_to = tos[from][0];
        double max_ev = expected_values[max_to];
        for (int to : tos[from]) {

            if (expected_values[to] > max_ev) {
                max_ev = expected_values[to];
                max_to = to;
            }
        }
        // from -> max_toの道を切ればいいことが分かる

        int cut_from = from, cut_to = max_to;

        double shortness = [&]() {
            vector<double> expected_values(n);
            for (int from = n - 2; from >= 0; from--) {
                double expected_value = 0.0;
                for (int to : tos[from]) {
                    if (from == cut_from && to == cut_to) {
                        continue;
                    }
                    expected_value += expected_values[to];
                }
                int size = tos[from].size();
                if (from == cut_from) {
                    size--;
                }
                expected_value = expected_value / size;
                expected_value++;
                expected_values[from] = expected_value;
            }
            return expected_values[0];
        }();

        ans = min(ans, shortness);
    }

    printf("%.10f\n", ans);

}



Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
using namespace std;
int v[100005];
int cmmdc(int a, int b) {
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main(){
  int n, k;
  scanf("%d%d", &n, &k);
  bool ok = 0;
  int c = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v[i]);
    if (v[i] == k) {
      printf("POSSIBLE\n");
      return 0;
    }
    c = cmmdc(v[i], c);
  }
  sort(v + 1, v + n + 1);
  if (v[n] < k) {
    printf("IMPOSSIBLE\n");
    return 0;
  }
  if (n == 1) {
    printf("IMPOSSIBLE\n");
    return 0;
  }
  if (k % c != 0) {
    printf("IMPOSSIBLE\n");
    return 0;
  }
  int dif = v[2] - v[1];
  if (dif != v[1]) {
    printf("POSSIBLE\n");
    return 0;
  }
  int aux = dif + dif;
  for (int i = 2; i <= n; ++i) {
    if (v[i] != aux) {
      printf("POSSIBLE\n");
      return 0;
    }
    aux += dif;
  }
  printf("IMPOSSIBLE\n");
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    double a,b,h,m; cin >> a >> b >> h >> m;
    double the = abs((h*60+m)*0.5 - m*6);
    if(the > 180) the = 360 - the;
    the = the / 180 * M_PI;
    double cc = a*a + b*b - 2*a*b*cos(the);
    cout << sqrt(cc) << endl;
    return 0;
}

Measured memory_bytes: 4216
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial,sqrt
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    h,w=MI()
    sx,sy=MI()
    gx,gy=MI()
    sy-=1
    sx-=1
    gy-=1
    gx-=1
    mp=[[0]*h for i in range(w)]
    Q=deque([[sy,sx]])
    for i in range(h):
        s=SI()
        for j in range(w):
            if s[j]=="#":
                mp[j][i]=1
    #print(mp)
    turn=[[inf]*h for i in range(w)]
    turn[sy][sx]=0
    #print(turn)
    step=[[-1,0],[1,0],[0,1],[0,-1]]
    
    while Q:
        y,x=Q.popleft()
        z=turn[y][x]
        if y==gy and x==gx:
            print(turn[y][x])
            sys.exit()
        for j,i in step:
            if not (0<=y+j<w and 0<=x+i<h):
                continue
            elif mp[y+j][x+i]==1:
                continue
            else:
                if z<turn[y+j][x+i]:
                    turn[y+j][x+i]=z
                    Q.appendleft([y+j,x+i])
        #print(turn)
        for i in range(-2,3):
            for j in range(-2,3):
                if not (0<=y+j<w and 0<=x+i<h):
                    continue
                elif mp[y+j][x+i]==1:
                    continue
                else:
                    if z+1<turn[y+j][x+i]:
                        turn[y+j][x+i]=z+1
                        Q.append([y+j,x+i])
        #print(turn)
    #print(turn)
    print(-1)
        
                
                
        
        
        
        
            
            
    
if __name__=="__main__":
    main()



Measured memory_bytes: 118596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan_init()
	n := scanInt()
	x := scanInt()
	t := scanInt()
	time := n/x
	if n %x != 0 {
		time += 1
	}
	fmt.Println(time*t)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 1788
lis = list(map(int,input().split()))

ans_num = -10000000000000000001

if lis[0] * lis[2] >= ans_num:
    ans_num = lis[0] * lis[2]
if lis[0] * lis[3] >= ans_num:
    ans_num = lis[0] * lis[3]
if lis[1] * lis[2] >= ans_num:
    ans_num = lis[1] * lis[2]
if lis[1] * lis[3] >= ans_num:
    ans_num = lis[1] * lis[3]

print(ans_num)

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

using namespace std;

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

    int n;cin>>n;
    vector<string> u(n);
    for(int i=0;i<n;i++) cin>>u[i];
    int m;cin>>m;
    int locked=1;
    for(int i=0;i<m;i++){
        string t;cin>>t;
        for(int j=0;j<n;j++){
            if(u[j]==t){
                if(locked) cout<<"Opened by "<<t<<endl;
                else cout<<"Closed by "<<t<<endl;
                locked=1-locked;
                goto done;
            }
        }
        cout<<"Unknown "<<t<<endl;
        done: continue;
    }
}

Measured memory_bytes: 3240
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] xyz = br.readLine().split(" ");
        int x = Integer.parseInt(xyz[0]);
        int y = Integer.parseInt(xyz[1]);
        int z = Integer.parseInt(xyz[2]);
        int a = x * 10 + y + z;
        int b = x + y * 10 + z;
        int c = x + y + z * 10;
        if (a >= b && a >= c) {
            System.out.println(a);
        }
        else if ( b >= a && b >= c) {
            System.out.println(b);
        }
        else {
            System.out.println(c);
        }
    }
}

Measured memory_bytes: 22996
n = eval(input())
R = [None]*n
for i in range(n):
    R[i] = eval(input())
maxv = -2e9
minv = R[0]
for i in range(1,n):
    maxv = max(maxv, R[i] - minv)
    minv = min(minv, R[i])
print(maxv)


Measured memory_bytes: 13292
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b,c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  bool flag = false;
  int diff = e-a;
  if (diff <= k) {
    flag = true;
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}

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

int main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  rep(a, A)
  {
    rep(b, B)
    {
      rep(c, C){
        int sum = 500*a + 100*b + 50*c;
        if(sum == X) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;
int x,y,a,b,c;
int p[maxn],q[maxn],d[maxn];
inline bool cmp(int a,int b){return b<a;}
int main(){
	scanf("%d %d %d %d %d",&x,&y,&a,&b,&c);
	int tempx = x,tempy = y;
	for(int i=1;i<=a;++i)scanf("%d",&p[i]);
	for(int i=1;i<=b;++i)scanf("%d",&q[i]);
	for(int i=1;i<=c;++i)scanf("%d",&d[i]);
	std :: sort(p+1,p+a+1,cmp);
	std :: sort(q+1,q+b+1,cmp);
	std :: sort(d+1,d+c+1,cmp);
	int P,Q,D;
	long long ans = 0,cnt = 0;
	P = Q = D = 1;
	for(int i=1;i<=x+y;++i){
		if(p[P] >= q[Q] && p[P] >= D[d] ){
			ans += p[P],++P,--tempx;
			if(!tempx)p[P] = 0;
		}
		else if(p[P] <= q[Q] && q[Q] >= D[d] && tempy){
			ans += q[Q],++Q,--tempy;
			if(!tempy)q[Q] = 0;
		}
		else ans += d[D],++D,++cnt;
	}
	printf("%lld",ans);
	return 0;
}



Measured memory_bytes: 1408
// 2013/09/17 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int G[7][2] =	{{2, 3},
			 {3, 2},
			 {6, 4},
			 {2, 6},
			 {5, 1},
			 {1, 3},
			 {6, 6}};

	while(true){
		string S;
		cin >> S;

		if(S=="#")
			break;

		int c = 0;

		for(int i=0; i<S.size(); i++){
			c = G[c][S[i]-'0'];
		}

		if(c==1){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
int N;
ll L;
ll solve(vector<ll> x, vector<ll> v){
	ll res = 0;
	ll mx = 0;
	ll smv = 0;
	ll V = 0;
	rep(i,N) V += v[i];
	for(int i=N-2;i>=-1;i--){
		smv += v[i+1];
		chmax(mx,smv-(L-x[i+1]));
		chmax(res,(V-smv)-(i==-1?0:x[i])*2+mx);
	}
	return res;
}

int main(){
	cin>>N>>L;
	vector<ll> x(N),v(N);

	rep(i,N) cin>>x[i]>>v[i];
	ll ans = 0;
	rep(t,2){
		chmax(ans,solve(x,v));
		reverse(all(v));
		rep(i,N) x[i] = L-x[i];
		reverse(all(x));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3424
w, h, n = map(int, input().split())
T = [list(map(int, input().split())) for i in range(n)]

xr = w
xl = 0
yu = h
yl = 0

for i in range(n):
    if T[i][2] == 2:
        xr = min(xr, T[i][0])
    elif T[i][2] == 1:
        xl = max(xl, T[i][0])
    elif T[i][2] == 4:
        yu = min(yu, T[i][1])
    else:
        yl = max(yl, T[i][1])

if (xr - xl) <= 0 or (yu - yl) <= 0:
    print(0)
else:
    print((xr - xl) * (yu - yl))

Measured memory_bytes: 3064
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int n;

  while ( scanf ( "%d", &n ) == 1 )
  {
    int a, b, c, d;
    int res = 0;

    for ( a = 0; a <= 9; ++a )
    for ( b = 0; b <= 9; ++b )
    for ( c = 0; c <= 9; ++c )
    {
      d = n - a - b - c;

      res += ( d >= 0 && d <= 9 );
    }

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

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
const int maxn = 1e5 + 50;
int a[maxn];
int n, k, q;
int main()
{
    cin>>n>>k>>q;
    for(int i = 1; i <= n; ++i) a[i] = k-q;
    while(q--){
        int x;scanf("%d", &x);
        a[x]++;
    }
    for(int i = 1; i <= n; ++i){
        if(a[i] <= 0) printf("No\n");
        else printf("Yes\n");
    }
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> Asorted = A;
    sort(all(Asorted));

    int eoinv = 0;
    for (int i = 0; i < N; i += 2) {
        int k = lower_bound(all(Asorted), A[i]) - Asorted.begin();
        if (k % 2 == 1) {
            eoinv++;
        }
    }

    write(eoinv);
}

Measured memory_bytes: 1024
//#############################################################################
#include "bits/stdc++.h"
//#############################################################################
//Macros 
#define MOD 1000000007
#define eb emplace_back
#define mp make_pair
#define fr first
#define sc second
#define vec vector
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define sum(v) accumulate(all(v),0LL)
//Type Defs
typedef long long ll;
typedef unsigned long long ull;
//#############################################################################
using namespace std;
//#############################################################################
//Helpers
void io_handler()
{
#ifdef LOCAL_TESTING
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
template <typename T>
void print_matrix(vector<vector<T>> mat){
    for(auto row: mat){
        for(auto e : row){cout << e << " ";}
        cout << endl;
    }
}
template <typename T>
void print_vector(vector<T> v){
    for(auto e : v){cout<< e <<" ";}
    cout<<endl;
}
template <typename T>
map<T,T> get_count(vector<T> v){
    map<T,T> count;
    for(auto e: v){
        if(count.find(e)!=count.end()){count[e]++;}
        else{count[e] = 1;}}
    return count;
}
inline ll sub_sum(vec<ll> pre,ll left,ll right){
    return pre[right]-(left>0?pre[left-1]:0LL);
}
//#############################################################################
//Solution
void solve(){
    ll n; cin>>n;
    vec<ll> score(n);
    ll total = 0LL;
    vec<vec<ll>> dp(n,vec<ll>(n,0));
    for(ll i = 0LL; i<n; i++){
        cin>>score[i];
        total += score[i];
        dp[i][i] = score[i];
    }
    vec<ll> pre(n,0LL); pre[0] = score[0];
    for(ll i =1LL; i<n; i++){
        pre[i] = score[i]+pre[i-1];
    }
    //DP on intervals 
    /*
        dp[left][right] = Max score Taro can have with subarray [left,right]
    */
    for(ll ln = 2; ln<n+1; ln++){
        for(ll left = 0LL; left<n-ln+1; left++){
            ll right = left+ln-1;
            dp[left][right] = max(
            score[left] + (pre[right]-(left+1>0?pre[left]:0LL)-dp[left+1][right]),
            score[right] + (pre[right-1]-(left>0?pre[left-1]:0LL)-dp[left][right-1])
            );
        }
    }
    ll ans = dp[0][n-1]-(total-dp[0][n-1]);
    cout<<ans<<endl;
}
//#############################################################################
//Driver
int main()
{
    io_handler();
    int t = 1;
    //cin>>t;
    for (int i = 0; i < t; i++){
        solve();
    }
#ifdef LOCAL_TESTING
    cout << "⏰ Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
//#############################################################################


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
bool hanbetu(string a){
    int n = a.size();
    if(n % 2 == 0){
        string A = a.substr(0,n/2);
        string B = a.substr(n/2,n/2);
        if(A == B) return 1;
    }
    return 0;
}

int main(){
    string s;
    cin >> s;
    while(1){
        s.pop_back();
        if(hanbetu(s)) break;
    }
    cout << s.size() << endl;
    
}

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

int main(){
    int n;
    string s;

    cin >> n;
    cin >> s;

    int s1[n];
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            s1[i] = 1;
        }else{
            s1[i] = 0;
        }
    }

    vector<int> sum(n+1,0);
    for(int i=0;i<n;i++){
        sum[i+1] = sum[i] + s1[i];
    }


    vector<int> people(n,0);
    for(int k=0;k<n;k++){
        people[k] = sum[k] + ( (n-1-k) - (sum[n]-sum[k+1]) ) ;
    }

    int min = people[0];
    for(int k=0;k<n;k++){
        if(min>=people[k]){
            min = people[k];
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 4228
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int N;
    cin >> N;

    const int MOD = 1e9 + 7;
    ll ans = 1;
    int free = 0;
    rep(i, N) {
        int x;
        cin >> x;
        if (x < 2 * free + 1) {
            ans *= free + 1;
            ans %= MOD;
        } else {
            free++;
        }
    }
    while (free > 1) {
        (ans *= free--) %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    int n;
    cin >> n;
    cout << (n>=1000? "ABD":"ABC") << endl;  
    return 0;
}

Measured memory_bytes: 256
using System;


class NumberTheory {
    bool isFact;
    long[] fact;
    public NumberTheory(){
        isFact = false;
    }
    
    public void FactTable(long n, long m){
        isFact = true;
        fact = new long[n+1];
        fact[0] = 1;
        for(long i=1;i<n+1;i++){
            fact[i] = (fact[i-1]*i)%m;
        }
    }
    
    public long GetFact(long n){
        if(isFact && -1<n && n<=fact.Length){
            return fact[n];
        } else {
            return -1;
        }
    }
    
    public long Mod_fact(long n, long p, out long e){
        e = 0;
        if(!isFact){
            Console.WriteLine("Error:FactTable is not created!!");
            return -1;
        }
        if(n==0) return 1;
        long res = Mod_fact(n/p,p, out e);
        e += n/p;
        
        if(n/p%2!=0) return res * (p-fact[n%p])%p;
        return res*fact[n%p]%p;
    }
    
    public long Mod_cmb(long n, long k, long p){
        if(n<0||k<0||n<k) return 0;
        long e1,e2,e3;
        long a1 = Mod_fact(n,p, out e1),a2 = Mod_fact(k,p, out e2),a3 = Mod_fact(n-k,p, out e3);
        if(e1>e2+e3) return 0;
        return a1 * Mod_inverse(a2*a3%p, p)%p;
    }
    
    public long Extgcd(long a, long b, out long x, out long y){
        long d = a;
        if(b!=0){
            d = Extgcd(b,a%b, out y, out x);
            y -= (a/b)*x;
        } else {
            x = 1; y = 0;
        }
        return d;
    }
    
    public long Mod_inverse(long a, long m){
        long x,y;
        Extgcd(a,m, out x, out y);
        return (m+x%m)%m;
    }
    
}

public class Program{
    static void Main(string[] args){
        long N = 1000000007;
        NumberTheory nt = new  NumberTheory();
        string[]  str = Console.ReadLine().Split(' ');
        long H = long.Parse(str[0]);
        long W = long.Parse(str[1]);
        nt.FactTable(H+W,N);
        long A = long.Parse(str[2]);
        long B = long.Parse(str[3]);
        long ans = 0;
        for(int i=1;i<H-A+1;i++){
            ans +=  nt.Mod_cmb(B+i-2,i-1,N) * nt.Mod_cmb(H+W-i-B-1,H-i,N) % N;
            ans = ans % N;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int a,b,c;
cin >> a >> b >> c;
vector<int>aa(3);
aa.at(0)=a;
aa.at(1)=b;
aa.at(2)=c;
sort(aa.begin(),aa.end());
if(aa.at(1)==c)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
 


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


Measured memory_bytes: 128
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int L[100000], R[100000]; // [L,R)
pair<int, int> sec[100000];
vector<pair<int, int>> v;

signed main(){
    cin >> N;
    rep(i, N){
        cin >> L[i] >> R[i];
        L[i]--;
        sec[i] ={ L[i],-R[i] };
    }
    sort(sec, sec+N);

    rep(i, N){
        while(v.size() > 0 && v.back().second >= -sec[i].second){
            v.pop_back();
        }
        v.pb({ sec[i].first,-sec[i].second });
    }

    if(v.size() == 1){
        int ans = 0;
        rep(i, N-1){
            ans = max(ans, -sec[i].second - sec[i].first);
        }
        cout << ans + -sec[N-1].second - sec[N-1].first << endl;
        exit(0);
    }

    int ans = 0;
    for(int i=1; i<v.size(); i++){
        ans = max(ans, max(0, v[0].second-v[i-1].first) + max(0, v[i].second-v[v.size()-1].first));
    }
    set<pair<int,int>> l, r;
    rep(i, N){
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    rep(i, N){
        l.erase({ L[i],i });
        r.erase({ R[i],i });
        ans = max(ans, R[i]-L[i] + max(0, r.begin()->first-prev(l.end())->first));
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    cout << ans << endl;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
const int maxn=100050;
int n,a[maxn];
int tot=0,ans=0;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		if(a[i]==i)
			tot++;
		if(a[i]!=i) {
			ans+=(tot+1)/2;
			tot=0;
		}
	}
	ans+=(tot+1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>

constexpr int STR_MAX_LEN = 1000;

int main(){
    char s1[STR_MAX_LEN], s2[STR_MAX_LEN];
    int dp[STR_MAX_LEN + 1][STR_MAX_LEN + 1];
    scanf("%s%s", s1, s2);
    int s1_len = strlen(s1), s2_len = strlen(s2);
    
    for(int i = 1; i <= s1_len; ++i){
        dp[i][0] = i;
    }
    for(int i = 1; i <= s2_len; ++i){
        dp[0][i] = i;
    }

    for(int i = 1; i <= s1_len; ++i){
        for(int j = 1; j <= s2_len; ++j){
            if(s1[i - 1] == s2[j - 1]){
                dp[i][j] = dp[i - 1][j - 1];
            }
            else{
                dp[i][j] = std::min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1});
            }
        }
    }
    printf("%d\n", dp[s1_len][s2_len]);
    return 0;
}

Measured memory_bytes: 6648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String alphabet = "abcdefghijklmnopqrstuvwxyz";
        for (int i = 0 ; i < s.length() ; i++) {
            char c = s.charAt(i);
            alphabet = alphabet.replace(String.valueOf(c), "");
        }
        if (alphabet.length() == 0) {
            System.out.println("None");
        } else {
            System.out.println(alphabet.charAt(0));
        }
    }

}

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

int main() {
	int n;
	cin >> n;
	double sum = 0, x;
	string u;
	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u == "BTC") {
			x *= 380000;
		}
		sum += x;
	}
	cout << sum << endl;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int s=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    float v=0.25/m;
    //cout<<v;
    int y=0;
     for(int i=0;i<n;i++){
         if(a[i]>=v*s){
             y++;
         }
     }
    if(y>=m)
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

double dp[20][10];
int n,s,t,b;

int move(int pos,int x,int y){
	if(pos<3&&y==-1)return pos;
	if(pos>=6&&y==1)return pos;
	if(pos%3==0&&x==-1)return pos;
	if(pos%3==2&&x==1)return pos;
	pos+=x+3*y;
	if(pos==b)return pos-x-3*y;
	return pos;
}

int main() {
	string ss,tt,bb;
	while(n=in()){
		cin>>ss>>tt>>bb;
		s=ss[0]-'A';
		t=tt[0]-'A';
		b=bb[0]-'A';
		memset(dp,0,sizeof(dp));
		dp[0][s]=1;
		int i,j;
		for(i=1;i<=n;i++){
			for(j=0;j<9;j++){
				dp[i][move(j,1,0)]+=dp[i-1][j]/4;
				dp[i][move(j,-1,0)]+=dp[i-1][j]/4;
				dp[i][move(j,0,1)]+=dp[i-1][j]/4;
				dp[i][move(j,0,-1)]+=dp[i-1][j]/4;
			}
		}
		printf("%.12f\n",dp[n][t]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void)
{
	int a, b, c;
	int d, e, f;
	int min;
	
	scanf("%d %d %d", &a, &b, &c);
	
	d = a + b;
	e = a + c;
	f = b + c;
	min = d;
	
	if(e <= min)
		min = e;
	if(f <= min)
		min = f;
	
	printf("%d", min);
	
	return 0;
}

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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
//#define TRACE(x) cerr << #x << " " << x << endl
#define TRACE(x)
#define eb emplace_back
#define _ << " " <<
typedef long long ll;
typedef std::pair<int, int> ii;
#define X first
#define Y second
#define double long double
typedef double db;
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;


ll aSeqStays(ll A, ll Q, ll R, ll G, ll B) { // A + kG stays in [Q, R] mod B
  TRACE(A _ Q _ R _ G _ B);
  ll P = R - Q;
  A = (A - Q + B) % B;
  if (A > P) return 0; // awful practice

  return ( (P-A) / G == (B - A - 1) / G );
}

bool solve(ll A, ll B, ll C, ll D) {
  if (A < B) return 0;

  if (C >= B - 1 && D >= B) return 1;

  ll Q = max((ll)0, (D < B) ? ((B - D) % B + B) % B : (ll)0);
  ll R = min((ll)C, (ll)B - 1);

  TRACE(Q _ R);
  if (Q > R) return 0;
  
  ll G = __gcd(D, B);

  return aSeqStays(A % B, Q, R, G, B);
}

void load() {
  int N;
  cin>>N;
  ll A,B,C,D;
  REP(i, N){
    cin>>A>>B>>C>>D;
    cout << (solve(A,B,C,D) ? "Yes" : "No") << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  load();	
  return 0;
}



Measured memory_bytes: 256