akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 10000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < vi, int > a, pair < vi, int > b)//true for a before b
{
	if(a.F.empty())
		return 1;
	if(b.F.empty())
		return 0;
	int i;
	fo(i,0,min(sz(a.F),sz(b.F)))
	{
		if(a.F[i] < b.F[i])
			return 1;
		else if(a.F[i] > b.F[i])
			return 0;
	}
	return (sz(a.F) <= sz(b.F));
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;

ll a[N], sum[N];

inline ll calc_sum(int l, int r)
{
	if(l > r)
		return 0LL;
	return (sum[r] - sum[l-1]);
}

void solve()
{
	int n, i;
	ll ans = INFLL;
	cin >> n;
	fo(i,1,n+1)
	{
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	fo(i,1,n)
		ans = min(ans, abs(calc_sum(1,i)-calc_sum(i+1,n)));
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(15);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

int N, K;
int minValue = INT_MAX;
vector<bool> D(10, false);

void dfs(vector<int> pay, int length) {
    if(pay.size() == length) {
        int cost = 0;
        // rep(i, pay.size()) {
        //     cout << pay[pay.size() - 1 - i];
        // }
        // cout << endl;
        rep(i, length) {
            cost += pay[i] * pow(10, i);
        }
        if(N <= cost && cost <= minValue) minValue = cost;
        return;
    }
    rep(i, 10) {
        if(!D[i]) {
            pay.push_back(i);
            dfs(pay, length);
            pay.pop_back();
        }
    }
}

int main() {

    vector<int> pay;
    cin >> N >> K;
    int length = to_string(N).length();
    rep(i, K) {
        int d;
        cin >> d;
        D[d] = true;
    }
    dfs(pay, length + 1);
    dfs(pay, length);
    cout << minValue << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

struct UnionFind {
	int par[201000];
	int rank[201000];

	void init() {
		for (int i = 0; i < 201000; i++) {
			par[i] = i;
			rank[i] = 1;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[y] == rank[x])rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

UnionFind uf;

int main() {
	while (cin >> n >> m&&n + m) {
		uf.init();
		vector<pair<int, P>> vip;
		rep(i, m) {
			int t, s, d;
			cin >> t >> s >> d;
			vip.push_back({ t,{s,d} });
		}
		sort(ALL(vip));
		rep(i, m) {
			int s = vip[i].second.first, d = vip[i].second.second;
			if (uf.same(1, s)) {
				uf.unite(s, d);
			}
		}
		int ans = 0;
		FOR(i, 1, n + 1) {
			ans += (uf.find(i) == 1);
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int nax = 1e5 + 100;

vector<int> g[nax];
int sz[nax],par[nax],depth[nax];

void dfs(int u,int p){
	par[u] = p;
	sz[u] = 1;
	for(int v : g[u]){
		if(v == p)continue;
		depth[v] = depth[u] + 1;
		dfs(v,u);
		sz[u] += sz[v];
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	#endif
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	int u = n;
	for(int i=0;i<(depth[n]-1)/2;i++){
		u = par[u];
	}
	// cout << n-sz[u] << ' ' << sz[u] << endl;
	cout << (n - sz[u] > sz[u] ? "Fennec" : "Snuke") << '\n';
}

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

signed main(){
  string S;
  cin>>S;
  
  string ans="No";
  if(S.size()%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<=S.size();i++){
        if(S[i]=='h'&&S[i+1]=='h'){
      cout<<ans<<endl;
      return 0;
    }else if(S[i]=='i'&&S[i+1]=='i'){
      cout<<ans<<endl;
      return 0;
    }
    if(S[i]=='h'&&S[i+1]=='i'){
      ans="Yes";
      cout<<ans<<endl;
      return 0;
    }else{
      i++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  string s;
  cin>>s;
  int a=INF;
  rep(i,s.size()){
    int n=stoi(s.substr(i,3));
    a=min(a,abs(n-753));
  }
  cout<<a<<endl;
    
}


Measured memory_bytes: 256
N,M,K = map(int,input().split())
MOD = 10**9+7

MAXN = N*M+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

a = 0
for d in range(1,N):
    a += d*(N-d)*M*M
b = 0
for d in range(1,M):
    b += d*(M-d)*N*N

ans = (a+b) * comb(N*M-2, K-2)
ans %= MOD
print(ans)

Measured memory_bytes: 34044
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;
#define INF 1<<21
#define DIV 1000000007

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

int main() {
  int N;
  int s[105];
  int sum = 0;
  int flag = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
	cin >> s[i];
	sum += s[i];
	if (s[i] % 10 != 0) {
	  flag = 1;
	}
  }
  sort(s, s + N);

  int i = 0;
  if (flag == 1) {

	while (sum % 10 == 0) {
	  if (s[i] % 10 != 0) {
		sum -= s[i];
	  }
	  i++;
	}
  }

  else {
	sum = 0;
  }

  cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
using namespace std;

int n;
string s;

signed main() {
	int i;
	
	cin >> s;
	n = s.length();
	
	int bcnt = 0, ans = 0;
	for (i = n - 1; i >= 0; i--) {
		if (s[i] == 'B') {
			int to = n - 1 - bcnt;
			ans += to - i;
			bcnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    	Scanner scan=new Scanner(System.in);
    	int a=scan.nextInt();
    	int b=scan.nextInt();
    	int c=scan.nextInt();
    	System.out.print((b>=c?c:b)+" ");
    	System.out.println(b+c-a<0?0:b+c-a);
    }
}

Measured memory_bytes: 23124
<?php

list($n, $m) = array_map('intval', explode(" ", trim(fgets(STDIN))));

for($i=0; $i<$n; $i++){
    $A[] = array_map('intval', explode(" ", trim(fgets(STDIN))));
}
// var_dump($A);
for($j=0; $j<$m; $j++){
    $B_j = intval(trim(fgets(STDIN)));
    for($i=0; $i<$n; $i++){
        $A[$i][$j] *= $B_j;
    }
}
$C = array_map('array_sum', $A);
print implode("\n", $C) . "\n";

?>


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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

void Main()
{
	int N;
	cin>>N;
	vec(v,N);
	ll ans=0;
	for(int x=1; x<=N; x++){
			if(x*x + 1 + 1 + x*1 + 1 +  1*x >N)break;
		for(int y=x; y<=N;y++){
			if(x*x + y*y + 1 + x*y + y*1 +  1*x >N)break;
			for(int z=y; z<=N;z++){
				if(x*x + y*y + z*z + x*y + y*z +  z*x > N)break;
				int t=0;
				if(x==y && y==z) t=1;
				else if(x==y || y==z || z==x) t=3;
				else t=6;
				v[x*x + y*y + z*z + x*y + y*z +  z*x - 1]+=t;
			}
		}
	}

	rep(i,N){
		cout<<v[i]<<_n;
	}
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3608
n = gets.to_i
h = Array.new(10 ** 4 + 1, 0)
for x in 1..100 do
  for y in 1..100 do
    for z in 1..100 do
      k = x * x + y * y + z * z + x * y + y * z + z * x
      if k <= 10 ** 4
        h[k] += 1
      end
    end
  end
end
for i in 1..n do
  puts h[i]
end


Measured memory_bytes: 14316
N = int(input())
S = [input() for _ in range(N)]
 
# 方針：各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する
 
# 各単語の出現回数を数える（辞書型を用いる！！）
dic = {}
for i in range(N):
  s = S[i]
  if s not in dic: dic[s] = 1
  else: dic[s] += 1

max_count = max(dic.values()) # 最大の出現回数
 
# 出現回数が最も多い単語を集計する
l = [key for key in dic.keys() if dic[key] == max_count]
 
# 昇順にソートして出力
for i in sorted(l):
  print(i)

Measured memory_bytes: 38464
N=int(input())
A=[0]*N
B=['0']*N
count=0
for i in range(N):
  A[i],B[i]=input().split()
for i in range(N):
  if B[i]=='BTC':
    count+=float(A[i])*380000.0
  else:
    count+=float(A[i])
print(count)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  ll N, M;
  cin >> N >> M;
  vector<ll> X(N), Y(M);
  for (ll i = 0; i < N; ++i) {
    cin >> X.at(i);
  }
  for (ll i = 0; i < M; ++i) {
    cin >> Y.at(i);
  }
  ll sum_x = 0, sum_y = 0;
  for (ll i = 0; i < N - 1; ++i) {
    sum_x = (sum_x + ((((X.at(i + 1) - X.at(i)) % mod) * (i + 1)) % mod) * (N - i - 1) % mod) % mod;
  }
  for (ll i = 0; i < M - 1; ++i) {
    sum_y = (sum_y + ((((Y.at(i + 1) - Y.at(i)) % mod) * (i + 1)) % mod) * (M - i - 1) % mod) % mod;
  }
  ll ans = sum_x * sum_y % mod;
  cout << ans << "\n";
}


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

struct Dice
{
	int c[6];	//??????????????????

	Dice() {}

	//c0:???, c1:??????, c2:???, c3:?\\, c4:???, c5:???
	Dice(int c0, int c1, int c2, int c3, int c4, int c5)
	{
		c[0] = c0; c[1] = c1; c[2] = c2; c[3] = c3; c[4] = c4; c[5] = c5;
	}

	void temae()
	{
		int temp = c[0];
		c[0] = c[3]; c[3] = c[5]; c[5] = c[1];
		c[1] = temp;
	}

	void oku()
	{
		int temp = c[0];
		c[0] = c[1]; c[1] = c[5]; c[5] = c[3];
		c[3] = temp;
	}

	//y????????¢??????
	void y_migi()
	{
		int temp = c[1];
		c[1] = c[4]; c[4] = c[3]; c[3] = c[2];
		c[2] = temp;
	}

	//y????????¢??????
	void y_hidari()
	{
		int temp = c[1];
		c[1] = c[2]; c[2] = c[3]; c[3] = c[4];
		c[4] = temp;
	}

	//z????????¢??????
	void z_migi()
	{
		int temp = c[0];
		c[0] = c[4]; c[4] = c[5]; c[5] = c[2];
		c[2] = temp;
	}

	//z????????¢??????
	void z_hidari()
	{
		int temp = c[0];
		c[0] = c[2]; c[2] = c[5]; c[5] = c[4];
		c[4] = temp;
	}

	//1???????????\?????????????????¢??????2????¨????????????´????????????????\\??????????????°3????\\????????????????????????
	void format()
	{
		if (c[0] == 1) {
			;
		} else if (c[1] == 1) {
			oku();
		} else if (c[2] == 1) {
			z_hidari();
		} else if (c[3] == 1) {
			temae();
		} else if (c[4] == 1) {
			z_migi();
		} else if (c[5] == 1) {
			oku();
			oku();
		}

		if (c[1] == 2)
		{
			y_migi();
			y_migi();
		} else if (c[2] == 2) {
			y_migi();
		} else if (c[4] == 2) {
			y_hidari();
		} else if (c[3] == 2) {
			return;
		} else {
			if (c[1] == 3)
			{
				y_migi();
				y_migi();
			} else if (c[2] == 3) {
				y_migi();
			} else if (c[4] == 3) {
				y_hidari();
			}
		}
	}

	bool operator == (const Dice &d) const {
		Dice td1 = Dice(c[0], c[1], c[2], c[3], c[4], c[5]);
		Dice td2 = d;

		td1.format();
		td2.format();

		rep(i,6)
		{
			if (td1.c[i] != td2.c[i]) return false;
		}
		return true;
	}
};

int n;
map<string, int> c2n;
string color[6];
int cc[6];
Dice d[30];
bool used[30];

signed main()
{
	c2n["Red"] = 1;
	c2n["Yellow"] = 2;
	c2n["Blue"] = 3;
	c2n["Magenta"] = 4;
	c2n["Green"] = 5;
	c2n["Cyan"] = 6;

	while (true)
	{
		cin >> n;
		if (n == 0) break;

		rep(j,n)
		{
			rep(i,6) cin >> color[i];
			cc[0] = c2n[color[0]];
			cc[1] = c2n[color[1]];
			cc[2] = c2n[color[2]];
			cc[3] = c2n[color[4]];
			cc[4] = c2n[color[3]];
			cc[5] = c2n[color[5]];
			d[j] = Dice(cc[0], cc[1], cc[2], cc[3], cc[4], cc[5]);
		}

		rep(i,n) used[i] = false;

		int ans = 0;
		for (int i=0; i<n; i++)
		{
			for (int j=i+1; j<n; j++)
			{
				if (d[i] == d[j] && used[j] == false)
				{
					ans++;
					used[j] = true;
				}
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int main()
{
    fastIO
    
    ll n, k;
    cin >> n >> k;
    
    vi arr(n + 1);
    for(int i = 1; i <= n; ++i)
        cin >> arr[i];
        
    vi track;
    vi visited(n + 1);
    
    int curr = 1;
    while(!visited[curr])
    {
        visited[curr] = 1;
        track.pb(curr);
        // cout << curr << endl;
        
        curr = arr[curr];
    }
    
    // cout << curr << endl;
    
    int start = -1;
    vi cycle = {0};
    
    for(int i = 0; i < track.size(); ++i)
    {
        // cout << track[i] << " ";
        if(start != -1)
            cycle.pb(track[i]);
        if(track[i] == curr && start == -1)
            start = i;
    }
    // cout << endl;
    // cout << "-----" << endl;
    // cout << start << endl << endl;
    
    cycle[0] = curr;
    
    // cout << k << endl;
    
    if(k <= start)
        cout << track[k];
    else
    {
        k -= start;
        int pos = k % (ll)(cycle.size());
        // cout << k << " " << cycle.size() << " " << pos << endl;
        cout << cycle[pos];
    }

    return 0;
}

Measured memory_bytes: 7160
A, B, C = list(map(int, input().split()))
K = int(input())
flag = False
for i in range(K):
    b = (2 ** i) * B
    c = (2 ** (K - i)) * C
    if A < b < c:
        flag = True
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8792
// Author - Sumit

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define int ll
#define ps push
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

void solve(){
    int n;
    cin>>n;
    int a[n][3];
    rep(i,0,n){
        rep(j,0,3){
            cin>>a[i][j];
        }
    }
    int dp[n][3];
    memset(dp,0,sizeof dp);
    rep(i,0,3) dp[0][i] = a[0][i];
    rep(i,1,n){
        dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    // rep(i,0,n){
    //     rep(j,0,3){
    //         cout<<dp[i][j]<< " ";
    //     }cout<<endl;
    // }
    debug(max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));

}

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

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

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#include <functional>

template< typename T, typename S >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<S> lazy;
    T te;
    S se;

    inline void merge_functions(S& lazy,S& val){
        lazy+=val;
        //lazy=val;
    }
    inline void operate(T& data,S& val,int len){
        data+=val*len;
        //data+=val;
        //data=val;
    }
    inline T merge_values(T& x,T& y){
        return x+y;
        //return min(x,y);
        //return max(x,y);
    }

    LazySegmentTree(){}
    LazySegmentTree(int sz,T te,S se):te(te),se(se){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,se);
    }

    void build(vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==se) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]);
        }
        lazy[k]=se;
    }

    void update(int a,int b,S val,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            merge_functions(lazy[k],val);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }
};


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

  int N,Q;
  cin>>N>>Q;

  LazySegmentTree<ll,ll> seg(N,0,0);

  vector<ll> init(N,0);
  seg.build(init);

  for(int q=0;q<Q;q++){
      int t;cin>>t;
      if(t==0){
          int a,b;
          ll x;
          cin>>a>>b>>x;
          a--;b--;
          seg.update(a,b+1,x);
      }else{
          int a,b;
          cin>>a>>b;
          a--;b--;
          cout<<seg.query(a,b+1)<<"\n";
      }
  }

  return 0;
}



Measured memory_bytes: 7856
/*input
6
1 1
2 2
3 3
4 4
5 5
6 6
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn],arr2[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP(i,n) cin>>arr[i]>>arr2[i];
    REP(i,n-2){
        if(arr[i]==arr2[i] and arr[i+1]==arr2[i+1] and arr[i+2]==arr2[i+2]){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
}  


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

int *createList(int num)
{
	int i, *list = new int[num];
	for (i = 0; i < num; i++)
		cin >> list[i];
	return list;
}

void bubbleSort(int num, int *list)
{
	int i, j, temp, swaps = 0;
	for (i = 0; i < num; i++)
	{
		for (j = num - 1; j >= 0; j--)
		{
			if (list[j] < list[j - 1])
			{
				temp = list[j];
				list[j] = list[j - 1];
				list[j - 1] = temp;
				swaps++;
			}
		}
	}
	for (i = 0; i < num - 1; i++)
		cout << list[i] << " ";
	cout << list[num - 1] << endl;
	cout << swaps << endl;

}

int main()
{
	int num, *list;
	cin >> num;
	list = createList(num);
	bubbleSort(num, list);
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int N, A, B;
    std::cin >> N >> A >> B;

    std::cout << min(A * N, B) << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define MOD 1000000007
ll fact[1000010];
ll invfact[1000010];
ll temp[1000010];

ll choose(ll n,ll r){
	if(n<0||r<0||r>n)return 0;
	return fact[n]*invfact[r]%MOD*invfact[n-r]%MOD;
}

int main(){
	fact[0]=1;
	rep(i,1,1000005)fact[i]=fact[i-1]*i%MOD;
	invfact[1000000]=pom(fact[1000000],MOD-2,MOD);
	for(ll i=999999;i>=0;i--)invfact[i]=invfact[i+1]*(i+1)%MOD;
	
	ll n;
	scanf("%lld",&n);
	rep(k,0,n)temp[k]=choose(k-1,n-1-k)*fact[k]%MOD*fact[n-1-k]%MOD;
	ll ans=0;
	rep(k,1,n)ans=(ans+k*(temp[k]-temp[k-1]+MOD))%MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, std::vector<long long> A)
{
  auto B = std::accumulate(vall(A), 0ll, [](auto l, auto r) { return l ^ r; });

  vector<lli> even;
  lli ret = 0;
  lli iter = 0;
  rrep(i, 60)
  {
    if (((B >> i) & 1))
    {
      ret += 1ll << i;
    }
    else
      iter |= 1ll << i;
  }
  lli rem = B - ret;
  vector<lli> mat = A;
  rep(i, N) mat[i] &= iter;
  lli rnk = 0;
  rep(i, 60)
  {
    lli idx = 59 - i;
    lli up = -1;
    for (int j = rnk; j < N; j++)
    {
      if ((mat[j] >> idx) & 1)
      {
        up = j;
        break;
      }
    }
    if (up < 0)
      continue;
    swap(mat[up], mat[rnk]);
    for (int j = 0; j < N; j++)
    {
      if (j != rnk && (mat[j] >> idx) & 1)
        mat[j] = mat[j] ^ mat[rnk];
    }
    rnk++;
  }
  // rep(i, N)
  // {
  //   cout << std::bitset<10>(mat[i]) << " ";
  // }
  lli ans = 0;
  lli tmp = iter;
  rep(i, rnk)
  {
    ans ^= mat[i];
  }
  cout << ret + ans * 2 << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
const ll INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;

// Bedone harf !


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

	int a, b;
	cin >> a >> b;
	if(a == b)
		cout << "Draw\n";
	else{
		if(a == 1)
			cout << "Alice\n";
		else if(b == 1)
			cout << "Bob\n";
		else{
			if(a > b)
				cout << "Alice\n";
			else
				cout << "Bob\n";
		}
	}

	return 0;
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h> 
 
using namespace std;
 
 
#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")
#define         FILEIN                     freopen("in.txt","r",stdin)
#define         FILEOUT                    freopen("out.txt","w",stdout)

ll fastexpo(ll b,ll p){
    ll res=1;
    while(p){
        if(p&1){
            res = ( res * b ) % mod;
        }
        b=(b*b)%mod;
        p=p/2;
    }
    return res;
}
ll nCr(ll n,ll r){
    ll val=1,val1=1,val2=1;
    FOR(i,n){
        val = val * i;
        val %= mod;
    }
    FOR(i,r){
        val1 = val1 * i;
        val1 %= mod;
    }
    FOR(i,n-r){
        val2 = val2 * i;
        val2 %= mod;
    }
    val1 = ( val1 * val2 ) % mod;
    ll ans = (val * fastexpo(val1,mod-2))%mod;
    return ans;
}
int main(){
    ll x,y;
    sfl(x),sfl(y);
    if((x+y)%3!=0){
        printf("0\n");
        return 0;
    }
    ll tot = (x+y)/3;
    ll n = 2*tot-x;
    ll m = tot-n;
    ll now=tot-n;
    if( n < 0 or m < 0 or tot < now ){
        printf("0");
        return 0;
    }
    ll ans = nCr(tot,now);
    pfl(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt() + 1;
		int [] t = new int [n];
		for(int i = 1; i < n; i++){t[i] = sc.nextInt();}
		int m = sc.nextInt() + 1;
		int [] p = new int [m];
		int [] x = new int [m];
		for(int i = 1; i < m; i++)
		{p[i] = sc.nextInt(); x[i] = sc.nextInt();}
		int goukei = 0;
		for(int i = 1; i < m; i++){
		for(int j = 1; j < n; j++){ goukei += t[j];}
		goukei = goukei + x[i] - t[p[i]];
		System.out.println(goukei);
		goukei = 0;
		}
		
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long int li;
typedef long long ll;
typedef long double ld;

int main()
{
    int n, k = 1;
    cin >> n;
    if (n >= 1800 && n <= 1999)
		k = 1;
	else if (n >= 1600 && n <= 1799)
		k = 2;
	else if (n >= 1400 && n <= 1599)
		k = 3;
	else if (n >= 1200 && n <= 1399)
		k = 4;
	else if (n >= 1000 && n <= 1199)
		k = 5;
	else if (n >= 800 && n <= 999)
		k = 6;
	else if (n >= 600 && n <= 799)
        k = 7;
	else if (n >= 400 && n <= 599)
		k = 8;
	cout << k << "\n";
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll a[7];

 void DICE(ll x, ll y){
	if(x==a[1]){
		if(y==a[4]) cout<<a[2]<<"\n";
			else if(y==a[2]) cout<<a[3]<<"\n";
				else if(y==a[3]) cout<<a[5]<<"\n";
					else if(y==a[5]) cout<<a[4]<<"\n";
	}
		else if(x==a[2]){
			if(y==a[1]) cout<<a[4]<<"\n";
				else if(y==a[4]) cout<<a[6]<<"\n";
					else if(y==a[6]) cout<<a[3]<<"\n";
						else if(y==a[3]) cout<<a[1]<<"\n";
		}
			else if(x==a[3]){
				if(y==a[1]) cout<<a[2]<<"\n";
					else if(y==a[2]) cout<<a[6]<<"\n";
						else if(y==a[6]) cout<<a[5]<<"\n";
							else if(y==a[5]) cout<<a[1]<<"\n";
			}
				else if(x==a[4]){
					if(y==a[1]) cout<<a[5]<<"\n";
						else if(y==a[5]) cout<<a[6]<<"\n";
							else if(y==a[6]) cout<<a[2]<<"\n";
								else if(y==a[2]) cout<<a[1]<<"\n"; 
				}
					else if(x==a[5]){
						if(y==a[1]) cout<<a[3]<<"\n";
							else if(y==a[3]) cout<<a[6]<<"\n";
								else if(y==a[6]) cout<<a[4]<<"\n";
									else if(y==a[4]) cout<<a[1]<<"\n";
					}
						else{
							if(y==a[2]) cout<<a[4]<<"\n";
								else if(y==a[4]) cout<<a[5]<<"\n";
									else if(y==a[5]) cout<<a[3]<<"\n";
										else if(y==a[3]) cout<<a[2]<<"\n"; 
						}
}
int main(){
	ll n,i,b,c;
	
	for(i=1;i<=6;i++){
		cin>>a[i];
	}
	
	cin>>n;
	
	for(i=0;i<n;i++){
		cin>>b;
		cin>>c;
		DICE(b,c);
	}
	
	return 0;
}


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

using namespace std;

#define ll long long
ll dp[100005][105] , n , m , mod=1e9+7 , w[105] , val[105] ,s;

ll solve(ll we , ll ind)
{
    if (we>s) return -1e18;
    if (ind>n) return 0;
    if (dp[we][ind] != -1) return dp[we][ind];
    ll ans = max(solve(we+w[ind] , ind+1)+val[ind] , solve(we,ind+1));

    return dp[we][ind]=ans;
}

int main()
{
    cin >> n >> s;
    memset(dp , -1 , sizeof(dp));

    for (int i=1; i<=n; i++)
    {
        cin >> w[i] >> val[i];
    }

    cout << solve(0,1) << "\n";

    return 0;
}


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

typedef long long lint;
const int maxn = 305, mod = 1e9 + 7, inv = (mod + 1) / 2;

int n, d[maxn], f[maxn][maxn][2], fac[maxn], ifac[maxn];

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int inc(int a, int b) {return a + b >= mod ? a + b - mod : a + b;}
inline int mul(int a, int b) {return (lint)a * b % mod;}

int main()
{
	n = gi();
	int flg = 1;
	for (int i = 1; i <= n; ++i) d[i] = gi(), flg &= d[i] == 2;

	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
	ifac[0] = ifac[1] = 1;
	for (int i = 2; i <= n; ++i) ifac[i] = mul(mod - mod / i, ifac[mod % i]);
	for (int i = 1; i <= n; ++i) ifac[i] = mul(ifac[i - 1], ifac[i]);

	if (flg) return printf("%d\n", n == 2 ? 1 : mul(fac[n - 1], inv)), 0;
	
	f[0][0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j)
			for (int k = 0; k <= 1; ++k) {
				f[i][j][k] = f[i - 1][j][k];
				if (d[i] >= 2 && j > 0) f[i][j][k] = inc(f[i][j][k], mul(f[i - 1][j - 1][k], d[i] - 1));
				if (d[i] >= 3 && j > 0 && k) f[i][j][k] = inc(f[i][j][k], mul(mul(f[i - 1][j - 1][0], d[i] - 1), d[i] - 2)); 
			}

	int ans = 0;
	for (int i = 3; i <= n; ++i) ans = inc(ans, mul(f[n][i][1], mul(fac[n - i - 1], mul(fac[i - 1], inv))));
	for (int i = 1; i <= n; ++i) ans = mul(ans, ifac[d[i] - 1]);

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int sum;

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  sort(a,a+N);

  if(sum%10==0){
    int ref = 0;
    bool ten = true;
    while(ref<=N-1 && ten==true){
      if(a[ref]%10!=0){
        sum -= a[ref];
        ten = false;
      }
      else{
        ref++;
      }
    }
    if(ref==N) sum = 0;
  }

  cout << sum << endl;



}



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

int main(void){
    long n, m;
    long a, b;
    long res = 0;
    cin >> n >> m;
    
    vector<pair<long, long>> pairs(n);
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    sort(pairs.begin(), pairs.end());
    
    for (int i = 0; i < n; i++) {
        if (pairs[i].second >= m) {
            res += pairs[i].first * m;
            break;
        }
        res += pairs[i].first * pairs[i].second;
        m -= pairs[i].second;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 1792
use std::io::stdin;
use std::cmp::max;

fn main(){
    let nmm = getvec();
    let (n, ma, mb) = (nmm[0], nmm[1], nmm[2]);
    let mut materials: Vec<Vec<i64>> = Vec::new();
    for _ in 0..n {materials.push(getvec())};
    println!("{}", solve(ma, mb, &materials));
}

fn solve(ma: i64, mb: i64, materials: &Vec<Vec<i64>>) -> i64{
    let inf = 1000000;
    let mut dp: [[i64;400];400] = [[inf;400];400];
    for material in materials.iter(){
        let (a, b, c) = (material[0] as usize, material[1] as usize, material[2]);
        for i in (0..400-a).rev(){
            for j in (0..400-b).rev(){
                if dp[i+a][j+b] > dp[i][j]+c{
                    dp[i+a][j+b] = dp[i][j]+c;
                }
            }
        }
        if dp[a-1][b-1] > c{
            dp[a-1][b-1] = c
        }
    }
    let mut ans = inf;
    for i in 1..400/max(ma,mb)+1{
        let x = dp[(ma*i-1) as usize][(mb*i-1) as usize];
        if x < ans{
            ans = x;
        }
    }
    if ans==inf {-1} else {ans}
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

Measured memory_bytes: 5500
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main()
{
  int N,M;
  int maxL = -INF, minR = INF;
  cin >> N >> M;
  REP(i,0,M) {
    int L,R;
    cin >> L >> R;
    chmax(maxL, L);
    chmin(minR, R);
  }
  cout << max(0, minR - maxL + 1) << endl;

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc135/tasks/abc135_a
import numpy as np


def calc(A: int, B: int) -> str:
    K = (B + A) / 2
    if int(K) == K:
        return str(int(K))
    return "IMPOSSIBLE"


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    A, B = load_input_as_int_array()
    larger = max(A, B)
    smaller = min(A, B)
    result = calc(smaller, larger)
    print(result)


main()


Measured memory_bytes: 21392
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if (x==1 && y==1){
		puts("1000000");
		return 0;
	}
	int ans=0;
	if (x==1) ans+=300000;
	else if (x==2) ans+=200000;
	else if (x==3) ans+=100000;
	if (y==1) ans+=300000;
	else if (y==2) ans+=200000;
	else if (y==3) ans+=100000;	
	printf("%d\n",ans);
	return 0;
} 

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

template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    os << "{";
    for(int i = 0; i < v.size(); i++)
        os << v[i] << (i+1<v.size()?", ":"");
    os << "}";
    return os;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
//}}}

vector<int> calc(vector<int> a) {
    int n = a.size();
    vector<int> res(n);
    int val = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] > 0) {
            res[i] = val;
            val = max(0, val-1);
        } else if(a[i] == 0) {
            val = INT_MAX;
        } else {
            int x = -a[i];
            val = max(0, min(val-1, x-1));
        }
    }
    return res;
}
int main(){
    iostream_init();
    int n;
    while(cin >> n){
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        vector<int> b = a;
        reverse(b.begin(), b.end());
        vector<int> left = calc(a);
        vector<int> right = calc(b);
        reverse(right.begin(), right.end());
        int ans = 0;
        REP(i, n) {
            if(a[i] > 0) {
                int val = max(left[i], right[i]);
                if(val >= a[i]) val = a[i];
                ans += val;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 3120
#include <stdio.h>

int main(void){
  
  int n;
  scanf("%d", &n);
  
  char s[n + 1], t[n + 1];
  scanf("%s",s);
  scanf("%s",t);
    
  for(int i = 0;i < n;i++){
  	printf("%c",s[i]);	
  	printf("%c",t[i]);
  }
  
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
	 char str[10];
	 scanf("%s", str);
        switch (str[0]){
          case 'S':
          printf("Cloudy");
          break;
      
          case 'C':
            printf("Rainy");
            break;
        
          case 'R':
            printf("Sunny");
            break;
      
          default:
            printf("X");
            break;
        }
	
	return(0);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<vector<int>>v(N, vector<int>(256, 0));
	rep(i, 0, N) {
		string s; cin >> s;
		rep(j, 0, s.size())v[i][s[j]]++;
	}

	auto func = [&](char c, int n) {
		string ret;
		while (n--)ret += c;
		return ret;
	};
	string ans;
	rep(i, 0, 256) {
		int n(INF);
		rep(j, 0, N)chmin(n, v[j][i]);
		ans += func((char)i, n);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

//ll modexp(ll x, ll y, ll p)
//{
//	ll res = 1;
//	x = x % p;
//	while (y > 0)
//	{
//		if (y & 1)
//			res = (res * x) % p;
//		y = y >> 1;
//		x = (x * x) % p;
//	}
//	return res;
//}

//ll mulmod(ll a, ll b,ll m)
//{
//	return ((a % m) * (b % m)) % m;
// }

// ll sub_mod(ll a, ll b, ll m){
//    if (a >= b)
//        return a - b;
//    else
//        return m - b + a;
// }

// ll add_mod(ll a, ll b){
//    if (0 == b)
//        return a;

//    b = mod - b;
//    if (a >= b)
//        return a - b;
//    else
//        return mod - b + a;
// }

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

// ll modInv(ll a)
// {
//     ll g = gcd(a, mod);
//     if (g != 1)
//         return -1;
//     else
//         return modexp(a, mod-2, mod);
// }

int main()
{
	fastio;
    ll n=0;
    string s;
    cin>>n>>s;
    if(n&1)
        cout<<"No";
    else{
        string a="";
        for(ll i=0;i<n/2;++i){
            a+=s[i];
        }
        if(a+a==s)
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

int nums[100];

int main(){
	int n, p;
	while(cin >> n && n){
		rep(i, n){
			cin >> nums[i];
		}
		cin >> p;
		int l = 0, r = n - 1;
		int res = 0;
		while(r - l >= 0){
			res++;
			int mb = (l + r) / 2;
			if(nums[mb]==p) break;
			else if(nums[mb] > p) r = mb - 1;
			else l = mb + 1;
		}
		cout << res  << endl;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }

int violate[10][6] = {
	{-1},
	{2,3,6,8,9,-1},
	{3,6,9,-1},
	{-1},
	{2,3,6,8,9,-1},
	{-1},
	{-1},
	{2,3,6,8,9,-1},
	{3,6,9,-1},
	{-1},	
};

int dp[2][2][10][10];

bool check(int L, int R) {
	for (int j=0; violate[R][j] != -1; ++j) if (violate[R][j] == L) return false;
	return true;
}

int main() {
	string S;
	
	while (cin >> S, S != "#") {
		int m = S.size();
		
		for_(b,0,2) for_(L,0,10) for_(R,0,10) dp[0][b][L][R] = 1L << 30;
		dp[0][0][0][S[0] - '0'] = 0;
		dp[0][1][S[0] - '0'][0] = 0;
		
		for_(i,1,m) {
			int nLR = S[i] - '0';
			for_(b,0,2) for_(L,0,10) for_(R,0,10) dp[1][b][L][R] = 1L << 30;
			for_(b,0,2) for_(L,0,10) for_(R,0,10) {
				if (dp[0][b][L][R] == 1L << 30) continue;
				if (check(nLR, R)) minUpdate(dp[1][1][nLR][R], dp[0][b][L][R] + (b ? 1 : 0));
				if (check(L, nLR)) minUpdate(dp[1][0][R][nLR], dp[0][b][L][R] + (b ? 0 : 1));
			}
			swap(dp[0], dp[1]);
		}
		
		int ans = 1L << 30;
		for_(b,0,2) for_(L,0,10) for_(R,0,10) minUpdate(ans, dp[0][b][L][R]);
		cout << ans << endl;
		/*
		int L[2] = {0, 0}, R[2] = {0, 0}, cnt[2] = {0, 0};
		bool flag[2] = {false, true};
		
		for_(i,0,m) {
			for_(b,0,2) {
				int r = (flag[b] ? S[i] - '0' : R[b]), l = (flag[b] ? L[b] : S[i] - '0');
				bool inv = false;
				for (int j=0; violate[r][j] != -1; ++j) inv |= (violate[r][j] == l);
				
				if (inv) {
					if (flag[b]) L[b] = r;
					else R[b] = l;
					++cnt[b];
				} else {
					R[b] = r;
					L[b] = l;
					flag[b] = !flag[b];
				}
			}
		}
		cout << min(cnt[0], cnt[1]) << endl;
		*/
	}
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <string.h>
#include <math.h>
int main() {

    int n;
    scanf("%d", &n);

    int cnt = 1;
    long power = 1;
    while (cnt <= n) {
        power *= cnt;
        power %= (long)(pow(10, 9) + 7);

        //printf("%ld\n", power);
        cnt++;
    }
    

    printf("%ld", power);

    return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef std::bitset<404> set;
int n, m;
int x[maxn], y[maxn];
set s[maxn];
int good[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	rep(i, 1, m) {
		cin >> x[i] >> y[i];
	}
	rep(i, 1, n) {
		s[i].set(i);
		good[i] = 1;
		for(int j = m;j >= 1;--j) {
			if(s[i].test(x[j]) && s[i].test(y[j])) {
				good[i] = 0;
				break;
			} else {
				if(s[i].test(x[j])) s[i].set(y[j]);
				if(s[i].test(y[j])) s[i].set(x[j]);
			}
		}
	}
	int ans = 0;
	rep(i, 1, n) {
		rep(j, 1, i - 1) {
			ans += good[i] && good[j] && (s[i] & s[j]).none();
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 2688