akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

size_t calc(ssize_t l, ssize_t r) {
  size_t abs_l = std::abs(l);
  if (l >= 0) {
    return static_cast<size_t>(r);
  } else if (r <= 0) {
    return abs_l;
  }
  size_t min = std::min(abs_l, static_cast<size_t>(r));
  size_t max = std::max(abs_l, static_cast<size_t>(r));
  return 2 * min + max;
}


int main() {
  size_t N, K;
  std::cin >> N >> K;

  std::vector<ssize_t> X(N);

  for (size_t i=0; i<N; i++) {
    std::cin >> X[i];
  }

  size_t ans = calc(X[0], X[N-1]);

  for (size_t i=0; i<N-K+1; i++) {
    ans = std::min(ans, calc(X[i], X[i+K-1]));
  }

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


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , k;

int main()
{
    _FastIO;
    cin >> n >> k;
    cout << min(1 , n % k) << endl;
    return 0;
}


Measured memory_bytes: 3668
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
int R,C;
int up[11];
int a[11][10011];
int calc(int n,int sum){
  for(int i=0;i<C;i++){
    int pr=0;
    for(int j=0;j<R;j++){
      if( (n & (1<<j)) ){
	if(a[j][i]) pr--;
	else pr++;
      } else{
	if(a[j][i]) pr++;
	else pr--;
      }
    }
    sum += max(0,pr);
  }
  return sum;
}
int solve(int sum){
  int ret=sum;
  for(int i=1;i<(1<<R);i++){
    int ts = sum;
    for(int j=0;j<R;j++)
      if( (i & (1<<j)) ) ts+=up[j];
    ret=max(ret,calc(i,ts));
  }
  return ret;
}
int main(){
  while(1){
    scanf("%d %d",&R,&C);
    if(!R && !C) break;
    for(int i=0;i<R;i++)
      for(int j=0;j<C;j++)
	scanf("%d",&a[i][j]);
    int sum=0;
    memset(up,0,sizeof(up));
    for(int i=0;i<R;i++){
      int tp=0;
      for(int j=0;j<C;j++){
	if(!a[i][j]){
	  sum++;
	  up[i]--;
	}
	else{
	  up[i]++;
	}
      }
    }
    printf("%d\n",solve(sum));
  }
}

Measured memory_bytes: 1420
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	string str;
	bool isA = true;
	while(cin >> str){
		if(str.size() == 1 && str[0] == '0') break;
		int A = count(str.begin()+1,str.end(),'A');
		int B = count(str.begin()+1,str.end(),'B');

		if(A > B){
			if(B < 10) A = 11;
			else A = B + 2;			
		}
		else if(B > A){
			if(A < 10) B = 11;
			else B = A + 2;
		}
		printf("%d %d\n",A,B);
	}
}

Measured memory_bytes: 0
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
    if(p[i] == i+1):
        if(i+1 < n and p[i] != i+2):
            x = p[i]
            p[i] = p[i+1]
            p[i+1] = x
            ans += 1
        else:
            x = p[i]
            p[i] = p[i-1]
            p[i-1] = x
            ans += 1
print(ans)


Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}
int main(){
  
  ll N;
  cin>>N;
  vector<ll>t(N);
  vector<ll>x(N);
  vector<ll>y(N);
  
  rep(i,N){
    cin>>t[i]>>x[i]>>y[i];
  }
  
  bool flag=true;

  rep(i,N){
    if(i==0){
      if(x[0]+y[0]<=t[0]&&(x[0]+y[0])%2==t[0]%2){
        flag=true;
      }
      else{
        flag=false;
      }
    }
else{
      if(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=t[i]-t[i-1]&&(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2==(t[i]-t[i-1])%2){
        flag=true;
      }
    else{
      flag=false;
      break;
    }
  }
  }
  
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
  
     
    

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;

    for(int i = 0; i <= a; i++) {
        for(int j = 0; j <= b; j++) {
          	for(int k = 0; k <= c; k++) {
                if(500*i + 100*j + 50*k == x) {
                  ans++;
                  //cout << i << ' ' << j << ' ' << k-i-j << endl;
                }
            }
        }
    }

    cout << ans << endl;

  	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator {
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD): fac(), finv(), inv() {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % mod_;
      inv[i] = mod_ - inv[mod_ % i] * (mod_ / i) % mod_;
      finv[i] = finv[i - 1] * inv[i] % mod_;
    }
  }

  long long c(long long n, long long k) const {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template<typename T>
T modpow(T a, T n, T mod = MOD) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template<typename T>
T modinv(T a, T m = MOD) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
  init();

  int n, k;
  cin >> n >> k;

  vector<ll> es(n);
  for (size_t i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    es[i] = a;
  }
  if (n <= k) {
    cout << "0" << '\n';
    exit(0);
  }
  sort(all(es), greater<ll>());
  ll sum = accumulate(es.begin() + k, es.end(), 0LL);
  cout << sum << '\n';

  return 0;
}


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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s=="RRR")
        cout<<3;
    else if(s=="RRS" || s=="SRR")
        cout<<2;
    else if(s=="SSS")
        cout<<0;
    else
        cout<<1;
}


Measured memory_bytes: 3644
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype='int')
s = A.sum()
i = -1
left_length = 0
while left_length < s / 2:
    i += 1
    left_length += A[i]
# print(i, left_length, s)
ans1 = 2 * left_length - s
# print(ans1)
left_length -= A[i]
ans2 = s - 2 * left_length
# print(ans2)
print(min(ans1, ans2))


Measured memory_bytes: 34200
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll pow(ll a, ll x, ll p){
  	ll tmp=1;
  	while(x>0){
    	if(x%2 == 1){
          	tmp = (a*tmp)%p;
        }
      	a = (a*a)%p;
      	x /= 2;
    }
  	return(tmp);
}

ll inv(ll a, ll p){
  	return pow(a,p-2,p);
}

ll factorial(ll n, ll p){
  	ll res = 1;
  	for(ll i=1;i<=n;i++){
      	res = (res*i)%p;
    }
  	return res;
}

ll combination(ll n, ll r, ll p){
  	ll res=1;
  	ll tmp1 = factorial(n,p);
  	ll tmp2 = factorial(n-r,p);
  	ll tmp3 = factorial(r,p);
  	res = ( ( (tmp1 * inv(tmp2,p) ) % p) * inv(tmp3,p) ) % p;
  	return res;
}

int main(){
    ll X,Y;
  	cin >> X >> Y;
  	if((X+Y)%3!=0){
		cout << 0 << endl;
      	return(0);
    }

  	ll a,b;
  	a = (-X+2*Y)/3;
  	b = (2*X-Y)/3;
  	if(a < 0 || b < 0){
      	cout << 0 << endl;
      	return(0);
    }
    //cout << a << " " << b << endl;
  	cout << combination(a+b,a,mod) << endl;
  	
    return(0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=30;

char s[maxn];
int tmp[maxn];
int n;
bool used[maxn];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if (n<26)
	{
		for(int i=1;i<=n;i++)
		{
			used[s[i]-'a'+1]=true;
			putchar(s[i]);
		}
		for(int i=1;i<=26;i++)
			if (!used[i])
			{
				putchar(i+'a'-1);
				return 0;
			}
	}
	
	for(int i=1;i<=n;i++) 
		tmp[i]=s[i]-'a'+1;
	for(int i=1;i<=26;i++) used[i]=true;
	int pos=-1,rep;
	for(int i=26;i>=1;i--)
	{
		for(int j=tmp[i];j<=26;j++)
			if (!used[j])
			{
				pos=i;rep=j;
				break;
			}
		if (pos==i) break;
		used[tmp[i]]=false;
	}
	
	if (pos==-1)
	{
		puts("-1");
		return 0;
	}
	
	for(int i=1;i<pos;i++) putchar(s[i]);
	putchar(rep+'a'-1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=53*p[k]*(i+1-last[k])/10;
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

Measured memory_bytes: 3700
#include <stdio.h>
#define MAX_N 100

int main(){
    int N, a[MAX_N];
    int heikin, sum=0, i;
    int cost=0;
    
    scanf("%d", &N);
    for (i=0; i<N; i++)
        scanf("%d", &a[i]);
    
    for (i=0; i<N; i++)
        sum += a[i];
    
    if (sum % N == 0) heikin = sum/N;
    else {
        if ((double)sum/N - sum/N < 0.5)
            heikin = sum/N;
        else
            heikin = sum/N + 1;
    }
    for (i=0; i<N; i++){
        cost += (a[i]-heikin)*(a[i]-heikin);
    }
    printf("%d\n", cost);
    
    return 0;
}

Measured memory_bytes: 128
/*
Author: rafa45
Date: 26 Sep 2020
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 1000000007

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

    int k=0, i=0;

    string s="";

    cin >> k;

    for(i=1; i<=k; i++){
        s += "ACL";
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3644
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
 mid =i+1
 l=0
 r=i+2
 while r<N:
  if L[r]-L[l]<L[mid]:
   ans+=(mid-l)
   r+=1
  else:
   if l==mid-1:
    r+=1
   else:
    l+=1
print(ans)

Measured memory_bytes: 41708
#include<bits/stdc++.h>
using namespace std;
#define N 1111116

int w,h,n,l[N],r[N],f[N],g[N],ans;

struct node{int x,y;}a[N];
vector<node> ql,qr;
bool cmp(node a,node b){return a.y<b.y;}

void build(int t,int x,int y){
	l[t]=x;r[t]=y;f[t]=0;g[t]=0;
	if (x==y) return;
	build(2*t,x,(x+y)/2);
	build(2*t+1,(x+y)/2+1,y);
}

void modify(int t,int x,int y,int z){
	if (x<=l[t]&&y>=r[t]) {f[t]+=z;g[t]+=z;return;};
	if (x<=r[2*t]) modify(2*t,x,y,z);
	if (y>=l[2*t+1]) modify(2*t+1,x,y,z);
	f[t]=max(f[2*t],f[2*t+1])+g[t];
}

void solve(){
	sort(a+1,a+n+1,cmp);
	build(1,0,n);modify(1,0,0,w);
	ql.clear();ql.push_back((node){0,-1});ql.push_back((node){0,0});
	qr.clear();qr.push_back((node){w,-1});qr.push_back((node){w,0});
	for (int i=1;i<=n;i++){
		ans=max(ans,(f[1]+a[i].y)*2);
		if (a[i].x<=w/2){
			for (int j=ql.size()-1;j&&ql[j].x<=a[i].x;ql.pop_back(),j--)
				modify(1,ql[j-1].y+1,ql[j].y,ql[j].x-a[i].x);
			ql.push_back((node){a[i].x,i-1});
		}
		else {
			for (int j=qr.size()-1;j&&qr[j].x>=a[i].x;qr.pop_back(),j--)
				modify(1,qr[j-1].y+1,qr[j].y,a[i].x-qr[j].x);
			qr.push_back((node){a[i].x,i-1});
		}
		ql.push_back((node){0,i});
		qr.push_back((node){w,i});
		modify(1,i,i,w-a[i].y);
	}
	ans=max(ans,(f[1]+h)*2);
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	w=read();h=read();n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	solve();
	for (int i=1;i<=n;i++) swap(a[i].x,a[i].y);
	swap(h,w);solve();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 24436
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int AB = scan.nextInt();
		int X = scan.nextInt();
		int Y = scan.nextInt();
		System.out.println(search(A,B,AB,X,Y));
	}

	public static int search(int A,int B,int AB,int X,int Y) {
		int ans = Integer.MAX_VALUE;
		int I = X>Y? X : Y;

		for(int i = 0; i <= I; i++) {
			int a = Math.max(X - i,0);
			int b = Math.max(Y - i,0);
			ans = Math.min(ans,a*A + b*B + 2*i*AB);
		}
		return ans;
	}
}


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

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        A[i]--;
    }
    // 次番号 nx[i] ∈ [0,nx.size()) ∪ -1, -1は次番号なし
    auto DoublingBuild = [](vector<int>& nx, int k_max) {
        vector<vector<int>> tb(k_max+1, vector<int>(nx.size()));
        for ( int i = 0; i < nx.size(); i++ ) {
            tb[0][i] = nx[i];
        }
        for ( int k = 1; k <= k_max; k++ ) {
            for ( int i = 0; i < nx.size(); i++ ) {
                if ( tb[k-1][i] < 0 ) tb[k][i] = -1;
                else tb[k][i] = tb[k-1][tb[k-1][i]];
            }
        }
        return tb;
    };
    auto DoublingQuery = [](vector<vector<int>>& tbl, int start, ll step) {
        int r = start;
        for ( int k = 0; k < 63; k++ ) {
            if ( r < 0 ) break;
            if ( (step >> k) & 1 ) r = tbl[k][r];
        }
        return r;
    };
    auto d = DoublingBuild(A, 70);
    ll ans = DoublingQuery(d, 0, K) + 1;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 60508
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=2.5e3+2;

template <typename _Tp> inline void IN(_Tp&x) {
    char ch;bool flag=0;x=0;
    while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    if(flag) x=-x;
}

int head[N],dis[N],vis[N],QAQ[N],cnt,n,m,p;
struct Edge {int nxt,w,to;} G[N<<1]; 
inline void add(int u,int v,int w) {
	G[++cnt].nxt=head[u],G[cnt].to=v,G[cnt].w=w,head[u]=cnt;
}
inline void Spfa() {
	memset(dis,127,sizeof(dis));
    int inf=-(1e9+7);
	deque<int> q;q.push_back(1),dis[1]=0,vis[1]=true;
	while(!q.empty()) {
		int u=q.front();q.pop_front();++QAQ[u],vis[u]=false;
        if(QAQ[u]>=n) dis[u]=inf;
		for(int i=head[u];i;i=G[i].nxt) {
			int v=G[i].to;
			if(dis[u]+G[i].w<dis[v]&&QAQ[v]<n) {
				dis[v]=dis[u]+G[i].w;     
			    if(vis[v]==false)
				    v<q.front()?q.push_front(v):q.push_back(v),vis[v]=true; 
		    }
		}
	}
}

int main() {
    // freopen("G.in","r",stdin);
    // freopen("G.out","w",stdout);
    IN(n),IN(m),IN(p);
    for(int i=1,a,b,c;i<=m;++i)
        IN(a),IN(b),IN(c),add(a,b,-(c-p));
    Spfa();
    if(dis[n]<-5e8) puts("-1");
    else printf("%d\n",(dis[n]<0)?-dis[n]:0);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define up(i,j,n) for( int i=j;i<=n;i++)
#define down(i,j,n) for( int i=j;i>=n;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define FILE "dealing"
#define ull unsigned int
int read(){
	int x=0,ch=getchar(),f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}

template<class T> bool cmin(T& a,T b){return a>b?a=b,true:false;}
template<class T> bool cmax(T& a,T b){return a<b?a=b,true:false;}
template<class T> T squ(T a){return a*a;}
const int maxn=305000,inf=1000000000,limit=100000,mod=1e9+7;
int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
int sub(int a,int b){return (a-=b)<   0?a+mod:a;}
int mul(int a,int b){return 1LL*a*b%mod;}
int n;
int a[maxn],b[maxn];
int fac[maxn],inv[maxn],f[maxn];
int l,r;
int C(int n,int m){
	if(n<m||n<0||m<0)return 0;
	return mul(fac[n],mul(inv[m],inv[n-m]));
}
int main(){
//	freopen(FILE".in","r",stdin);freopen(FILE".out","w",stdout);
	n=read();
	
	fac[0]=1;
	up(i,1,n+1)fac[i]=mul(fac[i-1],i);
	
	inv[0]=inv[1]=1;
	up(i,2,n+1)inv[i]=sub(mod,mul(inv[mod%i],mod/i));
	up(i,1,n+1)inv[i]=mul(inv[i-1],inv[i]);
	
	up(i,1,n+1){
		a[i]=read();
		if(!b[a[i]])
			b[a[i]]=i;
		else
			l=b[a[i]],r=i;
	}
	up(i,1,n+1)f[i]=C(n+1,i);
	up(i,1,n+1)f[i]=sub(f[i],C(n+1-(r-l+1),i-1));
	up(i,1,n+1)printf("%d\n",f[i]);
	return 0;
}





Measured memory_bytes: 4480
import sys, collections, heapq
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    N, Q = map(int, line_input())
    event = []
    for i in range(N):
        s, t, x = map(int, line_input())
        event.append((s-x, 1, x))
        event.append((t-x,-1, x))
    for i in range(Q):
        d = int(single_input())
        event.append((d, 2, d))
    event.sort()
    candidate = []
    heapq.heapify(candidate)
    stop = collections.defaultdict(int)
    ans = ""
    for time, parameter, co in event:
        if parameter == 1:
            heapq.heappush(candidate, co)
            stop[co] += 1
        elif parameter == -1:
            stop[co] -= 1
        else:
            while candidate:
                x = heapq.heappop(candidate)
                if stop[x] > 0:
                    heapq.heappush(candidate, x)
                    ans += str(x) + "\n"
                    break
            else: ans += "-1\n"
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 97732
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

uint64_t solve(const vector<pair<int, int>>& mat) {
  if (mat.size() < 2) {
    return 0ULL;
  }
  auto n = mat.size();
  vector<vector<uint64_t>> cache(n - 1, vector<uint64_t>(n, no_value));
  for (size_t range = 2; range <= n; ++range) {
    for (size_t first = 0; ; ++first) {
      auto last = first + range - 1;
      if (last == n) {
        break;
      }
      for (size_t mid = first; mid != last; ++mid) {
        auto lhs = first == mid ? 0 : cache[first][mid];
        auto rhs = (mid + 1) == last ? 0 : cache[mid + 1][last];
        auto mul = mat[first].first * mat[last].second * mat[mid].second;
        cache[first][last] = min(cache[first][last], lhs + rhs + mul);
      }
    }
  }
  return cache[0][n - 1];
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> mat;
  for (int i = 0; i < n; ++i) {
    int row, col;
    cin >> row >> col;
    mat.push_back(make_pair(row, col));
  }
  uint64_t result = solve(mat);
  cout << result << endl;
}

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> x;
	vector<int> in;
	for (int i = 0;i < n;i++){
		int c; cin >> c;
		x.push_back(c);
		in.push_back(c);
	}	

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

	int cent = x[n/2 - 1];

	for (int i = 0;i < n;i++){
		if(in[i] <= cent) cout << x[n/2] << endl;
		else cout << x[n/2-1] << endl;
	}

	return 0;

}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A, cnt = 0;
  while (cin >> A) if (A % 2) cnt++; 
  cout << (!(cnt % 2) ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long a = scan.nextLong();
		long b = scan.nextLong();

		long ans = (n / (a + b)) * a;
		long mod = n % (a + b);
		ans += Math.min(mod, a);

		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local S = read.l()
local T = {}
T.Sunny = "Cloudy"
T.Cloudy= "Rainy"
T.Rainy = "Sunny"
print(T[S])

Measured memory_bytes: 1008
A, B, times = map(int,input().split())

temp = 0
temp1 = 0
divisor = []
counter = 0

if A >= B:
  temp = A
  temp1 = B

else:
  temp = B
  temp1 = A

for i in range(1,temp1+1):
  if temp1 % i == 0:
    divisor.append(i)

for j in (reversed(divisor)):
  if temp % j ==0:
    counter += 1
    if counter == times:
      print(j)
      break
  



Measured memory_bytes: 3060
N = int(input())
T = [0, 0, 0]
ans = "Yes"
for _ in range(N):
    t = list(map(int, input().split()))
    k = abs((t[1]+t[2])-(T[1]+T[2]))
    n = t[0]-T[0]
    if n % 2 == 0:
        if k > n or k % 2 != 0:
            ans = "No"
    else:
        if k > n or k % 2 == 0:
            ans = "No"
    T = t

print(ans)

Measured memory_bytes: 9172
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
#define maxn 200005
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline ll read()
{
    ll 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;
}
ll to[maxn];
ll vis[maxn];
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	ll n=read();
	ll k=read();
	for(ll i=0;i<=maxn-1;i++) vis[i]=-1;
	for(ll i=1;i<=n;i++) to[i]=read();
	vis[1]=0;
	ll p=1;
	for(ll i=1;i<=k;i++){
        p=to[p];
        if(i==k){
            printf("%lld\n",p);
            return 0;
        }
        else if(vis[p]!=-1){
            if(i-vis[p]==1){
                cout<<p<<endl;
                return 0;
            }
            ll shen=k-i;
            ll pp=(i-vis[p]);
            ll nxt=shen%pp;
           // printf("p=%d\n",p);
            //printf("nxt=%d\n",nxt);
            if(nxt==0){
                cout<<p<<endl;
                return 0;
            }
            else{
                for(int j=i;j<=i+nxt;j++){
                        if(j==i+nxt){
                        cout<<p<<endl;
                        return 0;
                    }
                    p=to[p];

                }
            }

        }
        vis[p]=i;
    }
	return 0;
}


Measured memory_bytes: 6812
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
  	cin>>s>>t;
  	int m=s.length();
 	int n=t.length();
  	string ans="";
  	if(m==0 || n==0){
    	cout<<ans<<endl;
      	return 0;
    }
  	
  	int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (s[i-1] == t[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (s[i-1] == t[j-1]) 
      { 
          lcs[index-1] = s[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 	
  
  
  
  
  
  
  	cout<<lcs<<endl;
}

Measured memory_bytes: 38708
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

a,b = [int(i) for i in read().split()]


for i in range(10000):
    if i*8//100 == a and i*10//100 == b:
        print(i)
        break
else:
    print(-1)



Measured memory_bytes: 2940
n,m=map(int,input().split())
s=input()
t=input()
import fractions
x=n*m//(fractions.gcd(n,m))
n1=x//n
m1=x//m
x1=n1*m1//(fractions.gcd(n1,m1))
if n%m==0:
  for i in range(m):
    if t[i]!=s[n*i//m]:
      print("-1")
      exit()
  print(x)
  exit()
elif m%n==0:
  for i in range(n):
    if s[i]!=t[m*i//n]:
      print("-1")
      exit()
  print(x)
  exit()
else:
  for i in range(x//x1):
    if s[i*x1//n1]!=t[i*x1//m1]:
      print(-1)
      exit()
print(x)

Measured memory_bytes: 5304
# unihernandez22
# https://atcoder.jp/contests/abc166/tasks/abc166_e
# hashing, math, implementation
n = int(input())
a = list(map(int, input().split()))

x = []
y = {}

for i, elem in enumerate(a):
    x.append(i+a[i])
    y[i-a[i]] = y.get(i-a[i], 0) + 1

ans = 0

for i in x:
    ans += y.get(i, 0)

print(ans)



Measured memory_bytes: 46488
#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(){
    ll a, b, memo;
    cin >> a >> b;
    vector<ll> n(42);
    vector<ll> an(42);
    vector<ll> bn(42);
    rep(i, 42) n.at(i) = 0;
    rep(i, 42) an.at(i) = 0;
    rep(i, 42) bn.at(i) = 0;
    a;
    b++;
    rep(i, 42){
        memo = pow(2, i);
        an.at(i) = a/(memo*2)*memo + max(a%(memo*2)-memo, 0LL);
        bn.at(i) = b/(memo*2)*memo + max(b%(memo*2)-memo, 0LL);
    }
    rep(i, 42){
        if((bn.at(i) - an.at(i))%2 == 1) n.at(i) = 1;
    }
    ll ans = 0;
    rep(i, 42){
        if(n.at(i) == 1) ans += pow(2, i);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= int(1e6);



int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vi dp(n),h(n);
    for(int i = 0; i < n; i++) {
           cin >> h[i];
           dp[i] = INF;
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2 ; i < n ; i++) {
        dp[i] = min(dp[i],dp[i-1] + abs(h[i] - h[i-1]));
        dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout<<dp[n-1]; 

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>

int main() {
  int h1, m1, h2, m2, k;
  std::cin >>h1 >> m1 >> h2 >> m2 >> k;
  if (m2 < m1) {
    m2 += 60;
    --h2;
  }
  int len = m2 - m1 + (h2 - h1) * 60 - k;
  if (len < 0) len = 0;
  std::cout << len << std::endl;
  return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }



int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

    int n; 
    cin >> n;
    vector<int> a(n);
    vector<mint> b(n);

    
    rep(i, n) cin >> a[i];
    b[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
        b[i] = b[i + 1] + a[i+1];
    }

    mint ans;
    rep(i, n) {
        ans += a[i] * b[i].x;
    }

    cout << ans.x << endl;

	return 0;
}


Measured memory_bytes: 5572
s=input()
t=input()
flag=0
l1=list(s)
l2=list(t)
l1.sort()
l2.sort(reverse=True)
#print(l1,l2)
minlen=min(len(l1),len(l2))
for i in range(minlen):
    if (l1[i]<l2[i]):
        flag=1
        break
    if (l1[i]>l2[i]):
        flag=-1
        break

if flag==0:
    if (len(l1)<len(l2)):
        flag=1
    else:
        flag=-1
if flag==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int len = 100010;

typedef struct name {
	string s;
	int t;
} P,*Q;

int head = 0, tail = 0;
Q q = new P[len];
int n;

bool full() {
	if (head == (tail+1)%len) return true;
	else return false;
}

bool empty() {
	if (head  == tail ) return true;
	else return false;
}

void enque(P w) {
	if (!full()) {
		q[tail] = w;
		tail = (tail + 1) % len;
	}
	else cout << "no";
}

void deque() {
	if (!empty()) {
		head = (head + 1) % len;
	}
	else {
		cout << "no";
	}
}

P top() {
	return q[head];
}


int main() {

	int r, T = 0;
	cin >> n >> r;
	for (int i = 0; i < n; i++) {
		P a;
		cin >> a.s >> a.t;
		enque(a);
	}

	while (!empty()) {
		P a = top();
		if (a.t <= r) {
			T += a.t;
			cout << a.s << " " << T << endl;
			deque();
		}
		else {
			a.t -= r;
			T += r;
			deque();
			enque(a);
		}
		
	}
	
}


Measured memory_bytes: 7032
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  rep(i, N) cin >> x[i] >> y[i] >> h[i];
  int p = 0;
  rep(i, N) {
    if(h[i]) {
      p = i;
      break;
    }
  }
  int ax, ay, ah;
  rep(i, 101) rep(j, 101) {
    int top = h[p]+abs(i-x[p])+abs(j-y[p]);
    bool flag = true;
    rep(k, N) {
      if(max(top-abs(i-x[k])-abs(j-y[k]), 0) != h[k]) {
        flag = false;
        break;
      }
    }
    if(flag) {
      ax = i;
      ay = j;
      ah = top;
      break;
    }
  }
  cout << ax << ' ' << ay << ' ' << ah << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ll k;
   cin>>k;
   queue<ll> q;
   for(ll j=1;j<=9;j++)
   q.push(j);
  ll i=0;
  ll x=0;
while(i<k)
{
x=q.front();
q.pop();
if((x%10)!=0)
q.push(x*10+(x%10)-1);

q.push(x*10+(x%10));

if((x%10)!=9)
q.push(x*10+(x%10)+1);	
i++;
}
cout<<x<<endl;
return 0;
}



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

struct strc{
    int y;
    int x;
    int depth;
};

int H, W, y, x, depth;
char field[50][50];
queue<strc> q;

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

int main(){
    cin >> H >> W;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++) cin >> field[i][j];
    }
    int sy = 0, sx = 0, gy = H-1, gx = W-1, black = 0, ans;
    strc start = {sy, sx, 0};
    q.push(start);
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++) if (field[i][j] == '#') black++;
    }

    while (!q.empty()){
        strc now = q.front();
        q.pop();
        y = now.y; x = now.x; depth = now.depth;
        if (y == gy & x == gx) break;
        for (int dir = 0; dir < 4; dir++){
            strc next = {y + dy[dir], x + dx[dir], depth + 1};
            if (next.y >= 0 & next.y < H & next.x >= 0 & next.x < W & field[next.y][next.x] == '.'){
                q.push(next);
                field[next.y][next.x] = 'x';
            }
        }
    }
    if (field[gy][gx] == '.') ans = -1;
    else ans = H * W - (depth + 1) - black;
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
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...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll f[ohara], fr[ohara];

ll mod_pow(ll xx, ll nn, ll mod) {
  ll ret = 1;
  while (nn > 0) {
    if (nn & 1) ret = ret * xx % mod;
    xx = xx * xx % mod;
    nn >>= 1;
  }
  return ret;
}

ll ncr(ll nn, ll r) {
  if (nn < r) return 0;
  return f[nn] * fr[r] % MOD * fr[nn - r] % MOD;
}

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

  cin >> n >> k;
  f[0] = 1;
  rrep(i, 1, n + 3) { f[i] = f[i - 1] * i % MOD; }
  fr[n + 2] = mod_pow(f[n + 2], MOD - 2, MOD);
  rrrep(i, n + 1, 0) { fr[i] = fr[i + 1] * (i + 1) % MOD; }
  ans = 1;
  rrep(i, 1, min(n, k + 1)) {
    ans += ncr(n, i) * ncr(n - 1, i);
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll n;
    cin>>n;
    ll a[n+1];
    FOR(i,1,n)cin>>a[i];
    ll pref[n+1];
    pref[0]=0;
    for(int i=1;i<=n;i++)
    {
        pref[i]=pref[i-1]+a[i];
    }
    ll ans=INT64_MAX;
    for(int i=1;i<n;i++)
    {
        ans=min(ans,abs(pref[n]-pref[i]-pref[i]));
    }
    cout<<ans;
  }  
  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <math.h>
#define N 10000


void prime(int);

int main()
{
  int n,i;
  int array[N];
  int count=0,f,k=0,j;
  
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%d", &array[i]);
  }
  for(j=0;j<n;j++){
    k=0;
    for(i=2;i<=sqrt(array[j]);i++){
      f=array[j]%i;
      if(f==0){
	k=1;
      }
    }
    if(k==0){
	count++;
    }
  }
  printf("%d\n",count);

  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<int> lb(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < 30; j++) {
            if (a[i]&(1<<j)) {
                lb[i] = j;
                break;
            }
        }
    }

    bool f = false;
    int ans = 0;
    for (int j = 29; j >= 0; j--) {
        int cnt = f, cnt_lb = 0;
        for (int i = 0; i < n; i++) {
            if (a[i]&(1<<j)) {
                cnt++;
                if (lb[i]==j) cnt_lb++;
            }
        }
        
        if (cnt % 2 == 0) continue;
        if (cnt_lb > 0) {
            f = !f;
            ans++;
        } else {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

bool sign=false;
long long n;
long long ans[4];
vector<long long> num;

void dfs(int x,long long left){
	if(x==3){
		if(left==0) sign=true;
		return;
	}else{
		for(int i=0;i<num.size();i++)
			if(left>=num[i]){
				ans[x]=num[i];
				dfs(x+1,left-num[i]);
				if(sign) return;
			}
	}
}

int main(){
	cin>>n;
	long long nn=n,m=4;
	while(true){
		//cout<<n<<" "<<m<<endl;
		num.clear();
		for(int i=1;i<=n;i++) if(n%i==0) num.push_back(i);
		dfs(0,m);
		if(sign){
			cout<<n/ans[0]<<" "<<n/ans[1]<<" "<<n/ans[2]<<endl;
			return 0;
		}
		n+=nn;
		m+=4;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e6+10;
int n,x,y,v[N],f[N];
int tot,fi[N],a[N<<1],ne[N<<1];
inline void add(int x,int y){
	a[++tot]=y;ne[tot]=fi[x];fi[x]=tot;
}
inline int dp(int x){
	if (f[x]) return f[x];
	f[x]=-1;
	for (int i=fi[x];i;i=ne[i]) f[x]=max(f[x],-dp(a[i]));
	return f[x];
}
int main(){
//	freopen("C.in","r",stdin);freopen("C.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",v+i);
	for (int i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		if (v[x]>v[y]) add(x,y);
		if (v[x]<v[y]) add(y,x);
	}
	for (int i=1;i<=n;++i) if (dp(i)==1) printf("%d ",i);
	return 0;
}

Measured memory_bytes: 8448
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int V[300000], W[300000];

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


	int X, N;
	cin >> X >> N;
	int P[200] = {};
	rep(i, N) {
		int p;
		cin >> p;
		P[p] = 1;
	}

	int kotae = 0;
	int saishou = 200;
	rep(i, 200) {
		if (P[i]) continue;
		int d = abs(i - X);
		if (saishou > d) {
			saishou = d;
			kotae = i;
		}
	}


	co(kotae);



	Would you please return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  ll a[N]; rep(i,N) cin >> a[i];
  ll b[N]; rep(i,N) cin >> b[i];
  ll sum = 0; rep(i,N) sum += a[i]>b[i] ? b[i]-a[i] : (b[i]-a[i])/2;
  string result = sum>=0 ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N, 0);
    for(int i=0;i<N;i++) {
        cin >> A[i];
    }
    vector<vector<ll>> dp(N, vector<ll>(3, LLONG_MIN));
    for(int i=0;i<N;i++){
        if(i==0){
            dp[i][0] = A[i];
            dp[i][1] = 0ll;
            dp[i][2] = 0ll;
        }else if(i==1){
            dp[i][0] = 0ll;
            dp[i][1] = A[i];
            dp[i][2] = 0ll;
        }else if(i==2){
            dp[i][0] = dp[i-2][0] + A[i];
            dp[i][1] = dp[i-2][1] + A[i];
            dp[i][2] = dp[i-2][2] + A[i];
        }else if(i==3){
            dp[i][0] = dp[i-2][0] + A[i];
            dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + A[i];
            dp[i][2] = max(dp[i-2][2], dp[i-3][1]) + A[i];
        }else{
            dp[i][0] = dp[i-2][0] + A[i];
            dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + A[i];
            dp[i][2] = max(dp[i-2][2], max(dp[i-3][1], dp[i-4][0])) + A[i];
        }
    }
    if(N % 2 == 0){
        cout << max(dp[N-1][1], dp[N-2][0]) << endl;
    }else{
        cout << max(dp[N-1][2], max(dp[N-2][1], dp[N-3][0])) << endl;
    }
    return 0;
}


Measured memory_bytes: 15640