akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, M; cin >> N >> M;
	if (N & 1) {
		for (int i = 1; i <= M; i++) {
			cout << i << " " << N-i+1 << el;
		}
	} else {
		int mm = M*2+1;
		int a = mm/2, b = mm-a;
		
		for (int i = 1; i <= a/2; i++) {
			cout << i << " " << a-i+1 << el;
		}
		for (int i = 1; i <= b/2; i++) {
			cout << a+i << " " << a+b-i+1 << el;
		}	
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve()
{
    ll n;
    cin >> n;
    ll a[n]; ll t = 0, f = 0;
    rep(i, n)
    {
        ll x; cin >> x;
        if(x%2 == 0)
        {
            if(x%4 == 0) f++;
            else t++;
        }
    }
    n -= t;
    n -= f; //cout << n;
    if(t == 0) cout << (n > f+1 ? "No" : "Yes");
    else cout << (n > f ? "No" : "Yes");
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <algorithm>

void CallMyFunc(std::istream &input_stream) {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  try {
    int32_t n, m;
    input_stream >> n >> m;
    int32_t worked_sum = 0;
    for (int32_t i = 0; i < m; ++i) {
      int32_t worked;
      input_stream >> worked;
      worked_sum += worked;
    }
    std::cout << std::max((n - worked_sum), -1);
  } catch (...) {
    std::cerr << "ERROR: CallQuickSort()" << std::endl;
    throw;
  }
}

int main() {
  CallMyFunc(std::cin);
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

const int MAXN = 100000 + 100;

int s, nr, nq;
queue<int> rev, quet, quea;
priority_queue<int, vector<int>, greater<int> > spe;

void work()
{
	int curt = 0, v1 = 0, x1 = 0, x2 = s, v2 = s, dir = -1;
	while(!spe.empty())
	{
		int next = spe.top(), diff = next - curt;
		spe.pop();
		if(dir < 0)
			v1 = max(0, v1 - diff), v2 = max(0, v2 - diff), x1 = x2 - (v2 - v1);
		else if(dir > 0)
			v1 = min(s, v1 + diff), v2 = min(s, v2 + diff), x2 = x1 + (v2 - v1);
		curt = next;
		if(!quet.empty() && quet.front() == curt)
		{
			int a = quea.front(), ans = 0;
			quet.pop(), quea.pop();
			// cerr << "q = " << curt << ' ' << a << endl;
			// cerr << v1 << ' ' << x1 << ' ' << v2 << ' ' << x2 << endl;
			if(0 <= a && a <= x1)
				ans = v1;
			else if(x1 < a && a < x2)
				ans = v1 + (a - x1);
			else if(x2 <= a && a <= s)
				ans = v2;
			cout << ans << endl;
		}
		if(!rev.empty() && rev.front() == curt)
			rev.pop(), dir = -dir;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> s;
	cin >> nr;
	for(int i = 1; i <= nr; i++)
	{
		int x;
		cin >> x;
		rev.push(x), spe.push(x);
	}
	cin >> nq;
	for(int i = 1; i <= nq; i++)
	{
		int x, y;
		cin >> x >> y;
		quet.push(x), quea.push(y), spe.push(x);
	}

	work();

	return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
using ld = long double;
long long x[maxn], y[maxn], a[maxn];
ld dist(int a, int b){
	return sqrtl((x[a] - x[b])*(x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
}
int uf[maxn];
void init(){
	iota(uf, uf + maxn, 0);
}
int find(int x){
	if(x == uf[x]) return x;
	return uf[x] = find(uf[x]);
}
ld val[1<<maxn], f[1<<maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> a[i];
	for(int i = 1; i < 1<<n; i++){
		vector<int> here;
		ld sum = 0;
		for(int j = 0; j < n; j++) if((i>>j)&1) sum += a[j], here.push_back(j);
		vector<tuple<ld, int, int> > edg;
		int sz = here.size();
		for(int j = 0; j < sz; j++) for(int g = j + 1; g < sz; g++){
			edg.push_back(make_tuple(dist(here[j], here[g]), here[j], here[g]));
		}
		sort(edg.begin(), edg.end());
		init();
		ld mst = 0;
		for(auto e : edg){
			ld w; int u, v; tie(w, u, v) = e;
			if(find(u) != find(v)){
				mst += w;
				uf[find(u)] = find(v);
			}
		}
		val[i] = max((sum - mst) / sz, (ld)0.);
	}
	for(int i = 1; i < 1<<n; i++){
		f[i] = val[i];
		for(int j = i & (i - 1); j; j = i & (j - 1)){
			f[i] = max(f[i], min(f[j], f[i ^ j]));
		}
	}
	cout << fixed << setprecision(12) << f[(1<<n) - 1] << endl;
	return 0;
}


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

int main(){
  	char s[1005];
  	cin>>s;
  	int i;
  	for(i=0; s[i+1]!='\0';i++);
  	if(s[i]!='s')
      cout<<s<<"s";
  	else
      cout<<s<<"es";
	return 0;
}

Measured memory_bytes: 3640
input()
s = input()
cs = s.split("+")
ns = []
ds = []
for c in cs:
    cont = False
    i = 0
    for a in ds:
        if(a == c):
            cont = True
            ns[i] += 1
            break
        i += 1
    if(not cont):
        ds.append(c)
        ns.append(1)
nums = [0 for i in range(9)]
for n in ns:
    nums[n - 1] += 1
res = 0
res += 2 * nums[0]
for i in range(1, 9):
    if(nums[i] >= 3):
        res += 2 * nums[i] + 4
    else:
        res += 4 * nums[i]
res -= 1
print(res)

Measured memory_bytes: 7588
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> x;
vector <int> y;
vector <int> v;
vector <long double>lengthV;
void checkLength(){
    // for(int i = 0; i < n; i++){
    //     cout << v[i];
    // }
    // cout <<endl;
    long double lenSum = 0;
    for(int i = 1; i < n; i++){
        long double xDiff = x[v[i]]-x[v[i-1]];
        long double yDiff = y[v[i]]-y[v[i-1]];
        xDiff*=xDiff;
        yDiff*=yDiff;
        long double length = xDiff+yDiff;
        length = sqrt(length);
        lenSum+=length;
    }
    lengthV.push_back(lenSum);
}
void dfs(int num){
    v.push_back(num);
    if(v.size()>1){
        for(int i = 0; i < v.size()-1; i++){
            if(v[i]==num)return;
        }
    }
    if(v.size()>=n){
        checkLength();
        return;
    }
    for(int i = 0; i < n; i++){
        dfs(i);
        v.pop_back();
    }
}
int main(){
    cin >> n;
    x = vector <int> (n);
    y = vector <int> (n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < n; i++){
        dfs(i);
        v.pop_back();
    }
    long double ans = 0;
    for(int i = 0; i < lengthV.size(); i++){
        //cout << lengthV[i] << endl;
        ans += lengthV[i];
    }
    ans/=lengthV.size();
    cout << fixed << setprecision(10) <<ans << endl;
    return 0;
}

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

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

    if(C * 2 > A+B) {
        cout << A*X + B*Y;
    } else {
        int pos = max(X, Y);
        int neg = min(X, Y);
        if(X > Y) cout << min(C * pos * 2, C * neg * 2 + (pos - neg) * A); 
        if(Y > X) cout << min(C * pos * 2, C * neg * 2 + (pos - neg) * B); 
        if(Y == X) cout << C * pos * 2; 

    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int ans, a, b, num;
	
	while (cin >> a >> b){
		ans = 1;
		num = a + b;

		while (num >= 10){
			num /= 10;
			ans++;
		}

		cout << ans << endl;

	}
	return (0);
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    cin>>s;
    int now = 0;
    rep(i,s.size()){
        if(s[i]=='+') now++;
        else now--;
    }
    cout<<now<<endl;
    return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

for i in range(K):
  if(i%2==0):
    if(A%2==1):
      A=A-1
    C=int(A/2)
    A=C
    B=B+C
  else:
   if(B%2==1):
     B=B-1
   C=int(B/2)
   B=C
   A=A+C

print(A,B)


Measured memory_bytes: 2940
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

d :: [Int] -> [Int] -> Int
d an cn = (abs (a-c)) + (abs (b-d))
        where a = an !! 0
              b = an !! 1
              c = cn !! 0
              d = cn !! 1
              
mapd an cns = [d an cn | cn <- cns]

solve ab cdn = 1 + (f ( findIndex(==l) (mapd ab cdn)) )
               where l = minimum $ mapd ab cdn
             
f :: Maybe Int -> Int
f (Just x) = x
f x = 0

main = do
    [n,m] <- map bsreadInt . BC.words <$> BC.getLine
    abn <- map ((map bsreadInt . BC.words)) <$> replicateM n BC.getLine
    cdn <- map ((map bsreadInt . BC.words)) <$> replicateM m BC.getLine
    let ans = [solve (abn!!i) cdn | i <- [0..(n-1)]]
    mapM_ print ans

Measured memory_bytes: 892
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;

ll h,w;
ll ans;
//vector<char> masu;


int main(){
  long double l;

  cin >>l;

  long double ans = l * l *  l/ 27.00;
  

  cout <<setprecision(20)<<ans<<endl;
  
}


Measured memory_bytes: 256
#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() {
    string s;
    cin >> s;

    ll ans = 0;
    ll cntR = 0, cntL = 0;
    rep(i, s.size()) {

        if(s[i] == '<') {
            cntR++;
        }
        else {
            cntL++;
        }

        if(i+1 < s.size() && s[i] == '>' && s[i+1] == '<') {
            ll a = max(cntR, cntL);
            ll b = min(cntR, cntL);
            ans += ( a*(a+1) + b*(b-1) ) / 2;
            cntR = 0;  cntL = 0;
        }

    }

    ll a = max(cntR, cntL);
    ll b = min(cntR, cntL);
    ans += ( a*(a+1) + b*(b-1) ) / 2;    

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

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n,a,b,sum=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        int c = i;
        int k = 0;
        while(c>0){
            k += c%10;
            c /= 10;
        }
        if(a<=k&&k<=b) sum += i;
    }
    cout << sum << endl;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }

int main() {
  ll N;
  scanf("%lld", &N);

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= N; j++) {
      for (ll k = 1; k <= N; k++) {
        ll v = gcd(gcd(i, j), k);
        ans += v;
      }
    }
  }

  cout << ans << endl;
}


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

int main(){
	int H,W; cin>>H>>W;
	char c[100][100];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cout<<c[i][j];
          if(j==W-1){
            cout<<endl;
            for(int j=0;j<W;j++){
              cout<<c[i][j];
            }
          }
		}
      cout<<endl;
    }
	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  double n,d;
  const int max_n = 2 * 1e5;
  cin >> n >> d;
  double x[max_n + 1], y[max_n + 1];
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

  int cnt = 0;
  for(int i = 0; i < n; i++){
    if(sqrt((x[i]*x[i]) + (y[i]*y[i])) <= d) cnt ++;
  }
  cout << cnt << endl;


  return 0;
}

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

int main(){
  int N,X,A;
  cin >> N >> X;
  A = 1;
  vector<int> L(N),D(N+1);
  D.at(0) = 0;
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  for(int i=0;i<N;i++){
    D.at(i+1) = D.at(i) + L.at(i);
    if(D.at(i+1) > X){
      break;
    }
    A++;
  }
  cout << A;
}

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

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

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

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

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

using namespace output;

template<class T> struct Seg { 
	const T ID = INF; // comb(ID,b) must equal b
	T combine(T a, T b) { return min(a, b);} 
	int n; vector<T> seg;
	void init(int _n) { n = _n; seg.assign(2*n,ID);}

	void update(int p, T value) {	// set value at position p
		seg[p += n] = value;
		for (p /= 2; p; p /= 2) seg[p] = combine(seg[2*p], seg[2*p+1]);
	}
    
	T query(int l, int r) {	 // sum on interval [l, r]
		T ra = ID, rb = ID; 
		for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
			if (l&1) ra = combine(ra,seg[l++]);
			if (r&1) rb = combine(seg[--r],rb);
		}
		return combine(ra,rb);
	}
};

Seg<ll> seg;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, x; cin >> N >> x;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	seg.init(2 * N);
	F0R(i, N) {
		seg.update(i, arr[i]);
		seg.update(i + N, arr[i]);
	}
	ll ans = INF;
	F0R(rot, N) {
		ll subans = 0;
		F0R(i, N) {
			subans += seg.query(i+N-rot,i+N);
		}
		ans = min(ans, subans + 1LL * x * rot);
	}
	print(ans);
}

Measured memory_bytes: 384
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
al = inpl()
ans = 0
tmp = 0
pre = al[0]
for a in al:
    if(pre > a):
        ans += pre - a
    else:
        pre = a
print(ans)
        


Measured memory_bytes: 97204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int l = 0, r = n;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    chmax(l, a);
    chmin(r, b);
  }
  cout << max(r-l, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,C = map(int,input().split())
K = int(input())

max_num = max(A,B,C)
if A == max_num:
  print(A * (2 ** K) + B + C)
elif B == max_num:
  print(B * (2 ** K) + A + C)
else:
  print(C * (2 ** K) + B + A)

Measured memory_bytes: 8972
"use strict"
let fs = require('fs');
let input = fs.readFileSync("/dev/stdin", "utf8").split(/\n/);

const inputRow = input[0].split(' ').map(mp => +mp);
const B = input[1].split(' ').map(mp => +mp);  
let rowSum = 0;
let count = 0;

for(let i=2; i < inputRow[0]+2; i++) {
  for(let j=0; j < inputRow[1]; j++) {
    rowSum += (Number(input[i].split(' ')[j]) * B[j]);
    if(j === inputRow[1] - 1) rowSum += inputRow[2];
  }
  count += rowSum > 0 ? 1 : 0;
  rowSum = 0;
}

console.log(count);


Measured memory_bytes: 11468
#include <stdio.h>
#define MAX 100005
#define NIL -1
struct Nodes{
    int parent;
    int left;
    int right;
};
 
struct Nodes Node[MAX];
int Depth[MAX];
int Height[MAX];
 
int getS(int a){
    if(Node[a].parent == NIL)return NIL;
    if(Node[Node[a].parent].left!=a && Node[Node[a].parent].left != NIL){
        return Node[Node[a].parent].left;
    }
    if(Node[Node[a].parent].right!=a && Node[Node[a].parent].right != NIL){
        return Node[Node[a].parent].right;
    }
    return NIL;
}
void setD(int a,int b){
    if(a==NIL) return;
    Depth[a]=b;
    setD(Node[a].left,b+1);
    setD(Node[a].right,b+1);
}
 
int setH(int x){
  int a=0,b=0;
    if(Node[x].left!=NIL){
        a=setH(Node[x].left)+1;
    }
    if(Node[x].right!=NIL){
        b=setH(Node[x].right)+1;
    }
    if(a>b){
      return Height[x]=a;
    }else{
    return Height[x]=b;
    }
}
 
int main(){
  int left,right,a,n,root = 0,i,deg;
  scanf("%d",&n);
    for(i=0;i<n;++i){
        Node[i].parent=Node[i].left=Node[i].right = NIL;
    }
     
    for(i=0;i<n;++i){
      scanf("%d %d %d",&a,&left,&right);
        Node[a].left = left;
        Node[a].right = right;
        if(left!=NIL){
            Node[left].parent = a;
        }
        if(right!=NIL){
            Node[right].parent = a;
        }
    }
    for(i=0;i<n;++i){
        if(Node[i].parent==NIL){
            root=i;
        }
    }
    setD(root,0);
    setH(root);
     
    for(i=0;i<n;++i){
      printf("node %d: parent = %d, sibling = %d,"
	     ,i,Node[i].parent,getS(i));
      deg=0;
      if(Node[i].left!=NIL)deg++;
      if(Node[i].right!=NIL)deg++;
      printf(" degree = %d, depth = %d, height = %d,"
	     ,deg,Depth[i],Height[i]);
      if(Node[i].parent == NIL){
	printf(" root\n");
      }else if(Node[i].left==NIL&&Node[i].right==NIL){
	printf(" leaf\n");
      }else{
	printf(" internal node\n");
      }
    }
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
		using namespace std;
		#define ll int
		#define INF 100000000LL
		#define mod 1000000007
		#define pll pair<long,long>
		#define se second
		#define fi first
		#define pb push_back
		#include <ext/pb_ds/assoc_container.hpp>
		#include <ext/pb_ds/tree_policy.hpp>
		using namespace __gnu_pbds;

		typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
		typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update>pllordered_set;


		ll vis[100050][3];
		vector<ll> g1[100050];

		int main()
		{
					ios_base::sync_with_stdio(false);
					cin.tie(NULL);
					ll n,m;
					cin>>n>>m;
					ll dist[105][105];
					vector<tuple<ll,ll,ll> > edge;
					for(ll i=0;i<=n;i++)
					{
						for(ll j=0;j<=n;j++)
							dist[i][j]=INF;
					}
					for(ll i=0;i<=n;i++)
						dist[i][i]=0;
					for(ll i=0;i<m;i++)
					{
						ll u,v,w;
						cin>>u>>v>>w;
					//cout<<dist[u][v]<<" "<<dist[v][u]<<endl;
						dist[u][v]=w;
						dist[v][u]=w;
						edge.pb(make_tuple(u,v,w));
					}
					
					for(ll k=1;k<=n;k++)
					{
						for(ll i=1;i<=n;i++)
						{
							for(ll j=1;j<=n;j++)
							{
								if(dist[i][k]+dist[k][j]<dist[i][j])
								{
									dist[i][j]=dist[i][k]+dist[k][j];
								}
								
							}
						}
						
					}
					ll ans=0;
					for(auto i:edge)
					{
						ll u=get<0>(i);
						ll v=get<1>(i);
						ll w=get<2>(i);
						
						if(dist[u][v]<w)
						{
						//	cout<<u<<" "<<v<<" "<<dist[u][v]<<endl;
							ans++;
						}
					}
					
					cout<<ans;
					
					
		}


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

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

    sort(all(A));
    int posi = 0, nega = 0;
    rep(i, N) {
        posi += A[i] > 0;
        nega += A[i] < 0;
    }

    ll low = -LINF, high = LINF;
    while (high - low > 1) {
        ll mid = (low + high) / 2;
        ll k = 0;
        rep(i, N) {
            if (A[i] == 0) {
                if (mid > 0) k += N - 1;
            }
            else {
                ll t = 0;
                int j = 0;
                if (mid >= 0) {
                    if (A[i] > 0) {
                        t = (abs(mid) + abs(A[i]) - 1) / abs(A[i]);
                        j = lower_bound(all(A), t) - A.begin();
                    }
                    else {
                        t = (abs(mid) + abs(A[i]) - 1) / abs(A[i]);
                        j = A.end() - upper_bound(all(A), -t);
                    }
                }
                else {
                    if (A[i] > 0) {
                        t = (abs(mid)) / abs(A[i]);
                        j = lower_bound(all(A), -t) - A.begin();
                    }
                    else {
                        t = (abs(mid)) / abs(A[i]);
                        j = A.end() - upper_bound(all(A), t);
                    }
                }
                k += A[i] * A[i] < mid ? j - 1 : j;
            }
        }
        if (k / 2 >= K) high = mid;
        else low = mid;
    }
    write(low);
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
pair <int,int> rotate (pair<int,int>,pair<int,int>);
 
int main() {
    pair <int,int> p1, p2, p3,p4;
    cin >> p1.first >> p1.second >> p2.first >> p2.second;
    p3 = rotate(p1,p2);
    p4 = rotate(p2,p3);
    cout << p3.first << ' ' << p3.second << ' ';
    cout << p4.first << ' ' << p4.second << endl;

}
pair <int, int> rotate(pair<int,int> s,pair<int,int> t) {
    pair <int,int> p;
    p.first = s.second - t.second + t.first;
    p.second = t.second - s.first + t.first;
    return p;
}

Measured memory_bytes: 3168
from bisect import bisect_left, bisect

n=int(input())
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i)) #iの挿入点つまりiより小さい値の数×(Cの総数-
print(ans)

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

int main()
{
    string s;
    cin>>s;
    int l=0;
    int r=s.size()-1;
    int c=0;
    while(l<r)
    {
        if(s[l]==s[r])
        {
            l++;
            r--;
        }
        else
        {
            c++;
            l++;
            r--;
            
        }
    }
    cout<<c;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

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

    auto is_ok = [](std::string last_four) {
        for (int i = 0; i < 4; i++) {
            std::string t = last_four;
            if (i < 3) {
                std::swap(t[i], t[i + 1]);
            }

            if (t.find("AGC") != std::string::npos) {
                return false;
            }
        }
        return true;
    };

    std::vector<std::unordered_map<std::string, long long>> dp(n + 1);
    auto dfs = [&](auto f, int idx, std::string last_three) -> long long {
        if (idx == n) {
            return 1;
        }

        if (dp[idx].count(last_three) > 0) {
            return dp[idx][last_three];
        }

        long long val = 0;
        for (auto c : { 'A', 'G', 'C', 'T' }) {
            if (is_ok(last_three + c)) {
                val += f(f, idx + 1, last_three.substr(1, 2) + c) % mod;
                val %= mod;
            }
        }

        dp[idx][last_three] = val;
        return val;
    };

    std::cout << dfs(dfs, 0, "TTT") << std::endl;
}


Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int d = a<b?a:b;

		ArrayList<Integer> foo = new ArrayList<>();

		for(int i=1;i<=d;i++) {

			if(a%i==0 && b%i==0)
				foo.add(i);
		}
		Collections.sort(foo, Collections.reverseOrder());
		System.out.println(foo.get(c-1));
	}
}



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

int n;
double dp[3001][3001];

signed main()
{
	cin>>n;
	double p[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
	}
	dp[1][0]=1-p[1];
	dp[1][1]=p[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
		}
	}
	double ans=0;
	for(int k=n/2+1;k<=n;k++)
	{
		ans+=dp[n][k];
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
}

Measured memory_bytes: 68992
function main(input) {
  var N = input[0]-0;
  var ans = input.filter((v,i)=>i>0).map(v=>v.split(" ")[1]-v.split(" ")[0]+1).reduce((a,b)=>a+b);
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 21304
import java.util.*;
 
public class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String[] str_list = {"a","i","u","e","o"};
    if (Arrays.asList(str_list).contains(a)) {
      System.out.println("vowel");
    } else {
      System.out.println("consonant");
    }
  }
}

Measured memory_bytes: 35584
#import<iostream>
#define a 1LL<<64-__builtin_clzll
long long A,B,C,i;main(){std::cin>>A>>B;if(A^B){C=(a(A^B))-1;A&=C;B&=C;i=++C>>1;B=(B-i)?(a(B-i))-1:0;C=C-A-(A>B)*(A-1-B);std::cout<<C;}else puts("1");}

Measured memory_bytes: 256
#include <stdio.h>

void sort(int a[], int n){
  int b, i, j = 0, k = 1;//0~j-1 small j~k-1 equal k~i-1 big i~ unsorted
  b = a[0];
  if(n <= 1) return;
  for (i = 1; i < n; i++) {
    if(a[i] < b){
      a[j] = a[i];
      a[i] = a[k];
      a[k] = b;
      j++;
      k++;
    }else if(a[i] == b){
      a[i] = a[k];
      a[k] = b;
      k++;
    }
  }
  sort(a, j);
  sort(a+k, n-k);
  return;
}

void main() {
  int n, ans = 0;
  scanf("%d", &n);
  int a[n*2];
  for (int i = 0; i < n*2; i++) {
    scanf("%d", a+i);
  }
  sort(a, n*2);
  for (int i = 0; i < n; i++) {
    ans += a[i*2];
  }
  printf("%d\n", ans);
  return;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = in.nextIntArray(N);
            int[] B = in.nextIntArray(N);
            int[] C = in.nextIntArray(N - 1);

            long sum = 0;
            int prev = -2;
            for (int i = 0; i < N; i++) {
                int n = A[i] - 1;
                sum += B[n];
                if (prev + 1 == n) {
                    sum += C[prev];
                }
                prev = n;
            }
            out.println(sum);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 22868
X = int(input())

def is_prime(x):
    if x < 4:
        return True
    
    if (x % 2 == 0) or (x % 3 == 0):
        return False
  
    for i in range(5, int(x**0.5)+1):
        if x % i == 0:
            return False
    
    return True
  
ans = None
while True:
    if is_prime(X):
        print(X)
        break
    else:
        X += 1

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100000+10;
int n;
LL a[N],b[N];

priority_queue<LL> q;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
	
	LL sum=0,ans=0;
	for (int i=1;i<=n;i++)
		if (a[i]>b[i]) q.push(a[i]-b[i]);
		else if (a[i]<b[i]) {
			sum+=b[i]-a[i];
			ans++;
		}
	
	while (sum>0) {
		if (q.empty()) { puts("-1"); return 0; }
		sum-=q.top(); q.pop();
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2428
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n;
    long nums[200];
    REP(i, n)
    {
        cin >> nums[i];
    }

    //2で割れる回数を数える
    int min = INFINITY;
    REP(i, n)
    {
        while (nums[i] % 2 == 0 && nums[i] != 0)
        {
            nums[i] = nums[i] / 2;
            count++;
        }
        if (min > count)
            min = count;

        count = 0;
    }
    cout << min << endl;

    //-----------
    cin >> Z;
    return 0;
}

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

int N1 = 0;


bool solve(int i, int m,int* A) {
	if (m == 0)
		return true;
	if (i >= N1)
		return false;


	return solve(i + 1, m,A) || solve(i + 1, m - A[i],A);
}

int main(void) {

	cin >> N1;
	int* A = new int[N1];
	for (int i = 0; i < N1; i++) {
		cin >> A[i];
	}
	int N2 = 0; cin >> N2; int* B = new int[N2];
	for (int i = 0; i < N2; i++) {
		cin >> B[i];	
	}

	for (int i = 0; i < N2; i++) {
		if (solve(0, B[i],A))
			cout <<  "yes\n";
		else
			cout << "no\n";
	}
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
ll n;
int A,B,C,D;
map<ll,ll> mp;

ll Func(ll x){
	if (x==0) return 0;
	if (x==1) return D;
	if (mp.count(x)) return mp[x];
	
	ll y,t; mp[x]=1ll<<60;
	
	
	if (1e18/D>x) mp[x]=x*D;
	
	for (t=0,y=x;y%2!=0;y++,t++);
	mp[x]=min(mp[x],(y/2?Func(y/2)+A:0)+t*D);
	for (t=0,y=x;y%2!=0;y--,t++);
	mp[x]=min(mp[x],(y/2?Func(y/2)+A:0)+t*D);
	
	for (t=0,y=x;y%3!=0;y++,t++);
	mp[x]=min(mp[x],(y/3?Func(y/3)+B:0)+t*D);
	for (t=0,y=x;y%3!=0;y--,t++);
	mp[x]=min(mp[x],(y/3?Func(y/3)+B:0)+t*D);
	
	for (t=0,y=x;y%5!=0;y++,t++);
	mp[x]=min(mp[x],(y/5?Func(y/5)+C:0)+t*D);
	for (t=0,y=x;y%5!=0;y--,t++);
	mp[x]=min(mp[x],(y/5?Func(y/5)+C:0)+t*D);
	
	return mp[x];
}
void solve(){
	scanf("%lld%d%d%d%d",&n,&A,&B,&C,&D);
	mp.clear();
	printf("%lld\n",Func(n));
}
int main(){
	int T;
	scanf("%d",&T);
	while (T--) solve();
}

Measured memory_bytes: 4620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println((in.nextInt() - 1) * (in.nextInt() - 1));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int A,B;

int main()
{
    scanf("%d%d",&A,&B);
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)printf("Possible\n");
    else printf("Impossible\n");
    return 0;
}


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

int main() {
    ll n,m,v,p;
    std::cin >> n>>m>>v>>p;
    vector<ll> a(n);
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    sort(a.rbegin(),a.rend());
    
    ll l = p-1; //ok
    ll r = n; //ng?
    while(r-l>1){
        // std::cout << l<<" "<<r << std::endl;
        ll mid = (r+l)/2;
        
        // 論外
        if( a[mid]+m < a[p-1] ){
            r = mid;
            continue;
        }
        
        if( p>=v ){
            l =mid;
            continue;
        }
        
        ll rem = m*(v-p+1);
        // std::cout << "rem "<<rem << std::endl;
        
        for (int i = p-1; i < n; i++) {
            rem -= min(m,max((ll)0,a[mid]+m-a[i]));
        }
        
        if(rem<=0){
            l = mid;
        }else{
            r = mid;
        }
        
        
    }
    ll ans= a[l];
    
    sort(a.begin(),a.end());
    
    ll more = distance(a.begin(),lower_bound(a.begin(),a.end(),ans));
    
    std::cout << n-more << std::endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int L, R;
    cin >> L >> R;
    vector<bool> is_ok(2019, false);
    int count = 0;
    REP(i, L, R + 1) {
        if (is_ok[i % 2019] == false) {
            is_ok[i % 2019] = true;
            count++;
        }
        if (count >= 2019) {
            break;
        }
    }
    int ans = INF;
    rep(i, 2019) {
        REP(j, i + 1, 2019) {
            if (is_ok[i] == true && is_ok[j] == true) {
                ans = min(ans, (i * j) % 2019);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int INF=100000;
int N,M;

int row[100000];
int v[100000];
int z[100000];
bool C(int x){
    int cnt=0;
    for(int i=0;i<N-M;i++)cnt+=(z[i]>=v[x]);
    deque<int>Deq;

    for(int i=0;i<N;i++){
        if(row[i]){
            if(row[i]>=v[x])Deq.push_back(0);
            else Deq.push_back(INF);
        }
        else{
            Deq.push_back(1);
        }
    }

    while(Deq.size()!=1){
        int a=Deq.front();Deq.pop_front();
        int b=Deq.front();Deq.pop_front();
        int c=Deq.front();Deq.pop_front();

        Deq.push_back(a+b+c-max(a,max(b,c)));
    }
    return Deq.front()<=cnt;

}
int main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int d,p;
        cin>>d>>p;
        row[--p]=d;
        v[i]=d;
    }
    for(int i=M;i<N;i++)cin>>v[i],z[i-M]=v[i];
    sort(v,v+N);

    int lb=0,ub=N;

    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))lb=mid;
        else ub=mid;
    }

    cout<<v[lb]<<endl;
    return 0;
}

Measured memory_bytes: 2720
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
#https://atcoder.jp/contests/abc146/tasks/abc146_d
#D - Coloring Edges on Tree
"""
for each edge, keep track of parent, and each edges color
while we are BFSing, we can just iterate from 1, and skip if the next one is same as parents
"""

# reads a single line
N = gi()
ecs = {}
nbls = [[] for i in range(N + 5)]  #[] * N won't work
p = [0] * (N + 5)
in_l = []

max_d = 0

for i in range(1, N):
    a = gi()
    b = gi()
    nbls[a].append(b)
    nbls[b].append(a)
    max_d = max(max_d, len(nbls[a]), len(nbls[b]))
    in_l.append((min(a, b), max(a, b)))
p[1] = 0  #sentinel node to keep code clean
ecs[(0, 1)] = -1

c_i = 0
q = deque()
q.append(1)

while len(q):
    v = q.pop()
    #by the time we reach the node, the parent edge of this node has been colored
    parent_ci = ecs[(min(v, p[v]), max(v, p[v]))]
    for u in nbls[v]:
        if u == p[v]:
            continue
        q.append(u)
        p[u] = v
        if parent_ci == c_i:
            c_i += 1
            c_i %= max_d
        ecs[(min(u, v), max(u, v))] = c_i
        c_i += 1
        c_i %= max_d

print(max_d)
for e in in_l:
    print(ecs[e] + 1)


Measured memory_bytes: 53216
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>

using namespace std;

const int N = 1e9 + 5;
int n;

int main() {
    cin >> n;
    int max1 = 0, min1 = N * 2, max2 = 0, min2 = N * 2;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        max1 = max(max1, x + y);
        min1 = min(min1, x + y);
        max2 = max(max2, N - x + y);
        min2 = min(min2, N - x + y);
    }
    cout << max(max1 - min1, max2 - min2) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(){
  int i,n;
  double min,max,sum,ave;
  double data[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&data[i]);
  }
  max=data[0];
  min=data[0];
  for(i=0;i<n;i++){
    sum+=data[i];
    if(data[i]>max){
      max=data[i];
    }
    if(data[i]<min){
      min=data[i];
    }
  }
  printf("%.0lf %.0lf %.0lf\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 2796
#include<stdio.h>
#include<string.h>
int main()
{
    char s[110];
    int n;
    int i;
    int true=1;
    scanf("%d",&n);

    scanf("%s",s);
    if(n%2==1){
        printf("No\n");
        return 0;
    }
    for(i=0;i<n/2 && true==1;i++){
        if(s[i]!=s[n/2+i])
            true=0;
    }
    if(true==1)
        printf("Yes\n");
    else
    {
        printf("No\n");
    }
    

    return 0;
}


Measured memory_bytes: 128
class BinaryIndexedTree
  def initialize(n)
    @n   = n
    @bit = Array.new(n + 1){ 0 }
  end

  def sum(i)
    res = 0
    while i > 0
      res += @bit[i]
      i -= ( i & -i )
    end
    res
  end

  def add(i, x)
    i += 1
    while i <= @n
      @bit[i] += x
      i += ( i & -i )
    end
  end
end

n, q = gets.split.map { |e| e.to_i }
a    = gets.split.map { |e| e.to_i }

bit = BinaryIndexedTree.new(n)
a.each_with_index { |e, i| bit.add(i, e) }

q.times do
  query = gets.split.map { |e| e.to_i }
  
  if query[0] == 0
    _, q, x = query
    bit.add(q, x)
  else
    _, l, r = query
    puts bit.sum(r) - bit.sum(l)
  end
end

Measured memory_bytes: 56544