akhauriyash/Code-Regression huggingface dataset:
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {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;

#define MAXN 100000
const LL kcz=1000000000+7;
#define MOD(x) ((x)%kcz)
LL _f[MAXN+10];
LL *f=_f+1;
void solve(long long N, long long A, long long B, vector<long long> S){
	if (A>B) swap(A,B);
	LL a=A,b=B;
	for(int i=2; i<N; ++i) {
		if (S[i]-S[i-2]<a) {
			puts("0");
			return;
		}
	}	
	f[-1]=1;
	f[0]=1;
	int l=-1,r=-1;
	LL sum=1;
	for(int i=1; i<N; ++i) {
		f[i]=0;
		while(S[i]-S[r+1]>=b  && r<i) {
			++r;
			sum+=f[r];
			sum%=kcz;
		}
		f[i]+=sum%=kcz;
		debug(f[i]);
		if (S[i]-S[i-1]<a) {
			l=i-1;
			r=i-2;
			sum=0;
		}
	}
	LL ans=f[N-1]%kcz;
	for(int i=N-2; i>=-1; --i) {
		ans+=f[i];
		ans%=kcz;
		if (i>=0 && S[i+1]-S[i]<a) break;
	}
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	freopen("in.txt","r",stdin);
#endif
	long long N;
	long long A;
	long long B;
	scanf("%lld",&N);
	vector<long long> S(N-1+1);
	scanf("%lld",&A);
	scanf("%lld",&B);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&S[i]);
	}
	solve(N, A, B, S);
	return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
typedef const int let;
typedef pair<int,int> pii;
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

ll gcd(ll x, ll y){
   if(x < y)swap(x,y);
   ll r;
   while(y)r=x%y, x=y, y=r;
   return (x);
}

ll lcm(ll x, ll y){
   return (x*y / gcd(x,y) );
}

signed main()
{
   FAST();
   int x, y;
   cin >> x >> y;
   if ( x % y == 0){
      outl(-1);
      return (0);
   }

   outl( x );
}




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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 1e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
//        freopen("in.txt", "r", stdin);
//        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

string A, B;
ll dica[26], dicb[26];

int main() {
    IO();
    while(cin >> A >> B) {
        ll ans = 0, n = A.size();

        for(ll i = 0; i < n; ++i) {
            if(A[i] != B[i]) ans++;
        }

        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3860
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

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

   ll n;
   cin>>n;

   ll h[n+1];
   for(ll i=1;i<=n;i++){
       cin>>h[i];
   }

   ll dp[n+1]={0};
   dp[1] = 0;
   dp[2] = abs(h[2]-h[1]);
   for(ll i=3;i<=n;i++){
       dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
   }
   cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
int fact(int k){
    int sum=1;
    for (int i=1;i<=k;i++){
        sum*=i;
sum%=1000000007;
    }
    return sum;
}
signed main(){
  int a;
  cin>>a;
  cout<<fact(a);
}

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>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

ll freq[100001];
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
    freq[a]++;
  }
  int q;
  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    sum -= b * freq[b];
    sum += c * freq[b];
    freq[c] += freq[b];
    freq[b] = 0;
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 4344
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int students[n];

    for(int i = 1; i <= n; i++){
        int s;
        cin >> s;
        students[s-1] = i;
    }

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

    return 0;
}


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

bool isHamming(int x){
		int j=x;
		while(j%2==0)
			j=j/2;
		while(j%3==0)
			j=j/3;
		while(j%5==0)
			j=j/5;
		if(j==1)
			return true;
		else
			return false;
}
	
int main(){

	while(true){
		int m,n;
		cin >> m;

		if(m==0)
			break;

		cin >> n;
	
		int ans=0;
		for(int i=m; i<=n; i++){
			if(isHamming(i))
				ans++;
		}
		cout << ans<< endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}


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

    int M, N; cin >> M >> N;
    vector<vector<pair<int,int>>> condLess(N), condGreater(N);
    REP(i, M) {
        int K; cin >> K;
        REP(j, K) {
            int s, t; string cond;
            cin >> s >> cond >> t; --s;
            if (cond == "<=") condLess[s].emplace_back(i, t);
            else condGreater[s].emplace_back(i, t);
        }
    }
    vvi graph(M);
    REP(i, N) {
        for (auto &a : condGreater[i]) {
            for (auto &b : condLess[i]) {
                if (a.second > b.second) {
                    graph[b.first].push_back(a.first);
                }
            }
        }
    }

    vi deg(M);
    REP(i, M) {
        for (int u : graph[i]) ++deg[u];
    }
    queue<int> que;
    REP(i, M) if (deg[i] == 0) que.push(i);
    vi used(M);

    while (!que.empty()) {
        int v = que.front(); que.pop();
        used[v] = 1;
        for (int u : graph[v]) {
            if (--deg[u] == 0) que.push(u);
        }
    }
    cout << (accumulate(ALL(used), 0) == M ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 4068
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;

template <typename T>
inline bool read(T& ret) {
    T x = 0, f = 1; char ch = getchar();
    while(ch!=EOF && (ch > '9' || ch < '0')) { if(ch == '-') f = -1; ch = getchar();  }
    if(EOF==ch)return false;
    do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
    ret = x * f;
    return true;
}


inline char nc() {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
bool rn(T& v) {
    static char ch;
    while (ch != EOF && !isdigit(ch)) ch = nc();
    if (ch == EOF) return false;
    for (v = 0; isdigit(ch); ch = nc())
        v = v * 10 + ch - '0';
    return true;
}

template <typename T>
void o(T p) {
    static int stk[70], tp;
    if (p == 0) { putchar('0'); return; }
    if (p < 0) { p = -p; putchar('-'); }
    while (p) stk[++tp] = p % 10, p /= 10;
    while (tp) putchar(stk[tp--] + '0');
}


LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }



void Solve(){
}

const int MAXN=2e5+10;
int N, M;
int pa[MAXN];
int cnt[MAXN];


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


int main(){
#ifdef L_JUDGE
    freopen("in1.txt","r",stdin);
    //		freopen("out.txt","w",stdout);
#endif
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    while(cin>>N>>M){
        int a,b;
        for(int i=1;i<=N;i++){
            pa[i]=i;
            cnt[i]=1;
        }
        for(int i=0;i<M;i++){
            scanf("%d%d",&a,&b);
            int fa=find(a);
            int fb=find(b);
            if(fa!=fb){
                pa[fa]=fb;
                cnt[fb]+=cnt[fa];
            }
        }
        int ans = 0;
        for(int i=1;i<=N;i++){
            ans = max(ans, cnt[i]);
        }
        cout<<ans<<endl;
    }
    return 0;

#ifdef L_JUDGE
    fclose(stdin);
    fclose(stdout);
    //		system("out.txt");
#endif

	return 0;
}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int num1, num2;
    cin>>num1>>num2;
    if(num1>9 || num2>9){
        cout<<"-1\n";
    }
    else{
        cout<<num1*num2<<"\n";
    }
    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 () {
    int a = read(), b = read(), c = read();
    if (a == b && a != c) puts("Yes");
    else if (a == c && a != b) puts("Yes");
    else if (b == c && b != a) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;++i){
    set<string> s;
    string train;
    cin>>train;
    int len = train.length();
    for(int j=1;j<len;++j){
      string sub1,sub2;
      sub1 = train.substr(0,j);
      sub2 = train.substr(j);
      for(int k=0;k<2;++k){
        swap(sub1,sub2);
        s.insert(sub1+sub2);
        reverse(sub1.begin(),sub1.end());
        s.insert(sub1+sub2);
        reverse(sub2.begin(),sub2.end());
        s.insert(sub1+sub2);
        reverse(sub1.begin(),sub1.end());
        s.insert(sub1+sub2);
      }
    }
    cout<<s.size()<<endl;
  }

  return 0;
}

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

using namespace std;

#define ll long long int
typedef pair<int,int>PII;
int main() {

      int a,b,c;
      cin>>a>>b>>c;
      if ( !(c < a) &&!(c > b) ) {
            printf("Yes\n");
      }else {
            printf("No\n");
      }
      return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))

x = y = z = 0
for a in a_list:
    if a % 4 == 0:
        x += 1
    elif a % 2 == 0:
        y += 1
    else:
        z += 1
if (y == 0 and x >= z - 1) or (y > 0 and x >= z):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20004
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
void inp(){
	int a,b;scanf("%d%d",&a,&b);
	int c = b - a;
	printf("%d", ( c + 1 ) * c / 2 - b);
}
//b.cc by xsthunder at Fri Jul 27 23:12:40 2018


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    for (int i = 0; i < b; ++i) {
        cout << a;
    }
    cout << '\n';
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
def myfunc(e):
  return e[1]
nb = int(input())
liste=[]
for loop in range(nb):
  liste += [[int(x) for x in input().split()]]
liste.sort(key=myfunc)
def mm():
  somme = 0
  for loop in range(len(liste)):
    somme += liste[loop][0]
    if somme>liste[loop][1]:
      return "No"
  return "Yes"
print(mm())
    

Measured memory_bytes: 43736
#include <stdio.h>

#define in_range(a, b, x)	(a <= x && x <= b)	

typedef struct { double x, y; } P;

int input_p(P *p) { return scanf("%lf %lf", &p->x, &p->y);}

int main(void)
{
	P ps[8];

	while (~input_p(ps)){
		int i;

		for (i = 1; i < 4; i++) input_p(ps + i);

		if ((in_range(ps[0].x, ps[1].x, ps[2].x) ||
			 in_range(ps[0].x, ps[1].x, ps[3].x) ||
			 in_range(ps[2].x, ps[3].x, ps[0].x) ||
			 in_range(ps[2].x, ps[3].x, ps[1].x))
			&&
			(in_range(ps[0].y, ps[1].y, ps[2].y) ||
			 in_range(ps[0].y, ps[1].y, ps[3].y) ||
			 in_range(ps[2].y, ps[3].y, ps[0].y) ||
			 in_range(ps[2].y, ps[3].y, ps[1].y))
		) puts("YES");
		else puts("NO");
	}

	return (0);
}

Measured memory_bytes: 612
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int A = nextInt()*3;
		int B = nextInt();

		out.println((A+B)/2);
		sc.close();
	}
	private long max(long a, long b) {
		return Math.max(a, b);
	}
	private long min(long a, long b) {
		return Math.min(a, b);
	}
	private static int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	private static long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
	static long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

}


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

long long F_0_(long long n) {
  long long ret;
  if ( n%2 == 0 ) {
    ret = ( (n/2)%2 == 0 ) ? 0 : 1;
    ret ^= n;
  } else {
    ret = ( ((n+1)/2)%2 == 0 ) ? 0 : 1;
  }
  return ret; 
}

int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = F_0_(a-1) ^ F_0_(b);
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
int arr[m];
for(int i=0; i<m; i++) cin >> arr[i];
for(int i=0; i<m; i++) n = n- arr[i];
if(n>=0) cout << n ;
else cout << "-1";
return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#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 dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll a[26]; mem(a, 0);
    string s;
    cin >> s;
    for(auto x: s){
        a[x-'a']++;
    }
    rep(i, 26)
        if(a[i] == 0) ANS( (char)(i+'a'));
    ANS("None");
}
main(){
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


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

const long long INF = 2ll << 60;

bool is_ok(int index, long long key, const vector<long long> &v) {
    if (v.at(index) < key) return true;
    else return false;
}

int binary_search(long long key, const vector<long long> &v) {
    int ng = (int)v.size();
    int ok = -1;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (is_ok(mid, key, v)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<long long> s(a + 2), t(b + 2);
    s.at(0) = t.at(0) = -INF;
    for (int i = 0; i < a; i++) {
        cin >> s.at(i + 1);
    }
    for (int i = 0; i < b; i++) {
        cin >> t.at(i + 1);
    }
    s.at(a + 1) = t.at(b + 1) = INF;

    for (int i = 0; i < q; i++) {
        long long x;
        cin >> x;

        long long ls = s.at(binary_search(x, s));
        long long rs = *lower_bound(s.begin(), s.end(), x);
        long long lt = t.at(binary_search(x, t));
        long long rt = *lower_bound(t.begin(), t.end(), x);
        
        long long minimum = min({
            max(x - ls, x - lt), 
            max(rs - x, rt - x), 
            x - ls + rt - ls, 
            x - lt + rs - lt, 
            rs - x + rs - lt,
            rt - x + rt - ls
        });
      
        cout << minimum << endl;
    }
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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

map<string, int> mp;
const int N = 10010;
vector<P> G[N];
int lpgid[N];
const int M = 310;
int lpg[M];
int d[M][M];

void dijk(int s, int cap){
	vector<int> dist(N, 1e9);

	priority_queue<P> q;
	q.push(MP(0, s));
	dist[s] = 0;
	while (!q.empty()){
		auto p = q.top();
		q.pop();

		int dd = p.first;
		int pos = p.second;
		if (dist[pos] < dd) continue;
		if (lpgid[pos] >= 0) d[lpgid[s]][lpgid[pos]] = dd;

		for (auto edge : G[pos]){
			int nd = dd + edge.second;
			int npos = edge.first;
			if (dist[npos] <= nd) continue;
			dist[npos] = nd;

			if (nd <= cap) q.emplace(nd, npos);
		}
	}
}

int main(){
	int n, m, cap;
	while (cin >> n >> m >> cap, n){
		MEMSET(lpgid, -1);
		MEMSET(lpg, -1);
		rep(i, M) rep(j, M) if(i != j) d[i][j] = 1e9;
		rep(i, N) G[i].clear();
		mp.clear();


		string src, dest;
		cin >> src >> dest;
		int num = 0;
		mp[src] = num++;
		mp[dest] = num++;
		rep(i, n){
			string s, t;
			cin >> s >> t;
			if (!mp.count(s)) mp[s] = num++;
			if (!mp.count(t)) mp[t] = num++;
			int d;
			cin >> d;
			G[mp[s]].emplace_back(mp[t], d);
			G[mp[t]].emplace_back(mp[s], d);
		}
		rep(i, m){
			string s;
			cin >> s;
			assert(mp.count(s) == 1);
			lpgid[mp[s]] = i;
			lpg[i] = mp[s];
		}
		lpgid[mp[src]] = m;
		lpg[m] = mp[src];
		lpgid[mp[dest]] = m + 1;
		lpg[m + 1] = mp[dest];

		rep(i, m + 2) dijk(lpg[i], cap * 10);

		rep(i, m + 2) rep(j, m + 2) rep(k, m + 2)
			d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

		int ans = d[m][m + 1];
		if (ans >= 1e9) cout << -1 << endl;
		else cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int H, W;
vector<string> board;
vector<vector<int>> dists;

void bfs() {
    queue<pair<int, int>> q;
 
    int dx[] = {0, 0, 1, -1};
    int dy[] = {1, -1, 0, 0};

    rep(i, 0, H) {
        rep(j, 0, W) {
            if (board[i][j] == '#') {
                q.emplace(i, j);
                dists[i][j] = 0;
            }
        }
    }
 
    while(!q.empty()) {
        pair<int, int> now = q.front();
        q.pop();
 
        rep(i, 0, 4) {
            int ny = now.first + dy[i];
            int nx = now.second + dx[i];
 
            if (ny < 0 or nx < 0 or ny >= H or nx >= W) continue;
 
            if (dists[ny][nx] > dists[now.first][now.second] + 1) {
                dists[ny][nx] = dists[now.first][now.second] + 1;
                q.emplace(ny, nx);
            }
        }
    }
 
    return;
}

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

    cin >> H >> W;
    board.resize(H);
    dists = vector<vector<int>>(H, vector<int>(W, 100000000));
    rep(i, 0, H) cin >> board[i];

    
    bfs();

    int maxDist = 0;
    rep(i, 0, H) {
        rep(j, 0, W) {
            maxDist = max(maxDist, dists[i][j]);
        }
    }

    cout << maxDist << "\n";
}

Measured memory_bytes: 13456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n;
	
	while (cin >> n && n != 0) {
		int m, cnt = 0, ans = 0;
		char ch;

		cin >> m;
		n = n * 2 + 1;
		while (m--) {
			cin >> ch;
			if ((cnt % 2 == 0 && ch == 'I') || (cnt % 2 == 1 && ch == 'O')) {
				cnt++;
			}
			else {
				ans += (cnt >= n ? (cnt - n) / 2 + 1 : 0);
				cnt = (ch == 'I' ? 1 : 0);
			}
		}
		ans += (cnt >= n ? (cnt - n) / 2 + 1 : 0);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <vector>
#include <utility>

using namespace std;
typedef pair<int, int> pii;

int evaluate(int x, int y, int width, int height, const vector<string> &field){
	int score = 0;
	int count[26] = { 0 };
	if(field[y][x] != '.'){ return 0; }
	for(int i = x - 1; i >= 0; --i){
		if(field[y][i] != '.'){
			++count[field[y][i] - 'A'];
			break;
		}
	}
	for(int i = x + 1; i < width; ++i){
		if(field[y][i] != '.'){
			++count[field[y][i] - 'A'];
			break;
		}
	}
	for(int i = y - 1; i >= 0; --i){
		if(field[i][x] != '.'){
			++count[field[i][x] - 'A'];
			break;
		}
	}
	for(int i = y + 1; i < height; ++i){
		if(field[i][x] != '.'){
			++count[field[i][x] - 'A'];
			break;
		}
	}
	for(int i = 0; i < 26; ++i){
		if(count[i] == 2){ score += 2; }
	}
	return score;
}

int main(){
	int m, n;
	cin >> m >> n;
	vector<string> field(m);
	for(int i = 0; i < m; ++i){ cin >> field[i]; }
	vector< vector<pii> > pos(26);
	for(int i = 0; i < m; ++i){
		for(int j = 0; j < n; ++j){
			if(field[i][j] == '.'){ continue; }
			pos[field[i][j] - 'A'].push_back(pii(i, j));
		}
	}
	int answer = 0;
	while(true){
		bool modified = false;
		pii hit;
		for(int i = 0; i < 26 && !modified; ++i){
			if(pos[i].empty()){ continue; }
			pii p0 = pos[i][0], p1 = pos[i][1];
			if(p0.first == p1.first){
				int minx = min(p0.second, p1.second), maxx = max(p0.second, p1.second);
				for(int x = minx + 1; x < maxx; ++x){
					if(evaluate(x, p0.first, n, m, field) > 0){
						modified = true;
						hit = pii(p0.first, x);
						break;
					}
				}
			}else if(p0.second == p1.second){
				int miny = min(p0.first, p1.first), maxy = max(p0.first, p1.first);
				for(int y = miny + 1; y < maxy; ++y){
					if(evaluate(p0.second, y, n, m, field) > 0){
						modified = true;
						hit = pii(y, p0.second);
						break;
					}
				}
			}else{
				if(evaluate(p0.second, p1.first, n, m, field) > 0){
					modified = true;
					hit = pii(p1.first, p0.second);
				}
				if(evaluate(p1.second, p0.first, n, m, field) > 0){
					modified = true;
					hit = pii(p0.first, p1.second);
				}
			}
		}
		if(!modified){ break; }
		int count[26] = { 0 };
		for(int i = hit.second - 1; i >= 0; --i){
			if(field[hit.first][i] != '.'){
				++count[field[hit.first][i] - 'A'];
				break;
			}
		}
		for(int i = hit.second + 1; i < n; ++i){
			if(field[hit.first][i] != '.'){
				++count[field[hit.first][i] - 'A'];
				break;
			}
		}
		for(int i = hit.first - 1; i >= 0; --i){
			if(field[i][hit.second] != '.'){
				++count[field[i][hit.second] - 'A'];
				break;
			}
		}
		for(int i = hit.first + 1; i < m; ++i){
			if(field[i][hit.second] != '.'){
				++count[field[i][hit.second] - 'A'];
				break;
			}
		}
		for(int i = 0; i < m; ++i){
			for(int j = 0; j < n; ++j){
				if(field[i][j] == '.'){ continue; }
				if(count[field[i][j] - 'A'] >= 2){
					pos[field[i][j] - 'A'].clear();
					field[i][j] = '.';
					++answer;
				}
			}
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

struct Edge
{
  i64 to, cost;
};

i64 n;
vector<vector<Edge>> edge;
vector<vector<i64>> d;
vector<bool> ok;

void dijkstra(int s)
{
  d[s][s] = 0;
  priority_queue<pair<i64, i64>, vector<pair<i64, i64>>, greater<pair<i64, i64>>> que;
  que.push({0, s});
  while (que.size())
  {
    pair<i64, i64> p = que.top();
    que.pop();
    for (Edge i : edge[p.second])
      if (d[s][p.second] + i.cost < d[s][i.to])
      {
        d[s][i.to] = d[s][p.second] + i.cost;
        que.push({d[s][i.to], i.to});
      }
  }
  return;
}

void check(i64 s, i64 md)
{
  queue<i64> que;
  vector<bool> vis(n);
  for (i64 i = 0; i < n; i++)
    if (d[s][i] == md)
    {
      que.push(i);
      vis[i] = true;
    }
  while (que.size())
  {
    i64 p = que.front();
    que.pop();
    ok[p] = false;
    for (Edge i : edge[p])
      if (!vis[i.to] && d[s][i.to] == d[s][p] - i.cost)
      {
        vis[i.to] = true;
        que.push(i.to);
      }
  }
}

int main()
{
  i64 r;
  cin >> n >> r;
  edge.resize(n);
  for (i64 i = 0; i < r; i++)
  {
    i64 s, t, d;
    cin >> s >> t >> d;
    s--;
    t--;
    edge[s].push_back({t, d});
    edge[t].push_back({s, d});
  }
  d.resize(n, vector<i64>(n, 1e9));
  for (i64 i = 0; i < n; i++)
    dijkstra(i);
  i64 md = 0;
  for (i64 i = 0; i < n; i++)
    for (i64 j = 0; j < n; j++)
      md = max(md, d[i][j]);
  ok.resize(n, true);
  for (i64 i = 0; i < n; i++)
    check(i, md);
  vector<i64> ans;
  for (i64 i = 0; i < n; i++)
    if (ok[i])
      ans.push_back(i + 1);
  cout << ans.size() << endl;
  for (i64 i : ans)
    cout << i << endl;
  return 0;
}



Measured memory_bytes: 20784
def d(u):
 global t
 C[u]=1;t+=1;D[u]=t
 for v in range(N):
  if M[u][v]and C[v]==0:d(v)
 C[u]=2;t+=1;F[u]=t
N=int(input())
M=[[0]*N for _ in[0]*N]
for e in[list(map(int,input().split()))for _ in[0]*N]:
 for v in e[2:]:M[e[0]-1][v-1]=1
C,D,F=[0]*N,[0]*N,[0]*N
t=0
for i in range(N):
 if C[i]==0:d(i)
for i in range(N):print(i+1,D[i],F[i])


Measured memory_bytes: 5792
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

priority_queue<pair<int, pair<int,int> > > pq;

vector<pair<pair<int,int>,int> > result;

void hora(int tc) {
	int n, k;
	cin>>n>>k;
	for(int i = 0;i < n;i++) {
		int u = k + i;
		int v = k + n + (i + k) % n;
		pq.push({-u - v, {u, v}});
	}
	for(int i = 0;i < n;i++) {
		int a = pq.top().S.F;
		int b = pq.top().S.S;
		int cur = k + 2 * n + i;
		if(a + b <= cur) {
			result.pb({{a, b}, cur});
			pq.pop();
		}
	}
	if(result.size() != n) cout<<-1<<endl;
	else {
		for(auto x: result) cout<<x.F.F<<" "<<x.F.S<<" "<<x.S<<endl;
	}
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modfact(int n){
  long long ans = 1;
  for (int i = 1; i <= n; i++){
    ans = ans * i % MOD;
  }
  return ans;
}
int main(){
  int N, M;
  cin >> N >> M;
  if (abs(N - M) >= 2){
    cout << 0 << endl;
  } else if (N == M){
    cout << modfact(N) * modfact(N) % MOD * 2 % MOD << endl;
  } else {
    cout << modfact(N) * modfact(M) % MOD << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,i,a[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int count=1,j,k=0;
  for(i=0;i<=n;i++){
    j=a[k];
    if(j==2) {printf("%d",count);return 0;}
    k=j-1;
    count++;
  }
  printf("-1");
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    if (S == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:usize, k:usize, h:[i64;n]};
    let mut h = h;
    h.sort();
    h.reverse();
    let mut ans = 0;
    for i in k..n {
        ans += h[i];
    }
    println!("{}", ans);
}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

using namespace std;

ll dp[1001][1001];
char grid[1001][1001];
int main()
{
    fastio;
    int n, m;
    cin >> n >> m;
    //char grid[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> grid[i][j];
            dp[i][j] = 0;
        }
    }
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = m - 1; j >= 0; j--)
        {
            if (i == n - 1 && j == m - 1)
                dp[i][j] = 1;
            else if (i == n - 1)
                dp[i][j] = dp[i][j + 1];
            else if (j == m - 1)
                dp[i][j] = dp[i + 1][j];
            else dp[i][j] = (dp[i][j + 1] + dp[i + 1][j]) % mod;
            if (grid[i][j] == '#') dp[i][j] = 0;
        }
        //cout << endl;
    }

    cout << dp[0][0];
}



Measured memory_bytes: 9088
n,k = map(int,input().split())


class Combination(): # nCr mod MOD など
    """
    O(n+log(mod))の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    C = Combination(10**6)
    print(C.combi_mod(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7): # O(n+log(mod))
        self.mod = mod
        self.fac, self.facinv = self.prepare(n_max)
        #self.modinv = self.make_modinv_list(n_max) ##なくても問題ないので、必要な時のみ使う
        
    def prepare(self,n): # O(n+log(mod))
        # 前処理(コンストラクタで自動的に実行)
        # 1! ~ n! の計算
        factorials = [1]  # 0!の分
        for m in range(1, n+1):
            factorials.append(factorials[m-1]*m%self.mod)
        # n!^-1 ~ 1!^-1 の計算
        invs = [1] * (n+1)
        invs[n] = pow(factorials[n], self.mod-2, self.mod)
        for m in range(n, 1, -1):
            invs[m-1] = invs[m]*m%self.mod
        return factorials, invs # list
    
    def make_modinv_list(self, n): # O(n)
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            # 整数aのMを法とした時の逆元a^-1は、(0<=a<=M-1)
            # a == qM+rであるとき(qは商,rは余り)、
            # a^-1 == -qr^-1 % M で与えられる。
            modinv[i] = (self.mod - self.mod//i)*modinv[self.mod%i]  % self.mod
        return modinv

    def perm_mod(self,n,r): # nPr % self.mod
        if n < r:
            return 0
        if (n < 0 or r < 0):
            return 0
        return (self.fac[n] * self.facinv[n-r]) % self.mod

    def combi_mod(self,n,r): # nCr % self.mod
        if n < r:
            return 0
        if (n < 0 or r < 0):
            return 0
        return (((self.fac[n] * self.facinv[r]) % self.mod) * self.facinv[n-r]) % self.mod

    def repeated_permutation(self,n,deno): # 重複順列
        # n!/(deno[0]!*deno[1]!*...*deno[len(deno)-1]) % MOD
        ## n:int(分子),deno:分母のlist
        if n < max(deno):
            return 0
        if (n < 0 or min(deno) < 0):
            return 0
        D = 1
        for i in range(len(deno)):
            D = D*self.facinv[deno[i]] % self.mod
        return self.fac*D % self.mod # int ## == n!/(deno[0]!*deno[1]!*...*deno[len(deno)-1]) % MOD
    
    def H(self,n,r): # 重複組合せ nHr % self.mod
        now_n = len(self.fac)
        if now_n < n+r-1: # もしself.facの長さが足りなかったら追加
            for i in range(now_n+1, n+r-1+1):
                self.fac.append(self.fac[i-1]*i%self.mod)
        return self.combi_mod(n+r-1,r)


mod = 10**9+7
C = Combination(n,mod)
ans = 0
for i in range(min(k+1,n+1)):
    ans += C.combi_mod(n,i)*C.H(n-i,i)
    ans %= mod
print(ans)



Measured memory_bytes: 54128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
const int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
const int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;

const int MX = 1001001001;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    ssort(h);
    int ans = MX;
    rep(i,n-k+1) {
        int tmp = h[i+k-1] - h[i];
        chmin(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int size;
		int[] heap;
		size = input.nextInt();
		heap = new int[size+1];
		for(int i = 1; i <= size; i++) {
			heap[i] = input.nextInt();
		}
		input.close();
		for(int i = 1; i <= size; i++) {
			int parent = -100000000;
			int key = heap[i];
			int left = -100000000;
			int right = -100000000;
			if(i == 1) {
				if(2 * i <= size) {
				left = heap[2 * i];
				}
				if(((2 * i) + 1) <= size) {
				right = heap[(2 * i) + 1];
				}
				
				
			}
			else {
				parent = heap[i/2];
				if(2 * i <= size) {
				left = heap[2 * i];
				}
				if(((2 * i) + 1) <= size) {
				right = heap[(2 * i) + 1];
				}
				
			}
			System.out.print("node " + (i) + ": key = " + key  + ", ");
			if(parent != -100000000) {
				System.out.print("parent key = " + parent + ", ");
			}
			if(left != -100000000) {
				System.out.print("left key = " + left + ", ");
				
			}
			if(right != -100000000) {
				System.out.print("right key = " + right + ", ");
				
			}
			System.out.println();
	
		}
	}

}


Measured memory_bytes: 27188
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache, reduce

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

# S = sys.stdin.readline().rstrip()
# c = list(S)
# if c[0] == c[1] or c[1] == c[2] or c[2] == c[3]:
#     print('Bad')
# else:
#     print('Good')

N, L = list(map(int, sys.stdin.readline().split()))

a = np.arange(L, L + N)
d = abs(a).argmin()
print(a.sum() - a[d])


Measured memory_bytes: 22424