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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];  
  ll all = accumulate(ALL(a), 0ll);
  rep(i, n) {
    ll del = min(a[i], b[i]);
    a[i] -= del;
    b[i] -= del;
    a[i+1] -= min(a[i+1], b[i]);
  }
  ll del = accumulate(ALL(a), 0ll);
  cout << all-del << endl;
}

Measured memory_bytes: 1920
#!/usr/bin/env python3
import sys


def solve(M: "List[int]", D: "List[int]"):
    if M[0] != M[1]:
        print(1)
    else:
        print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = [int()] * (2)  # type: "List[int]"
    D = [int()] * (2)  # type: "List[int]"
    for i in range(2):
        M[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(M, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);

    int sum = 0, kosu = 0, cnt = 0;

    int s, k;
    while (scanf("%d,%d", &s, &k) != EOF)
    {
        sum += s * k;
        kosu += k;
        cnt++;
    }

    cout << sum << "\n"
         << round((double)kosu / cnt) << endl;
    return 0;
}


Measured memory_bytes: 3416
#include<cstdio>
#include<algorithm>
using namespace std;
int n,X[1005],Y[1005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&X[i],&Y[i]);
	int fg=abs(X[1]+Y[1])&1;
	for(int i=2;i<=n;++i)
		if(fg!=(abs(X[i]+Y[i])&1))
			return puts("-1"),0;
	printf("%d\n",32-fg);
	for(int i=30;~i;--i)printf("%d ",1<<i);
	if(!fg){
		putchar('1');
		for(int i=1;i<=n;++i)++X[i];
	}
	puts("");
	for(int i=1;i<=n;++i){
		int x=X[i],y=Y[i];
		for(int j=30;~j;--j)
			if(abs(x)>=abs(y))
				if(x>0)putchar('R'),x-=1<<j;
				else putchar('L'),x+=1<<j;
			else
				if(y>0)putchar('U'),y-=1<<j;
				else putchar('D'),y+=1<<j;
		if(!fg)putchar('L');
		puts("");
	}
	return 0;
}


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

int main(){
	ll N, sum = 0; cin >> N;
	ll A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
		sum += A[i];
	}
	if(sum % (N*(N+1)/2) == 0){
		ll cnt = sum/(N*(N+1)/2), chk = 0;
		for(int i=0; i<N; i++){
			ll gap = A[(i+1)%N] - A[i];
			if((cnt-gap)%N == 0 && 0 <= (cnt-gap)/N && (cnt-gap)/N <= cnt){
				chk += (cnt-gap)/N;
			}else{
				cout << "NO" << "\n";
				return 0;
			}
		}
		if(chk == cnt) cout << "YES" << "\n";
		else cout << "NO" << "\n";
	}else{
		cout << "NO" << "\n";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

ll dp[105][2*N];
int main(){
	int n,w;
	cin>>n>>w;
	vector<int> wei(n);
	vector<int> val(n);
	REP(i,n){
		cin>>wei[i]>>val[i];
	}
	REP(i,2*N){
		dp[0][i]=0;
	}
	REP(i,n){
		REP(j,w+1){
			if(j>=wei[i]){
				dp[i+1][j]=max(dp[i][j-wei[i]]+val[i],dp[i][j]);
			}else{
				dp[i+1][j]=dp[i][j];
			}
			//OUT(dp[i+1][j]);
		}
	}

	OUT(dp[n][w]);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 998244353
#define all(x) x.begin(), x.end()

struct SegTree{ //Current implementation is range sum.
    struct ra{ll l, r;};
    vi st;
    SegTree(ll N){
        st.resize(4*N, -1ll);
    }
    void update(ll node, ra R, ra T, ll delta){
        if(R.r < T.l or T.r < R.l) return;
        if(T.l <= R.l and R.r <= T.r){
            st[node] = max(st[node], delta); //Change here as reqd! (2)
            return;
        }
        ll m = (R.l + R.r) / 2;
        update(node*2,{R.l,m},T,delta);
        update(node*2+1,{m+1,R.r},T,delta);
        st[node] = max(st[node*2], st[node*2+1]); //Change here as reqd! (3)
        return; 
    }
    ll query(ll node, ra R, ra T){
        if(R.r < T.l or T.r < R.l) return -1ll;
        if(T.l <= R.l and R.r <= T.r) return st[node];
        ll m = (R.l + R.r) / 2;
        return max(query(node*2,{R.l,m},T), query(node*2+1,{m+1,R.r},T));
        //Change here as reqd! (4)
    }
};

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

    ll N; cin >> N;
    
    vii A(N);
    for(auto &i : A)
        cin >> i.first >> i.second;
    
    sort(all(A));
    
    SegTree Val(N);

    vi CC(N + 5); CC[N] = 1;

    for(ll x = N - 1; x >= 0; x--){
        ll t = A[x].first + A[x].second;
        ll l = lower_bound(all(A), make_pair(t, -5ll)) - A.begin();

        ll r = Val.query(1, {0, N-1}, {x, l-1});
        r = max(r, x);
        CC[x] = (CC[x+1] + CC[r+1]) % MOD;
        Val.update(1, {0, N-1}, {x, x}, r);
    }

    cout << CC[0] << endl;

    return 0;
}

Measured memory_bytes: 11264
let nl = readLine()!.split(separator: " ").map { Int($0)! }
let n = nl[0], m = nl[1], q = nl[2]
var a = [Int](repeating: 0, count: q), b = a, c = a, d = a
var maybeMax = 0
for i in 0..<q {
  let s = readLine()!.split(separator: " ").map { Int($0)! }
  a[i] = s[0]; b[i] = s[1]; c[i] = s[2]; d[i] = s[3]
}

func solve(range: ClosedRange<Int>, f: [Int] = []) {
  if f.count != n {
    for i in range {
      solve(range: i...range.upperBound, f: f + [i])
    }
  } else {
    var t = 0
    for i in 0..<q {
      if f[b[i] - 1] - f[a[i] - 1] == c[i] {
        t += d[i]
      }
    }
    maybeMax = max(t, maybeMax)
  }
}
solve(range: 1...m)
print(maybeMax)

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

void call(int n){
	int i = 1, x;
	do{
		x = i;
		if(x % 3 == 0){
			cout << " " << i;
		}else{
			do{
				if(x % 10 == 3){
					cout << " " << i;
					break;
				}
				x /= 10;
			}while(x);
		}
	}while(++i <= n);
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	
	return 0;
}

Measured memory_bytes: 3104
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int N,M;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	if(N==1) {
		printf("%d\n",M);
		return 0;
	}
	int ans=1;
	for(int i=2;i*i<=M;i++)
		if(M%i==0) {
			int tmp=M/i;
			if(tmp/N>0)
				ans=max(ans,i);
			if(i/N>0)ans=max(ans,tmp);
		}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 1728
#include<stdio.h>
#include<math.h>
#define Pi 3.1415926535897932384626433
int main(){
int H,M,A,B,J;
double t,n,b,ans,cout;
 scanf("%d %d %d %d",&A,&B,&H,&M);
t=M/2.0;
n=30*H+t;
J=6*M;
ans=fabs(n-J);
if(ans>=180) ans=360-ans;
b=(ans*Pi)/180;
cout=sqrt(A*A+B*B-2*A*B*cos(b));
printf("%.20lf",cout);
return 0;
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    int a,b; cin>>a>>b;
    cout<<b*2-a<<endl;
}


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

int main(){
	int n, l;
	scanf("%d", &n);
	scanf("%d", &l);
	int a[n];
	for(int i = 0; i <n; i++) scanf("%d", &a[i]);
	int st = -1;
	for(int i = 0; i < n-1; i++){
		if(a[i] + a[i+1] >= l){
			st = i;
		}
	}
	if(st == -1){
		printf("Impossible\n");
	} else {
		printf("Possible\n");
		for(int i = 0; i < st; i++){
			printf("%d\n", i+1);
		}
		for(int i = n-2; i >= st; i--){
			printf("%d\n", i+1);
		}
	}
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
using namespace std;
typedef long long int ll;

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

int main() {
	//input
	ll N;
	cin >> N;

	if (N == 0) {
		cout << 0; return 0;
	}

	vector<char> S(0);
	while (true) {
		if (N < 0 && abs(N) % 2 == 1) {
			S.push_back('1');
			N = (N - 1) / -2;
		}
		else {
			if (abs(N) % 2 == 1) {
				S.push_back('1');
			}
			else {
				S.push_back('0');
			}
			N /= -2;
		}

		if (N == 1) {
			S.push_back('1');
			for (int i = S.size() - 1; i >= 0; i--) {
				cout << S[i];

			}
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int n,A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1, m-A[i]);
    return res;
}

int main(){
    int q,M,i;

    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0; i<q; i++){
        scanf("%d",&M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2604
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		String S = sc.next();
		boolean ans = true;
		
		for(int i = 0; i < S.length(); i++){
			char c = S.charAt(i);
			if(i == A && c != '-') ans = false;
			else if(i != A && c < '0' || c > '9') ans = false;
		}
		
		System.out.println(ans?"Yes":"No");
	}
}

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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const long long inf = (long long) 1e18;
const int mod = (int) 1e9 + 7;

inline void add(int& a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

class fenwick {
 public:
  int n;
  vector<int> f;

  fenwick(int _n) : n(_n) {
    f.resize(n);
  }

  inline void agg(int x, int y) {
    for (int i = x; i < n; i = i | (i + 1)) {
      add(f[i], y);
    }
  }

  inline int get(int x) {
    int ret = 0;
    for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
      add(ret, f[i]);
    }
    return ret;
  }

  inline int get(int x, int y) {
    int ret = 0;
    if (x <= y) {
      ret = get(y) - (x - 1 < 0 ? 0 : get(x - 1));
      if (ret < 0) {
        ret += mod;
      }
    }
    return ret;
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long a, b;
  cin >> n >> a >> b;
  if (a > b) {
    swap(a, b);
  }
  vector<long long> s(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> s[i + 1];
  }
  s[0] = -inf;
  fenwick f(n + 1);
  f.agg(0, 1);
  int zero_prefix = -1;     
  vector<int> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (i + 2 <= n && s[i + 2] - s[i] < a) {
      cout << 0 << '\n';
      return 0;
    }
    if (s[i + 1] - s[i] < a) {
      int low = 0 /* zero_prefix + 1 */, high = i - 1, mid;
      while (low < high) {
        mid = (low + high + 1) >> 1;
        if (s[i + 1] - s[mid] >= b) {
          low = mid;
        } else {
          high = mid - 1;
        }
      }
      int res = f.get(low);
      dp[i + 1] = res;
      f.agg(i + 1, res);
      for (int j = zero_prefix + 1; j <= i - 1; j++) {
        f.agg(j, (mod - dp[j]) % mod);
        dp[j] = 0;
      }
      zero_prefix = i - 1;
    } else {
      int low = 0 /* zero_prefix + 1 */, high = i, mid;
      while (low < high) {
        mid = (low + high + 1) >> 1;
        if (s[i + 1] - s[mid] >= b) {
          low = mid;
        } else {
          high = mid - 1;
        }
      }
      int res = f.get(low);
      dp[i + 1] = res;
      f.agg(i + 1, res);
    }
  }
  int ans = 0;
  for (int j = 0; j <= n; j++) {
    add(ans, dp[j]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1920
/*  In the name of ALLAH   */
#include <bits/stdc++.h>
using namespace std;

#define int          int64_t
#define FIO()        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii          pair<int,int>
#define pb           push_back
#define pu           push
#define fi           first
#define se           second
#define endl         "\n"

const int mod = 1e9 + 7;
const int MAX_I =  9223372036854775807;
const int MIN_I = -9223372036854775807;

int32_t main() {
	FIO();
	int A,B; cin>>A>>B;
	if(A<10&&A>0&&B<10&&B>0)
		cout<<A*B<<endl;
	else
		cout<<"-1\n";
}

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

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

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int n;
	cin>>n;

	int a[n],b[n];
	F0R(i,n) cin>>a[i]>>b[i];

	sort(ALLn(a,n));
	sort(ALLn(b,n));

	ll y,z;

	if(n%2) y=a[n/2],z=b[n/2];
	else y=(a[n/2-1]+a[n/2]), z=(b[n/2-1]+b[n/2]);

	cout<<z-y+1;
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
}



Measured memory_bytes: 5184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
using namespace std;
#pragma warning (disable: 4996)

long long N, K, a[100009], b[100009]; vector<long long>F;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	long long cx = K + 1;
	while (cx > 0) { F.push_back(cx - 1); cx -= (cx&-cx); }

	long long maxn = 0;
	for (int i = 0; i < F.size(); i++) {
		long long sum = 0;
		for (int j = 0; j < N; j++) {
			if ((a[j] | F[i]) == F[i]) sum += b[j];
		}
		maxn = max(maxn, sum);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;


int main(int argc, char* argv[]) {
  long long N, M;
  cin >> N >> M;

  if (N == 1 && M == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (N == 1) {
    cout << M - 2 << endl;
    return 0;
  }
  if (M == 1) {
    cout << N - 2 << endl;
    return 0;
  }
  if (N == 2 || M == 2) {
    cout << 0 << endl;
    return 0;
  }

  cout << (N - 2) * (M - 2) << endl;

  return 0;
}

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

int main() {
    string S; cin >> S;
    cout << S.substr(0,4) + " " + S.substr(4,8) << endl;
}

Measured memory_bytes: 256
n = int(input())
a = w = t = r = 0
for i in range(n):
    s = input()
    if s == "AC":
        a += 1
    elif s == "WA":
        w += 1
    elif s == "TLE":
        t += 1
    else:
        r += 1
    
ans = f"""AC x {a}
WA x {w}
TLE x {t}
RE x {r}"""

print(ans)

Measured memory_bytes: 9192
#include<cstdio>
#include<algorithm>
using namespace std;
char c[10];int a[10],flag;
int main()
{
	scanf("%s",c);
	for(int i=0;i<3;i++)
		a[(c[i]-'a')]++;
	for(int i=0;i<3;i++)
		if(a[i]!=1)flag=1;
	if(flag)printf("No\n");
	else printf("Yes\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, x, y;
    cin >> N;

    vector<pll> v;
    REP(i, N) {
        cin >> x >> y;
        v.push_back({x, y});
    }
    sort(ALL(v));
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    set<pll> vpq;
    REP(i, N) REP(j, N) {
        if (i == j) continue;
        vpq.insert({v[i].first - v[j].first, v[i].second - v[j].second});
    }

    ll ans = 10000;
    for (auto pq : vpq) {
        ll cnt = 0;
        ll p = pq.first, q = pq.second;
        map<pll, bool> m;
        REP(i, N) {
            m[{v[i].first, v[i].second}] = true;
            if (!m[{v[i].first + p, v[i].second + q}] && !m[{v[i].first - p, v[i].second - q}]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

ll N,sum;
ll A[100002];

int main(void){
    cin >> N;
    rep(i,N)cin >> A[i+1];
    A[0] = A[N+1] =0;
    rep(i,N+1){
        sum += abs(A[i]-A[i+1]);
    }
    //cout << sum << endl;
    for(int i=1;i<=N;i++)cout << sum - abs(A[i-1]-A[i])- abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]) << endl;
}


Measured memory_bytes: 2048
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7
N, K = inpl()
A = inpl()
correct = 0
inverse = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] < A[j]:
            correct += 1
        elif A[i] > A[j]:
            inverse += 1

W1 = K*(K-1)//2 % MOD
W2 = K*(K+1)//2 % MOD
ans = (correct*W1+inverse*W2) % MOD
print(ans)

Measured memory_bytes: 41836
s = input()
if s.find("A") == 0 and s[2:-1].count("C") == 1:
    s1 = s.replace("A","a", 1)
    s2 = s[2:-1].replace("C","c")
    s = s1[:2] + s2 + s1[-1]
    if s.islower() == True:
        print("AC")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s;
    cin >> s;

    int i = s.find('C');
    if(i != string::npos)
        i = s.find('F', i);

    if(i == string::npos)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
#define N 1000
bool M[N][N];

int main(){
    int n,u,k,v;
    queue<int> Q;
 
    cin >> n;
    for(int i=0;i<n;i++){
	cin >> u >> k;
	u--;
	for(int j=0;j<k;j++){
	    cin >> v;
	    v--;
	    M[u][v]=true;
	}
    }
   
    int d[N]={0};
    Q.push(0);
    while(!Q.empty()){
	u=Q.front();
	Q.pop();
	for(int i=1;i<n;i++){
	    if(M[u][i] && d[i]==0){
		d[i]=d[u]+1;
		Q.push(i);
	    }
	}
    }

    for(int i=0;i<n;i++){
	if(i!=0 && d[i]==0) d[i]=-1;
	printf("%d %d\n",i+1,d[i]);
    }

    return 0;
}

Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
const long long int l=1000000000000000000;
int main()
{
   long long int n,m;
    cin>>n>>m;
    for(int i=2;i<9999999;i++)
    {
        if((n*i)%m)
        {
            cout<<n*i<<endl;
            return 0;
        }
        if((n*i)>l)
        {
            cout<<-1<<endl;
            return 0;
        }

    }
    cout<<-1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

int main () {
    string x;
    cin >> x;
    if (x[0] == 'A' || x[1] == 'A' || x[2] == 'A')
        if (x[0] == 'B' || x[1] == 'B' || x[2] == 'B') { puts("Yes"); return 0; } puts("No");
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn zalgorithm(v: &Vec<char>) -> Vec<usize> {
    let mut ret = vec![0; v.len()];
    ret[0] = v.len();
    let mut i = 1;
    let mut j = 0;
    while i < v.len() {
        while i + j < v.len() && v[j] == v[i + j] {
            // eprintln!("i: {}, j: {}, v[j]: {}, v[i + j]: {}", i, j, v[j], v[i + j]);
            j += 1;
        }
        ret[i] = j;
        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1;
        while i + k < v.len() && k + ret[k] < j {
            ret[i + k] = ret[k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    ret
}

fn main() {
    let n = get!(usize);
    let v: Vec<char> = get!(String).chars().collect();
    // eprintln!("v: {:?}", v);
    // eprintln!("nv: {:?}", nv);
    let mut ans = 0;
    for i in 0..n {
        let tv = v[i..].to_vec();
        let nv = zalgorithm(&tv);
        // eprintln!("tv: {:?}", tv);
        // eprintln!("nv: {:?}", nv);
        // eprintln!("--------------------------");
        for j in 0..tv.len() {
            let l = std::cmp::min(nv[j], j);
            ans = std::cmp::max(l, ans);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4476
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1*60+m1;
    int t2 = h2*60+m2;
    if(t1<t2){
        cout << t2-t1-k;
    }else{
        cout << 60*24+t1-t2-k;
    }
    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B, C = map(int, input().split())
    if A <= C <= B:
        print(Yes)
    else:
        print(No)


if __name__ == '__main__':
    main()


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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[110], y[110];
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> y[i];
  }
  sort(x, x + N,greater<int>());
  sort(y, y + M);

  bool ans = false;
  for (int i = X; i < Y; i++) {
    if (x[0] < i + 1 && i < y[0]) {
      ans = true;
      break;
    }
  }
  if (ans) cout << "No War" << endl;
  else cout << "War" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()
/* --- */
const int N = 110;
int a[N], b[N], n;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", a + i);
	for (int i = 0; i < n; i++) scanf("%d", b + i);
	for (int i = 1; i < n; i++) a[i] += a[i - 1];
	for (int i = n - 2; i >= 0; i--) b[i] += b[i + 1];
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans = max(ans, a[i] + b[i]);
	printf("%d\n", ans);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  ll h,w;
  ll ans=0;
  ll mp[500][500];
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
      ans+=((i+1)*(h-i) )*((j+1)*(w-j) )*mp[i][j];
    }
  }
  cout<<ans<<endl;
  return 0;
}






Measured memory_bytes: 5048
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>
 
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
void runtime(){cout<<fixed<<setprecision(5)<<1.0*clock()/CLOCKS_PER_SEC<<endl;}

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <class T>void read(vector<T> &a,int n){T x; a.clear();for(int i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

const ll mod=1000000007;

int n;
vector<pii> v;
ll ans=1;

map<pll,int> pos,neg;
set<pll> was;

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

ll bpow(ll a,ll x)
{
    if(!x) return 1;
    if(x&1) return a*bpow(a,x-1)%mod;
    ll b=bpow(a,x/2);
    return b*b%mod;
}


ll val_z;
ll z_val;
ll z;


int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
    
    cin>>n;
    for(int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        
        if(a==0 && b==0)
        {
            z++;
            continue;
        }
        if(a==0)
        {
            z_val++;
            continue;
        }
        if(b==0)
        {
            val_z++;
            continue;
        }
        
        ll g=gcd(abs(a),abs(b));
        a/=g;
        b/=g;
        
        if(a<0)
        {
            a=-a;
            b=-b;
        }
        
        if(b>0)
            pos[mp(a,b)]++;
        else
            neg[mp(a,b)]++;
    }
    
    for(pair<pll,int> pp : pos)
    {
        pll p=pp.f;
        int x=pp.s;
        
        pll np=mp(p.s,-p.f);
        
        if(neg.count(np))
        {
            was.insert(np);
            int y=neg[np];
            ans=(ans*bpow(2,x)%mod+ans*bpow(2,y)%mod-ans+mod)%mod;
        }
        else
        {
            ans=(ans*bpow(2,x))%mod;
        }
    }
    
    for(pair<pll,int> pp : neg)
    {
        pll p=pp.f;
        int x=pp.s;
        
        if(!was.count(p))
        {
            ans=(ans*bpow(2,x))%mod;
        }
    }
    
    if(val_z && z_val)
        ans=(ans*bpow(2,val_z)%mod+ans*bpow(2,z_val)%mod-ans+mod)%mod;
    else if(val_z)
        ans=(ans*bpow(2,val_z))%mod;
    else if(z_val)
        ans=(ans*bpow(2,z_val))%mod;
    cout<<(ans+z-1+mod)%mod<<'\n';
}


Measured memory_bytes: 15524
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
using namespace std;
#define ll long long

int main() {
    string s;
    int k;
    cin >> s >> k;
    set<string> t;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 1; j <= k; j++) {
            t.insert(s.substr(i, j));
        }
    }
    auto itr = t.begin();
    for(int i = 0; i < k-1; i++) itr++;
    cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;

int main(){
  int N;
  cin >> N;
  vector<int> p(N),p_orig(N);
  vector<int> q(N),q_orig(N);
  rep(i,N) {cin >> p[i]; p_orig[i] = p[i];}
  rep(i,N) {cin >> q[i]; q_orig[i] = q[i];}
  int a=0;
  int b=0;
  
  while(next_permutation(ALL(p))){
    rep(i,N){
      if(p_orig[i]<p[i])break;
    }
    a++;
  }
  a--;
  while(next_permutation(ALL(q))){
    rep(i,N){
      if(p_orig[i]<q[i])break;
    }
    b++;
  }
  b--;
  cout << abs(a-b) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,j;
  cin >> n;
  vector<int> a(n);
  bool check0 = true;
  for(i = 0; i < n; i++)
  {
    cin>>a.at(i);
    if(a.at(i) != 0)check0 = false;
  }
  if(check0) cout << "Yes" << endl;
  else
  {
    if(n%3 != 0)cout << "No" << endl;
    else
    {
      vector<int> num(3);
      sort(a.begin(), a.end());
      bool ok = true;
      for(i = 0; i < 3; i++)
      {
        for(j = 0; j < n/3; j++)
        {
          if(j == 0)num.at(i) = a.at(n/3*i);
          else
          {
            if(a.at(n/3*i+j) != num.at(i))
            {
              ok = false;
            }
          }
        }
      }
      if(!ok)cout << "No" << endl;
      else if(num.at(0) == 0 && num.at(1) == num.at(2)) cout << "Yes" << endl;
      else
      {
        bool ok2 = true;
        while(num.at(0)>0&&num.at(1)>0&&num.at(2)>0)
        {
          if((num.at(0)%2+num.at(1)%2+num.at(2)%2)%2 != 0)
          {
            ok2 = false;
          }
          num.at(0) /= 2;
          num.at(1) /= 2;
          num.at(2) /= 2;
        }
        if(ok2)cout << "Yes" << endl;
        else cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	double max, min;
	double in;
	
	scanf("%lf", &in);
	max = min = in;
	
	while (scanf("%lf", &in) != EOF){
		if (in > max) max = in;
		else if (in < min) min = in;
	}
	
	printf("%.1lf\n", max - min);
	
	return (0);
}

Measured memory_bytes: 0
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
vector<pair<string, int> > vec;

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n = read();
    rep(i, 1, n) {
        string s;
        int d;
        sf(s, d);
        pr(s);prln(d);
        vec.push_back({s, d});
    }
    string s;
    sf(s);
    ll sum = 0;
    bool ok = false;
    // prln(s);
    rep(i, 0, n - 1) {
        if (ok) {
            prln(vec[i].second);
            sum += 1ll * vec[i].second;
            prln(sum);
            continue;
        }
        // prln(vec[i].first);
        if (vec[i].first == s) {
            // prln("sfrwer");
            ok = true;
        }
    }
    out(sum);
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:640000000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
//#include <unordered_map>
/// unordered map only when c++ 11 is ticked :p
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI=acos(-1.0);

#define    READ(f)       freopen(f, "r", stdin)
#define    WRITE(f)      freopen(f, "w", stdout)

#define    INF           999999999999999
#define    pii           pair<int, int>
#define    pdd           pair<double, double>
#define    pll           pair<long long int, long long int>
#define    ii            long long int
#define    uii           unsigned long long int
#define    ui            unsigned int
#define    bitCheck(a,k) ((bool)(a&(1<<(k))))
#define    bitOff(a,k)   (a&(~(1<<(k))))
#define    bitOn(a,k)    (a|(1<<(k)))
#define    bitFlip(a,k)  (a^(1<<(k)))
#define    iseq(a,b)     (fabs(a-b)<EPS)

template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }


///******************DELETE****************

#ifdef rafiul41
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

int strToint(string x)
{
    stringstream ss(x);
    int i;
    ss>>i;
    return i; /// this int does not have any leading zeros !!!
}
///**************************************************

int main()
{
#ifdef rafiul41
//
//    READ("in.txt");
//    WRITE("out.txt");

#endif // rafiul41
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int ans=min(b,d)-max(a,c);
    if(ans<0)
        ans=0;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
S = str(input())

YYMM = 0
MMYY = 0
if 1 <= int(S[0:2]) <= 12 :
  MMYY = 1
if 1 <= int(S[2:4]) <= 12 :
  YYMM = 1

if YYMM + MMYY == 2 :
  print ("AMBIGUOUS")
elif YYMM + MMYY == 0 :
  print ("NA")
elif YYMM == 1 :
  print ("YYMM")
else :
  print ("MMYY")
 


Measured memory_bytes: 38384
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int H, W;
        {int[] a = r.ii(); H = a[0]; W = a[1];}
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < H; i++){
            String s = r.s();
            for(int j = 0; j < 2; j++){
                sb.append(s);
                sb.append('\n');
            }
        }
        print(sb);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
string make_string(T N)
{
    string ret;
    T now = N;
    while (now > 0)
    {
        T x = now % 10;
        ret += (char)('0' + x);
        now /= 10;
    }
    reverse(all(ret));
    return ret;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll D, T, S;
    cin >> D >> T >> S;
    ll A = T * S;
    if (A >= D)
        putout("Yes");
    else
        putout("No");
    return 0;
}


Measured memory_bytes: 3616
def main():
    a, b, k = map(int,input().split())


    for i in range(k):
        if i % 2 == 0:
            if a % 2 == 1:
                a = a-1
            b = b+ a//2
            a = a//2

        else:
            if b % 2 == 1:
                b = b-1
            a = a + b//2
            b = b//2

    print(str(a) +" "+str(b))





if __name__ == "__main__":
        main()


Measured memory_bytes: 3060
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

ans=0
for i in range(n):
    if x>=a[i]:
        x-=a[i]
        ans+=1
# print(x)
print(min(ans,n-1 if x>0 else n))

Measured memory_bytes: 69284
# ai の大きい方から左端か右端
# はるかに問題なのはそこから先だがDP
n=int(input())
*a,=map(int, input().split( ))
dp = [0]
#周回が総数、dpのindexが左に置いた数
aii = [(ai,i) for i,ai in enumerate(a)]
aii.sort(key= lambda x:-x[0])
for j,(ai,i) in enumerate(aii):
    dp2 = [0]*(j+2)
    dp2[0]=dp[0]+ai*abs(n-j-1-i)
    dp2[-1]=dp[-1]+ai*abs(j-i)
    for k in range(j):
        dp2[k+1] = max(dp[k]+ai*abs(k-i), dp[k+1]+ai*abs((n-(j-k-1)-1)-i))##abs((n-(j-k-1)-1)-i)
    dp = dp2

print(max(dp))

Measured memory_bytes: 68904
// C - Sequence
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))

ll counting(vector<ll> &A, int N, bool OddEven){//OddEven: odd true, even false
	ll c = 0, csum = 0;
	up(i,0,N,1){
		csum += A[i];
		if(i%2==OddEven && csum<=0){// -0 NG
			c += abs(csum) + 1;
			csum = 1;
		}
		if(i%2==!OddEven && csum>=0){// +0 NG
			c += abs(csum) + 1;
			csum = -1;
		}
	}
	return c;
}

int main(){
	int N; cin>>N;
	vector<ll> A(N);
	up(i,0,N,1) cin>>A[i];
	ll a = counting(A,N,true);
	ll b = counting(A,N,false);
	cout<< (a<b?a:b) <<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

using ll = unsigned long long;

int N, M;

int main(){
    cin >> N >> M;
    cin.ignore();

    atcoder::dsu d(N);

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        cin.ignore();
        d.merge(a, b);
    }

    vector<vector<int>> gr = d.groups();

    cout << gr.size() - 1 << endl;

    return 0;
}

Measured memory_bytes: 8960