akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
#define bs bitset<5001>

int kai_size = 1000001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
signed main() {
	int n; cin >> n;
	vel a(n);
	rep(i, n) { cin >> a[i]; }
	veb use(n, false); int m = 0;
	for (int i = n; i >= 1; i--) {
		int want = a[i - 1];
		int ko = 0;
		for (int j = 2*i; j <= n; j+=i) {
			if (use[j-1]) { ko++; }
		}
		if (ko % 2 != want) {
			use[i-1] = true; m++;
		}
	}
	cout << m << endl;
	rep(i, n) {
		if (use[i]) { cout << i + 1 << endl; }
	}
	return 0;
}

Measured memory_bytes: 19200
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i;
    cin>>n;
    int dp[n][3],a,b,c;
    cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
    for(i=1;i<n;++i)
    {
        cin>>a>>b>>c;
        dp[i][0] = a + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c + max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    return 0;
}

Measured memory_bytes: 1408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>


using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

class ATaskSchedulingProblem {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a,b,c;
    int ans = 0;
    //string ans = "";
    cin >> a >> b >>c;
    vector<int> v;
    v.push_back(abs(a-b));
    v.push_back(abs(a-c));
    v.push_back(abs(b-c));
    sort(v.begin(), v.end());
    ans = v.at(0) + v.at(1);
    cout << ans << endl;
}
};


int main() {
	ATaskSchedulingProblem solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    if(a==b)cout<<c;
    else if(a==c)cout<<b;
    else cout<<a;
    return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable._
import io.StdIn.readLine

object Main extends App {
  val map = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val maxL = s.map(e => (e.length, e)).max._2

  println(maxF + " " + maxL)
}


Measured memory_bytes: 43620
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 10000001; 
  
// array to store prime factors 
int factor[MAX] = { 0 }; 
  
// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 	
 
 
int main()
{ 
    ll t;
    t=1;
    while(t--)
    {
       ll n;
       cin>>n;
       ll sum=0;
       generatePrimeFactors();
       for(ll i=1;i<=n;i++)
       {
           sum  = sum + (i*(calculateNoOFactors(i)));
       }
       cout<<sum<<endl;
    }
           
        
 return 0;
}

Measured memory_bytes: 42652
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
 
template <class T>
std::vector<T> ToFixedArray(std::istream& is, int n) {
	std::vector<T> ret(n);
	auto* dst = ret.data();
	while(n-- > 0)
		is >> *dst++;
	return ret;
}
 
#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)
 
void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}
using Dist_t = uint64_t;
constexpr auto DistMax = std::numeric_limits<Dist_t>::max()/2;
using DistV = std::vector<Dist_t>;
int main() {
	DisableIOSync();

	using std::cin;
	using namespace std;
	int NCity, NLink, NDest;
	cin >> NCity >> NLink >> NDest;

	auto dest = ToFixedArray<int>(std::cin, NDest);
	for(auto& d : dest)
		--d;

	using DistV = std::vector<Dist_t>;
	DistV dist(NCity * NCity, DistMax);
	const auto fdist = [&dist, NCity](const int from, const int to) -> decltype(auto) {
		return dist[from + to*NCity];
	};
	For(i, 0, NCity) {
		fdist(i,i) = 0;
	}
	For(i, 0, NLink) {
		int id0, id1, cost;
		cin >> id0 >> id1 >> cost;
		--id0;
		--id1;
		fdist(id0, id1) = cost;
		fdist(id1, id0) = cost;
	}
	For(inter, 0, NCity) {
		For(from, 0, NCity) {
			For(to, 0, NCity) {
				fdist(from, to) =
					std::min(
						fdist(from, to),
						fdist(from, inter) + fdist(inter, to)
					);
			}
		}
	}
	Dist_t res = DistMax;
	std::sort(dest.begin(), dest.end());
	do {
		Dist_t sum = 0;
		For(i, 1, NDest) {
			sum += fdist(dest[i-1], dest[i]);
		}
		res = std::min(res, sum);
	} while(std::next_permutation(dest.begin(), dest.end()));
	std::cout << res << std::endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<ll> a(n);
	ll c = 0;
	map<ll, ll> count, ans;
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		count[a[i]]++;
	}
	ll ct = 0;
	for(auto i: count)
	{
		if(i.second>=2)
			ct+=(i.second)*(i.second-1)/2;
	}
	for(int i = 0; i < n; i++)
	{
		c = 0;
		if(count[a[i]] < 2)
			c = ct;
		else 
			c = ct - (count[a[i]])*(count[a[i]]-1)/2 + (count[a[i]]-1)*(count[a[i]]-2)/2;
		cout<<c<<"\n";
	}

}

Measured memory_bytes: 11136
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI = 3.1415926535897932384626;

template<typename T> T power(T x, T y, ll m = mod) {T ans = 1; while (y > 0) {if (y & 1LL) ans = (ans * x) % m; y >>= 1LL; x = (x * x) % m;} return ans % m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM =
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

ll val[1000006];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (ll gg = k; gg >= 1; gg--)
	{
		ll boi = power(k / gg, n);
		for (ll gg1 = 2 * gg; gg1 <= k ; gg1 += gg)
		{
			ll boi1 = val[gg1];
			if (boi1 == 0)
				break;
			boi = (boi - boi1 + mod) % mod;
		}
		val[gg] = boi;
		ll weary = (gg % mod * boi % mod) % mod;
		ans += weary;
		ans %= mod;
	}
	cout << ans;
	return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 4380
l = input()
arr = l.split(' ')
arr = [int(e) for e in arr]

if 1 <= arr[0] <= 100 and 1 <= arr[1] <= 100 and 1 <= arr[2] <= 100:
  if arr[0] == arr[1] + arr[2]:
    print('Yes')
  elif arr[1] == arr[2] + arr[0]:
    print('Yes')
  elif arr[2] == arr[0] + arr[1]:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<bits/stdc++.h>

#define ll long long int
using namespace std;
int main() 
{
	ll n;
	scanf("%lld",&n);
	ll a[n],b[n],c[n],i;
	
	for(i=0;i<n;i++)
	scanf("%lld",&a[i]);
	
	for(i=0;i<n;i++)
	scanf("%lld",&b[i]);
	
	for(i=0;i<n;i++)
	scanf("%lld",&c[i]);
	
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	
	ll ans=0;
	ll bans[n];
	for(i=0;i<n;i++)
	{
	    long long int* ic=lower_bound(c,c+n,b[i]+1);
	    ll use=n-(ic-c);
	    bans[i]=use;
	}
	
	ll f[n+1];
	f[n]=0;
	f[n-1]=bans[n-1];
	for(i=n-2;i>=0;i--)
	{
	    f[i]=bans[i]+f[i+1];
	}
	
	for(i=0;i<n;i++)
	{
	    ll vala=a[i];
	    long long int* indexb=lower_bound(b,b+n,vala+1);
	    ll usable2=f[indexb-b];
	    ans=ans+usable2;
	}
	printf("%lld\n",ans);
	return 0;
}


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

long long int N;

struct StrangeBank{
    int val[101010];
    int c[12] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

    constexpr StrangeBank() : val(){
        val[0] = 0;
        for(int i = 1, j = 1; i < 101010; ++i){
            val[i] = 9999999;
            while(j < 12 && c[j] <= i)++j;
            for(int k = 0; k < j; ++k){
                val[i] = min(val[i], val[i - c[k]] + 1);
            }
        }
    }
};

/*constexpr*/ StrangeBank sb = StrangeBank();

int main(){
    scanf("%lld", &N);
    cout << sb.val[N] << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a, b;
    scan(a, b);

    int ans;

    foreach (i ; a .. b + 1) {
        auto s = i.to!string;
        if (equal(s, s.retro)) ans++;
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 1276
#include <stdio.h>

int main() {

  int h, w;
  int i, j;

  while(1) {
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0)
      break;
    else {
      for(i = 0; i < h; i++) {
	for(j = 0; j < w; j++) {
	  if(i == 0 || j == 0 || i == h-1 || j == w-1)
	    printf("#");
	  else
	    printf(".");
	}
	printf("\n");
      }
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 572
#include <cstdio>
#include <cstring>
 
using namespace std;
 
int main(void){
    int n, id, value, num, buf[4000], bufnum, i, j;
    long long int yen[4000];
    bool f;
    while(1){
        scanf("%d",&n);
        if(n == 0){
            break;
        }
        memset(yen,0ll,sizeof(yen));
        bufnum = 0;
        for(i = 0;i < n;i++){
            scanf("%d%d%d",&id,&value,&num);
            for(j = 0;j < bufnum;j++){
                if(buf[j] == id){
                    break;
                }
            }
            if(j == bufnum){
                buf[bufnum++] = id;
            }
            yen[id - 1] += (long long int)value * num;
        }
        f = true;
        for(i = 0;i < bufnum;i++){
            if(yen[buf[i] - 1] >= 1000000ll){
                printf("%d\n",buf[i]);
                f = false;
            }
        }
        if(f){
            printf("NA\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1088
import sys
import collections
import heapq
input = sys.stdin.readline


# 操作の回数 n を a, b, cd の３つに分割する
def f(n):
    a = []
    for i in range(n+1):
        for j in range(i, n+1):
            a.append((i, j-i, n-j))
    return(a)


def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for a, b, cd in f(K):
        H = []
        D = collections.deque(V)
        for i in range(a):
            if not D:
                break
            heapq.heappush(H, D.popleft())
        for i in range(b):
            if not D:
                break
            heapq.heappush(H, D.pop())
        for i in range(cd):
            if not H or H[0] >= 0:
                break
            heapq.heappop(H)
        ans = max(ans, sum(H))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int N, M, R, r[10]; cin >> N >> M >> R;
	for(int i=0; i<R; ++i) cin >> r[i];
	vector<vector<pair<int, int>>> v(N+1);
	for(int i=0; i<M; ++i){
	    int A, B, C; cin >> A >> B >> C;
	    v[A].push_back(make_pair(C, B));
	    v[B].push_back(make_pair(C, A));
	}
	map<int, map<int, int>> mp;
	for(int i=0; i<R; ++i){
	    for(int p=0; p<=N; ++p) mp[r[i]][p]=1e9;
	    vector<bool> dec(N+1, true);
	    mp[r[i]][r[i]]=0;
	    dec[r[i]]=false;
	    int se=r[i];
	    for(int t=1; t<N; ++t){
	        for(int p=0; p<v[se].size(); ++p){
	            if(dec[v[se][p].second]){
	                mp[r[i]][v[se][p].second]=min(mp[r[i]][v[se][p].second], mp[r[i]][se]+v[se][p].first);
	            }
	        }
	        se=0;
	        for(int k=1; k<=N; ++k) if(dec[k] && mp[r[i]][se]>mp[r[i]][k]) se=k;
	        dec[se]=false;
	    }
	}
	vector<int> perm;
	for(int i=0; i<R; ++i) perm.push_back(i);
	int ans=1e9;
	do{
	    int now=0;
	    for(int i=1; i<R; ++i) now += mp[r[perm[i]]][r[perm[i-1]]];
	    ans=min(ans, now);
	}while(next_permutation(perm.begin(), perm.end()));
	cout << ans << endl;
	return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int h = ri();
	int w = ri();
	int len = ri();
	std::string s[h];
	for (auto &i : s) std::cin >> i;
	
	int res = -1;
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
		int cur = 0;
		int times = 1;
		std::string board[h];
		for (int k = 0; k < h; k++) board[k] = s[k];
		bool first = true;
		while (1) {
			bool drop[h][w];
			memset(drop, 0, sizeof(drop));
			for (int k = 0; k < h; k++) for (int l = 0; l <= w - len; l++) {
				bool ok = board[k][l] != '*';
				for (int m = 0; m + 1 < len; m++) if (board[k][l + m] != board[k][l + m + 1]) ok = false;
				if (ok) for (int m = 0; m < len; m++) drop[k][l + m] = true;
			}
			bool just_first = first;
			if (first) drop[i][j] = true, first = false;
			int cur_sum = 0;
			for (int k = 0; k < h; k++) for (int l = 0; l < w; l++)
				if (drop[k][l] && !(just_first && k == i && l == j)) cur_sum += board[k][l] - '0';
			if (!cur_sum && !just_first) break;
			cur += cur_sum * times;
			std::string next[h];
			for (auto &i : next) i = std::string(w, '*');
			for (int k = 0; k < w; k++) {
				int head = h;
				for (int l = h; l--; ) if (board[l][k] != '*' && !drop[l][k]) next[--head][k] = board[l][k];
			}
			for (int k = 0; k < h; k++) board[k] = next[k];
			if (!just_first) times *= 2;
		}
		res = std::max(res, cur);
	}
	printf("%d\n", res);
	return 0;
}


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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B > C + D){cout << "Left" << endl;}
  else if(A + B == C + D){cout << "Balanced" << endl;}
  else{cout << "Right" << endl;}
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


//Hang in there!

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>data(N);
	for (int i = 0; i < N; i++) {
		cin >> data[i];
	}
	int check = 0;
	for (int i = 0; i < N; i++) {
		if(data[i] != i + 1){
			check++;
		}
	}
	if (check <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
    FILE *fin,*fout;
//#define DEBUG
#ifdef DEBUG
    fin=fopen("input.txt","r");fout=fopen("output.txt","w");
#else
    fin=stdin; fout=stdout;
#endif    

    while(feof(fin)==0){
        //calc 
        int a,b;
        fscanf(fin,"%d %d\n",&a,&b);
        int ans;
        ans=a+b;
        fprintf(fout,"%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<map>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

ll q,h,s,d,n;

ll tmin(ll a,ll b,ll c)
{
	ll k=min(a,b);
	return min(k,c);
}
ll fmin(ll a,ll b,ll c,ll d)
{
	ll k=tmin(a,b,c);
	return min(k,d);
}
int main()
{
	cin>>q>>h>>s>>d;
	cin>>n;
	int k=n/2;
	int l=n%2;

	ll ans=0;
	ans+=k*fmin(8*q,4*h,2*s,d);
	ans+=l*tmin(4*q,2*h,s);

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;


int main(){
    int A,B;
    cin >> A >> B;
    if(A<=8 && B<=8){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let mut ans = 0;
    for i in 1..(n+1)/2+1 {
        let mut m = 1;
        let mut c = 0;
        while m * m < 2 * i - 1 {
            if (2 * i - 1) % m == 0 {
                c += 1;
            }
            m += 1;
        }
        if m * m != 2 * i - 1 && c == 4 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int mx = (n-1)*(n-2)/2;

    if(mx < k) {
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int, int>> ans;
    rep(i, n-1) {
        ans.push_back(make_pair(i+1, n));
    }

    vector<pair<int, int>> edge;
    rep(i, n-1) {
        rep(j, i) {
            edge.push_back(make_pair(i+1, j+1));
        }
    }
    
    int add = mx - k;
    rep(i, add) {
        ans.push_back(edge[i]);
    }

    cout << ans.size() << "\n";
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int n,m,k;

using ll = long long;
const int mod = 1e9 + 7;

ll quick_pow(ll a, ll b) {
    ll res = 1;
    a %= mod;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int comb(int n, int m){
    //n!/(m!(n-m)!)
    vector<int> fac(n+1), finv(n+1);
    fac[0] = finv[0] = 1;
    for(int i = 1; i <= n; ++i)fac[i]=(ll)fac[i-1]*i%mod;
    finv[n] = quick_pow(fac[n], mod-2);
    for(int i = n-1; i; --i)finv[i] = (ll)finv[i+1]*(i+1)%mod;
    
    return (ll)fac[n] * finv[m] % mod * finv[n - m]% mod;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m>>k;
    
    
    ll d = 0;
    for (int i = 1; i < n; i++){
        d += (ll)i*(n-i)%mod*m%mod*m%mod;
        d%= mod;
    }
    
    for (int i = 1; i < m; i++){
        d += (ll)i*(m-i)%mod*n%mod*n%mod;
        d %= mod;
    }
    
    cout<<d*comb(n*m-2, k-2)%mod<<endl;
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 1792
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1 for i in range(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, y = self.find(x), 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

N, M = map(int, input().split())
friend_lis = [list(map(int, input().split())) for i in range(M)]

lis = UnionFind(N)
for i,j in friend_lis:
  lis.union(i-1, j-1)
#print(lis.parents)

ans = -min(lis.parents)
print(ans)

Measured memory_bytes: 49728
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int h, w, m; cin >> h >> w >> m;
  //vector<int> tr(m), tc(m);
  vector<pair<int, int>> row_sum(h+5), col_sum(w+5);
  set<pair<int, int>> targets;
  rep (i, h) row_sum[i].second = i;
  rep (i, w) col_sum[i].second = i;
  rep (i, m) {
    int r, c; cin >> r >> c; 
    r--; c--;
    targets.insert({r, c});
    row_sum[r].first++;
    col_sum[c].first++;
  }

  sort(begin(row_sum), end(row_sum));
  reverse(begin(row_sum), end(row_sum));
  sort(begin(col_sum), end(col_sum));
  reverse(begin(col_sum), end(col_sum));
  int max_row_sum = (*max_element(begin(row_sum), end(row_sum))).first;
  int max_col_sum = (*max_element(begin(col_sum), end(col_sum))).first;

  int ans = max_row_sum + max_col_sum - 1;
  for (auto p_row : row_sum) {
    if (p_row.first != max_row_sum) break;
    for (auto p_col : col_sum) {
      if (p_col.first != max_col_sum) break;
      if (!targets.count({p_row.second, p_col.second})) {
        ans = max_row_sum + max_col_sum;
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    int m,d;
    cin >> m >> d;
    int res = 0;
    for (int j=4; j <= m; j++) {
        for (int i=1; i <= d; i++) {
            if (i % 10 >= 2 && i / 10 >= 2) {
                if ((i % 10) * (i / 10) == j) {
                    // cout << i % 10 << ' ' << i / 10 << endl;
                    res++;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/

using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,k;
vector<int> G[2222];
P es[2222];
bool vis[2222];

int dfs(int v,int d){
  int res=0;
  vis[v]=true;
  if(d>k)res++;
  rep(i,G[v].size()){
    int nv=G[v][i];
    if(!vis[nv])res+=dfs(nv,d+1);
  }
  return res;
}

int main(){
  cin.sync_with_stdio(false);
  cin>>n>>k;
  rep(i,n-1){
    int a,b;
    cin>>a>>b; a--; b--;
    es[i].fi=a; es[i].se=b;
    G[a].pb(b); G[b].pb(a);
  }
  int res=INF;
  if(k%2==0){
    k/=2;
    rep(i,n){
      rep(j,n)vis[j]=false;
      minch(res,dfs(i,0));
    }
  }else{
    k=(k-1)/2;
    rep(i,n-1){
      rep(j,n)vis[j]=false;
      int v1=es[i].fi,v2=es[i].se;
      vis[v1]=true,vis[v2]=true;
      minch(res,dfs(v1,0)+dfs(v2,0));
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int Tax8, Tax10;
    cin >> Tax8 >> Tax10;
    for (int i = 0; i <= 1000; i++)
        if (Tax8 == (int)floor(i * 0.08) && Tax10 == (int)floor(i * 0.1))
        {
            cout << i << endl;
            return 0;
        }

    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define out(x) rep(i, 0, (x).size()) cout << (x)[i] << ((i != (x).size() - 1) ? " " : "\n")
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const int LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////
class unionfind {
private:
  int size_;
  std::vector<int> parent;
  std::vector<int> rank;

public:
  unionfind()
      : size_(0), parent(std::vector<int>()), rank(std::vector<int>()){};
  unionfind(int size__)
      : size_(size__), parent(std::vector<int>(size_)), rank(std::vector<int>(size_, 0)) {
    std::iota(parent.begin(), parent.end(), 0);
  }
  int size() { return size_; }
  int root(int x) {
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y])
      parent[x] = y;
    else if (rank[x] > rank[y])
      parent[y] = x;
    else
      parent[y] = x, rank[x]++;
  }
};

int N, Q, tp, x, y;
signed main() {
  cin >> N >> Q;
  unionfind uf(N);
  while (Q--) {
    cin >> tp >> x >> y;
    if (tp == 0)
      uf.unite(x, y);
    else
      cout << uf.same(x, y) << '\n';
  }
}


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

int main() {
  int n, k; cin >> n >> k;
  vec a(n);
  rep (i,n) {
    cin >> a[i];
  }

  rep(i,n-k) {
    if (a[k+i] > a[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4052
#include<stdio.h>
#define R register
int m,d,ans;
int main(void)
{
	scanf("%d%d",&m,&d);
	for(R int i=4; i<=m; i++)
	{
		for(R int j=22; j<=d; j++)
		{
			int k=j%10,g=j/10;
			if(k>1&&g>1&&k*g==i)
			{
				ans++;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    
    long maxc = 0;
    REPI(i,1,n+1) {
        bool fl = true;
        for (int j = 0; j < i; j++) {
            if (s[n - i + j] != t[j]) {
                fl = false;
                break;
            }
        }
        if (fl) {
            maxc = i;
        }
    }
    cout << 2 * n - maxc << endl;
}


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

int main()
{
	int n,c=0;
	cin >> n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(i%2 && a[i]%2)
		{
			c++;
		}
	}
	
	cout << c;
}

Measured memory_bytes: 3560
#include<iostream>
#include<stdlib.h>
using namespace std;
int Comp(const void *a,const void *b)
{
	return *(int*)a-*(int*)b;
}
int main()
{
	int i,a[10];
	for(i=0;i<10;i++)
		cin>>a[i];
	qsort(a,10,sizeof(int),Comp);
	for(i=9;i>6;i--)
		cout<<a[i]<<endl;
	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  
  int total = 0;
  vector<int> azi(N);
  for(int i = 1; i <= N; i++ ){
    azi.at(i-1) = L + i - 1;
    total += azi.at(i-1);
  }
  
  int sa = 200000;
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( azi.at(i) == 0 ){
      cout << total << endl;
      return 0;
    }else if( azi.at(0) > 0 ){
      cout << total - azi.at(0) << endl;
      return 0;
    }else if( total - ( total - azi.at(i) )  < sa ){
      ans = total -azi.at(i);
    }
  }
  
  cout << ans << endl;
}

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

#define BR "\n"
#define SP " "

int main() {
  int N, X;

  while (1) {
    cin >> N >> X;
    if (N == 0 && X == 0) break;

    int c = 0;
    for (int i = 1; i <= N; i++) {
      if (i > X) break;

      for (int j = i + 1; j <= N; j++) {
        if (i + j > X) break;
        
        for (int k = j + 1; k <= N; k++) {
          if (i + j + k > X) break;
          if (i + j + k == X) {
            c++;
          }
        }
      }
    }
    cout << c << BR;
  }
  return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
const int N = 12;

int n;

char a[N];
void rec(int i, int q)
{
    if (i == n)
    {
        printf("%s\n", a);
        return;
    }
    for (char u = 'a'; u <= 'a' + q; ++u)
    {
        a[i] = u;
        if (u < 'a' + q)
            rec(i + 1, q);
        else
            rec(i + 1, q + 1);
    }
}

int main()
{
    scanf("%d", &n);
    rec(0, 0);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,A=1;
	cin>>n;
	int a[n],b[4]={0,0,0,0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]%=4;
		b[a[i]]++;
	}
	if((b[1]+b[3])>b[0]) A=0;
	if(b[1]+b[3]==b[0]+1&&b[2]==0) A=1;
	cout<<((A) ? "Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 100010

// 1 2 3 4 5 6
//   1+2+...(n-i+1) 
//   
int main(){
    IOS;
     
    
     ll n,ans=0;cin>>n;
     rep(i,1,n+1)ans+=((n-i+1)*(n-i+2))/2;
     rep(i,0,n-1){
     	ll u,v;cin>>u>>v;
     	if(u>v)swap(u,v);
     	ans-=u*(n-v+1);
     }
     cout<<ans;
     
     
    return 0;
}


Measured memory_bytes: 3644
a_list = list(map(int, input().split()))
a, b, c, d = a_list[0], a_list[1], a_list[2], a_list[3]

start = 0
alice_time = (a, b)
bob_time = (c, d)

max_end = max(b, d)
alice_zone = [0] * max_end
bob_zone = [0] * max_end
alice_zone[a:b] = [1] * len(alice_zone[a:b])
bob_zone[c:d] = [1] * len(bob_zone[c:d])

kasanari_zone = [alice * bob for alice, bob, in zip(alice_zone, bob_zone)]
print(sum(kasanari_zone))


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

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

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	constexpr T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

const long long INF=1LL<<61;

int main(){
	int n; cin>>n;
	vector<string> s(n);
	vector<lint> cost(n);
	rep(i,n) cin>>s[i]>>cost[i];

	map<pair<string,int>,int> f; // (string, prefix or suffix) -> id
	rep(i,n){
		rep(j,s[i].length()+1){
			// prefix
			string t=s[i].substr(0,j);
			if(f.count({t,0})==0) f[{t,0}]=f.size();
			// suffix
			t=s[i].substr(s[i].length()-j);
			if(f.count({t,1})==0) f[{t,1}]=f.size();
		}
	}

	int N=f.size()+1,src=f.size();
	weighted_graph<lint> G(N);
	rep(i,n){
		add_directed_edge(G,src,f[{s[i],1}],cost[i]);
		rep(j,s[i].length()+1){
			// prefix
			string t=s[i].substr(0,j);
			string r=t;
			reverse(r.begin(),r.end());
			rep(k,n){
				int len1=s[k].length(),len2=t.length();
				if(s[k].substr(0,min(len1,len2))==r.substr(0,min(len1,len2))){
					int next;
					if(len1<=len2){
						next=f[{t.substr(0,len2-len1),0}];
					}
					else{
						next=f[{s[k].substr(len2),1}];
					}
					add_directed_edge(G,f[{t,0}],next,cost[k]);
				}
			}
			// suffix
			t=s[i].substr(s[i].length()-j);
			r=t;
			reverse(r.begin(),r.end());
			rep(k,n){
				int len1=s[k].length(),len2=t.length();
				if(s[k].substr(len1-min(len1,len2))==r.substr(len2-min(len1,len2))){
					int next;
					if(len1<=len2){
						next=f[{t.substr(len1,len2),1}];
					}
					else{
						next=f[{s[k].substr(0,len1-len2),0}];
					}
					add_directed_edge(G,f[{t,1}],next,cost[k]);
				}
			}
		}
	}

	auto d=Dijkstra(G,src);

	lint ans=INF;
	for(auto p:f){
		string t=p.first.first;
		string r=t;
		reverse(r.begin(),r.end());
		if(t==r) ans=min(ans,d[p.second]);
	}
	cout<<(ans<INF?ans:-1)<<'\n';

	return 0;
}


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

int main() {
   string s;
   cin>>s;
   int ans = 0;
   deque<int> ar;
   for(int i =0;i<s.length();i++) {
      int m = ar.size()-1;
      if (!ar.empty() && (ar[m]^(s[i]-'0'))) {
         ar.pop_back();
         ans+=2;
      }
      else
         ar.push_back(s[i] - '0');
   }
   cout<<ans<<endl;
}   

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;

struct UnionFind {
	vector<ll>p;
	UnionFind(ll n) {
		p.resize(n, -1);
	}
	ll find(ll x) {
		if (p[x] == -1)return x;
		else return p[x] = find(p[x]);
	}
    void unite(ll x, ll y) {
		x = find(x), y = find(y);
		if (x == y)return;
		p[x] = y;
	}
};

struct edge{
	ll u, v, cost;
};
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}


ll V, E;
edge G[200010];

int kruskal() {
	sort(G, G + E, comp);
	UnionFind uf(V);
	ll res = 0;
	rep(i, E) {
		edge e = G[i];
		if (uf.find(e.u) != uf.find(e.v)) {
			uf.unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> V >> E;
	rep(i, E) {
		ll s, t, w; cin >> s >> t >> w; 
		G[i] = { s,t,w };
	}
	cout << kruskal() << endl;
	return 0;
}


Measured memory_bytes: 5580
#include <bits/stdc++.h>
typedef long long ll;
const ll p = 1e9 + 7;
const int N = 2e5 + 5;
int n, x, y, frac[N], inv[N], ans, dp[N], cnt, head[N], sz[N];
struct node { int u, v; } edge[N << 1]; 
inline void add(int x, int y) { edge[cnt].u = head[x], edge[cnt].v = y, head[x] = cnt++; }
inline int power(int x, int y, int ret = 1) { for (; y; y >>= 1, x = (ll) x * x % p) if (y & 1) ret = (ll) ret * x % p; return ret; }
void dfs(int x, int fa) {
	int i;
	sz[x] = 1;
	for (i = head[x]; ~i; i = edge[i].u) {
		int y = edge[i].v;
		if (y == fa) continue;
		dfs(y, x);
		sz[x] += sz[y], dp[x] = (ll) dp[x] * dp[y] % p * inv[sz[y]] % p;
	}
	dp[x] = (ll) dp[x] * frac[sz[x] - 1] % p;
}
void solve(int x, int fa) {
	int i;
	if (fa) dp[x] = (ll) dp[fa] % p * sz[x] % p * inv[n - sz[x]] % p * frac[n - sz[x] - 1] % p;
	for (i = head[x]; ~i; i = edge[i].u) {
		int y = edge[i].v;
		if (y == fa) continue;
		solve(y, x);
	}
}
int main() {
	memset(head, -1, sizeof head);
	int i;
	std::cin >> n;
	frac[0] = frac[1] = dp[1] = 1;
	for (i = 2; i <= n; ++i) frac[i] = (ll) frac[i - 1] * i % p, dp[i] = 1;
	inv[n] = power(frac[n], p - 2);
	for (i = n; i; --i) inv[i - 1] = (ll) i * inv[i] % p;
	for (i = 1; i < n; ++i) std::cin >> x >> y, add(x, y), add(y, x);
	dfs(1, 0), solve(1, 0);
	for (i = 1; i <= n; ++i) std::cout << dp[i] << '\n';
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++)
            cout<<i<<"x"<<j<<"="<<i*j<<endl;
    }
    return 0;
}




Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
// #include "debug.h"
#define debug(...) 42

const ll inf = 1e17L;

const int mod = 1e9 + 7;
void solve(int testCaseID) {

   int n, k;
   cin >> n >> k;
   vector <int> v(n);
   vector <pair <int, int> > p(n);

   for(int i = 0; i < n; i++) {
      cin >> v[i];
      p[i] = {v[i], i};
   }

   sort(p.begin(), p.end());

   ll inv_cnt = 0;
   for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
         inv_cnt += v[i] > v[j];
      }
   }

   inv_cnt = (inv_cnt * k) % mod;
   debug(inv_cnt);
   for(int i = 0; i < n; i++) {
      for(int j = 0; j < i; j++) {
         if(p[j].first < p[i].first) {
            inv_cnt += (k * 1LL * (k - 1)) / 2;
            inv_cnt %= mod;
            debug(inv_cnt);
         }
      }
   }

   cout << inv_cnt << endl;

} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve(i + 1);
   }
   return 0;
}


Measured memory_bytes: 3652