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


#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
 
using namespace std;
using ll = long long;
typedef pair<int, int> Pair;
 
const int MOD = 1000000007;
 
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
 
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
 
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}
 
mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
 

int main() {
  int N, K;
  cin >> N >> K;

  for (int i = 1; i <= K;i++) {
    cout << H(i,K-i) * H(i+1,N-K-i+1) << '\n';
  }
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def main():
    N ,K = ints_raw()
    Vs = ints_raw()
    N = len(Vs)
    leftSum = [0]
    leftNegas = [[]]
    for v in Vs:
        leftSum.append(leftSum[-1]+v)
        neoNega = leftNegas[-1]
        if v<0:
            neoNega = neoNega+[v]
            neoNega.sort()
        leftNegas.append(neoNega )


    rightSum = [0]
    rightNegas = [[]]
    for v in Vs[::-1]:
        rightSum.append(rightSum[-1]+v)
        neoNega = rightNegas[-1]
        if v<0:
            neoNega = rightNegas[-1]+[v]
            neoNega.sort()
        rightNegas.append(neoNega )

    ans = 0
    for left_k in range(K+1):
        left_total = 0
        left_n = 0
        for n in range(min(N+1,left_k+1)):
            tmp = leftSum[n] - (sum(leftNegas[n]) if len(leftNegas[n])<=left_k-n else sum(leftNegas[n][:left_k-n]))
            if left_total < tmp:
                left_total = tmp
                left_n = n
        right_total = 0
        right_n = 0
        right_k = K -left_k
        for n in range(min(K-left_k+1,N-left_n+1)):
            tmp = rightSum[n] - (sum(rightNegas[n]) if len(rightNegas[n])<=right_k-n else sum(rightNegas[n][:right_k-n]))
            if right_total < tmp:
                right_total = tmp
                right_n = n
        ans = max(ans,left_total+right_total)
    return ans

print(main())


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

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

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

	int N = 50;
	vector<int> a(N);


	auto f = [&](vector<int> a) {
		int cnt = 0;
		while (true) {
			bool ok = true;
			rep(i, 0, N) {
				if (a[i] >= N)
					ok = false;
			}
			if (ok)break;
			auto m = max_element(all(a));
			int k = (*m - (N - 1)) / N + !!((*m - (N - 1)) % N);
			int mi = m - a.begin();
			cnt += k;
			rep(i, 0, N) {
				if (i == mi)
					a[i] -= k*N;
				else
					a[i] += k;
			}
		}
		return cnt;
	};

	int x = K / N;
	K %= N;
	rep(i, 0, 50) {
		a[i] = 49 + x;
		if (i < K)
			a[i] += N - K + 1;
		else
			a[i] -= K;
	}
	dump(f(a), a);
	cout << N << endl;
	cout << a[0]; rep(i, 1, a.size()) { cout << " " << a[i]; } cout << endl;

	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s,t,u;cin>>s>>t;
  int a,b;cin>>a>>b;
  cin>>u;

  if(s==u)a--;
  else b--;
  cout<<a<<' '<<b<<endl;

  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rerep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
int main(void) {
	int N, M, count = 0;
	vector<pair<int, int>> c;
	cin >> N >> M;
	int min=0;
	rep(i, M) {
		int tmp, tmp2;
		cin >> tmp >> tmp2;
		c.push_back(pair<int,int>(tmp2,tmp));
	}
	sort(c.begin(), c.end());
	min = c[0].first;
	count++;
	for (int i = 0; i < M;i++) {
		if (min <= c[i].second) {
			min = c[i].first;
			count++;
		}
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<math.h>
 
typedef struct{
  double x;
  double y; 
}xy;

void kock(int n,xy p1,xy p2){  
  xy s,t,u;
  if (n==0) return ;
  s.x=(2.0*p1.x+1.0*p2.x)/3.0;
  s.y=(2.0*p1.y+1.0*p2.y)/3.0;
  t.x=(1.0*p1.x+2.0*p2.x)/3.0;
  t.y=(1.0*p1.y+2.0*p2.y)/3.0;
  u.x=(t.x-s.x)*(cos(M_PI/3.0))-(t.y-s.y)*(sin(M_PI/3.0))+s.x;
  u.y=(t.x-s.x)*(sin(M_PI/3.0))+(t.y-s.y)*(cos(M_PI/3.0))+s.y;
  kock(n-1,p1,s);
  printf("%lf %lf\n",s.x,s.y); 
  kock(n-1,s,u);
  printf("%lf %lf\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%lf %lf\n",t.x,t.y);
  kock(n-1,t,p2);
}
int main( ){
  xy p1,p2;
  int n;
  p1.x=0.0;
  p1.y=0.0;
  p2.x=100.0;
  p2.y=0.0;
  scanf("%d",&n); 
  printf("%lf %lf\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%lf %lf\n",p2.x,p2.y); 
  return 0;
}
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
void repeat(int x,int y){
	while(x--) cout<<y;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
   int a,b;
   cin>>a>>b;
   if(a>=b) repeat(a,b); else repeat(b,a);	

   return 0;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  ll h, w;
  cin >> h >> w;
  vector < vector < char > > a(h, vector < char > (w));
  for(int i = 0 ;i < h; i++){
    for(int j = 0; j < w; j++) cin >> a[i][j];
  }

  vector < vector < ll > > dp(h, vector < ll > (w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[i][j] == '#') dp[i][j] = 0;
      else{
        if(i == 0 && j == 0) dp[i][j] = 1;
        else if(i == 0) dp[i][j] = dp[i][j - 1];
        else if(j == 0) dp[i][j] = dp[i - 1][j];
        else dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      }
      dp[i][j] %= mod;
    }
  }

  cout << dp[h - 1][w - 1] << '\n';
}


Measured memory_bytes: 9088
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<LL> X(N);
	for(int i=0;i<N;++i){
		cin >> X[i];
	}
	const int P_MAX = 100001;
	vector<bool> Bprime(P_MAX+1,true);
	vector<int> prime;
	for(int i=2;i<=P_MAX;++i){
		if( Bprime[i] ){
			prime.push_back(i);
			for(int j=i+i;j<=P_MAX;j+=i){
				Bprime[j] = false;
			}
		}
	}
	const int P_size = prime.size();
	//cout << P_size << endl;
	int index = lower_bound(prime.begin(),prime.end(),2200) - prime.begin();
	//cout << index << endl;
	
	map< vector<vector<int> >,int > MAP;
	int rrr = 0;//立方数の個数
	int NoPair = 0;//ペアになれない数の個数
	for(int i=0;i<N;++i){
		LL temp = X[i];
		vector< vector<int> > dat(2);
		for(int j=0;j<index;++j){
			if( temp%prime[j] == 0 ){
				int pNum = 0;
				while(temp%prime[j] == 0 ){
					temp /= prime[j];
					++pNum;
				}
				if(pNum%3){
					dat[(pNum%3)-1].push_back( prime[j] );
				}
			}
		}
		
		if( temp != 1 ){//2200より大きい素数が残っている。
			vector<int>::iterator itr;
			itr = lower_bound(prime.begin(),prime.end(),temp);
			//素数の1乗
			//P_MAXより大きい素数は立方数のペアがいない(q<=10^10)
			if( itr != prime.end() ){
				if( (*itr) == temp ){
					dat[0].push_back( temp );
					temp = 1;
				}
			}
			if( temp != 1 ){//素数の2乗
				LL var = sqrt( 1.0*temp );
				if( var*var == temp ){
					dat[1].push_back( var );
					temp = 1;
				}
			}
			if( temp == 1 ){
				MAP[ dat ]++;
			}else{
				//pq型,ペアにならない
				NoPair++;
			}
		}else if( (dat[0].size() == 0) && (dat[1].size() == 0) ){
			//立方数
			++rrr;
			continue;
		}else{
			MAP[ dat ]++;
		}
		
	}

	map< vector<vector<int> >,int >::iterator itr,end;
	itr = MAP.begin();
	end = MAP.end();
	LL ans = 0;
	for(;itr!=end;++itr){
		int L = itr->second;
		if( L == 0 ) continue;
		vector< vector<int> > ter;
		ter = itr->first;
		swap( ter[0],ter[1] );
		int R = MAP[ ter ];
		ans += max(L,R);
		if( R ){
			MAP[ ter ] = 0;
		}
	}
	if( rrr ) ++ ans;//立方数は一つだけ加える
	cout << ans + NoPair << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 30720
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s, t;
  cin >> s >> t;
  int count = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3828
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

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

	int r;
	cin >> r;

	int maxv = -1000000000;
	int minv = r;
	for (int i = 1; i < n; i++)
	{
		cin >> r;
		maxv = max(maxv, r - minv);
		minv = min(minv, r);		
	}

	cout << maxv << endl;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

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

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================

int main(){
  int n, h, w; cin >> n >> h >> w;
  int a, b, ans = 0;
  REP(i, n){
    cin >> a >> b;
    ans += MIN(a / h,b / w);
  }
  cout << ans << "\n";
  return 0;
}

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

int main(){
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  int cnt=0;
  int ans=0;
  char pre = 'a';
  if(S[0]>pre){
    cout<<pre<<endl;
    return 0;
  }
  for(int i=0; i<S.length(); i++){
    if(S[i]==pre){
      //cout<<"同じ"<<endl;
    }else if(S[i]==pre+1){
      //cout<<"次"<<endl;
    }else{
      ans=pre+1;
      break;
    }
    pre=S[i];
  }
  if(ans>0){
    cout<<(char)(ans)<<endl;
  }else if(pre!='z'){
    cout<<(char)(pre+1)<<endl;
  }else{
    cout<<"None"<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
const int N=2e5+5,p=1e9+7;
typedef long long ll;
struct node {
	int a,b,c;
	void operator +=(const node &x){
		c=((ll)(a+b+c)*x.c+(ll)(b+c)*x.b+c*(ll)x.a)%p;
		b=((ll)a*x.b+(ll)b*x.a)%p;
		a=(ll)a*x.a%p;
	}
}v;
vector<node> q[N];
int h[N],l[N],r[N],t;
void dfs(int x){
	if(!h[x]){
		q[r[x]=++t].push_back(v);
		return;
	}
	int m=0,y,z;
	for(int i=h[x];i;i=l[i]){
		dfs(i);
		if(i==h[x]){r[x]=r[i];continue;}
		y=q[r[x]].size(),z=q[r[i]].size();
		m=max(m,min(y,z));
		if(y<z) swap(y,z),swap(r[x],r[i]);
		for(int j=1;j<=z;++j)
			q[r[x]][y-j]+=q[r[i]][z-j];
	}
	m=q[r[x]].size()-m;
	for(int j=q[r[x]].size()-1;j>=m;--j){
		q[r[x]][j].a=(q[r[x]][j].a+q[r[x]][j].c)%p;
		q[r[x]][j].c=0;
	}
	q[r[x]].push_back(v);
}
ll P(int y){ll x=2,z=1;for(;y;y>>=1,x=x*x%p) if(y&1) z=z*x%p;return z;}
int main(){
	int n,x,s=0;
	scanf("%d",&n);
	v=(node){p+1>>1,p+1>>1,0};
	for(int i=1;i<=n;++i){
		scanf("%d",&x);
		l[i]=h[x],h[x]=i;
	}
	dfs(0);
	for(int i=q[r[0]].size()-1;i>=0;--i) s=(s+q[r[0]][i].b)%p;
	printf("%d\n",(ll)s*P(n+1)%p);
	return 0;
}

Measured memory_bytes: 22900
#include <iostream>
#include <vector>
#include <string>
#include <set>
#define ll long long int
using namespace std;
 
int main()
{
    ll a ,b ,c ;
    cin>>a>>b>>c;
    ll ans = 0 ;
    if(a==b && b ==c)
    { 
          if(a % 2  != 0 )
          ans = 0;
else
        ans = -1;

     }
     else{
    while(a % 2 == 0 && b % 2 == 0 && c % 2 ==0)
    {
        ll ai ,bi ,ci ;
        ai = a ;
        bi = b ;
        ci = c ;
        a = bi/2 + ci/2 ;
        b = ai/2 + ci/2 ;
        c =ai/2 + bi/2 ;
        ans++;
        //cout<<a<<b<<c<<" \n";
    }
     }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define yabs(x) ((x<0)?(-(x)):(x))

const int N=1e7+5,Node=210;

struct Edge{ int to,next; }way[Node*Node];
int n,x[Node],prime[N],cntprime,tot,num[Node],put[Node];
bool v[N],notprime[N],use[Node];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void AddEdge(int a,int b) { Build(a,b); Build(b,a); }

void Init() {
	scanf("%d",&n);
	int x;
	for (int i=1;i<=n;++i) scanf("%d",&x),v[x]=1;
}

void Euler() {
	notprime[1]=1;
	for (int i=2;i<=10000000;++i) {
		if (!notprime[i]) prime[++cntprime]=i;
		for (int j=1;j<=cntprime && 1ll*i*prime[j]<=10000000;++j) {
			notprime[i*prime[j]]=1;
			if (!(i%prime[j])) break;
		}
	}
}

bool Dfs(int x) {
	for (int i=num[x];i;i=way[i].next) {
		int v=way[i].to;
		if (!use[v]) {
			use[v]=1;
			if (put[v]==-1 || Dfs(put[v])) {
				put[v]=x;
				return 1;
			}
		}
	}
	return 0;
}

void Solve() {
	Euler();
	int top=0,cnt1=0,cnt0=0;
	v[0]=0;
	for (int i=1;i<=10000001;++i) {
		bool fl=(v[i]!=v[i-1]);
		if (fl) x[++top]=i,cnt1+=i&1;
	}
	cnt0=top-cnt1;
	for (int i=1;i<=top;++i) if (x[i]&1) {
		for (int j=1;j<=top;++j) if (!(x[j]&1)) {
			if (!notprime[yabs(x[j]-x[i])]) {
				AddEdge(i,j);
			}
		}
	}
	int ans=0;
	for (int i=1;i<=top;++i) put[i]=-1;
	for (int i=1;i<=top;++i) if (x[i]&1) {
		memset(use,0,sizeof(use));
		if (Dfs(i)) ans++;
	}
	printf("%d\n",ans+(cnt0-ans)/2*2+(cnt1-ans)/2*2+(cnt0-ans)%2*3);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin >> S;

  int L = S / 100;
  int R = S % 100;

  if(1 <= L && L <= 12){
    if(1 <= R && R <= 12){
      cout << "AMBIGUOUS";
    }else cout << "MMYY";
  }else if(1 <= R && R <= 12){
    cout << "YYMM";
  }else cout << "NA";
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout << "Bad\n";
    else
        cout << "Good\n";
    return 0;
}




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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 1'000'005;

ll addM(ll a, ll b){
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll mulM(ll a, ll b){
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main(){
    int n, k;
    cin >> n >> k;
    
    COMBinit();
    
    ll ans = 0;
    k = min(k, n-1);
    // cout << k << endl;
    
    rep3(i, 0, k){
        ll tmp = mulM(COMB(n, i), COMB(n-1, i));
        ans = addM(ans, tmp);
    }
    
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 27096
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	char s[100], t[100], u[103];
	int a, b;
	scanf("%s %s", s, t);
	scanf("%d%d", &a, &b);
	scanf("%s", u);
	if(strcmp(s, u) == 0)	--a;
	else if(strcmp(t, u) == 0)	--b;
	printf("%d %d\n", a, b);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int 
#define endl '\n'
ll mod=1e9+7;

int main()
{
   FASTio;
    #ifndef ONLINE_JUDGE                    //file start
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
    #endif                                  //file end
    ll n,i,j,k;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    ll ans=0;
    sort(arr,arr+n);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            if(arr[j]==arr[i])
                continue;
            for(k=j+1;k<n;k++)
            {
                if(arr[k] == arr[j])
                    continue;
                if(arr[i]+arr[j]>arr[k])
                    ans++;
            }
            
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    string S; cin >> S;
    int a=0, b=0;
    rep(i, S.size()) {
        if (S[i] == '0') a++;
        else b++;
    }
    cout << min(a, b) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

uint32_t N;
uint32_t A[100000] = {};

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (uint32_t i = 0; i < N; ++i)
	{
		int32_t a;
		in >> a; --a;
		if (++A[a] >= 3) { A[a] = 1; }
	}

	uint64_t count = 0;
	bool n2 = false;
	for (uint32_t i = 0; i < 100000; ++i)
	{
		if (A[i] > 0)++count;
		if (A[i] == 2)n2 ^= true;
	}
	if (n2)--count;
	std::cout << count << std::endl;

	return 0;
}
#endif


Measured memory_bytes: 640
#include<stdio.h>
int main(void) {

	int i, k, n, x_1 = 0, x_2 = 0, x_3 = 0, r_1 = 0, r_2 = 0, x[100000];
	long long int min = 1000000000;

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

	for (i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}

	for (i = 0; i < n - k + 1; i++) {
		if (x[i] < 0) {
			x_1 = -x[i];
		}
		else {
			x_1 = x[i];
		}
		if (x[i + k - 1] < 0) {
			x_2 = -x[i + k - 1];
		}
		else {
			x_2 = x[i + k - 1];
		}
		if (x[i] - x[i + k - 1] < 0) {
			x_3 = -(x[i] - x[i + k - 1]);
		}
		else {
			x_3 = x[i] - x[i + k - 1];
		}
		r_1 = x_1 + x_3;
		if (r_1 < min) {
			min = r_1;
		}
		r_2 = x_2 + x_3;
		if (r_2 < min) {
			min = r_2;
		}

	}
	printf("%lld\n", min);

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int s,x;
  int data[1000000];
  scanf("%d",&s);
  data[0] = s;
  x = s;
  for(int i = 1;i < 1000000;i++){
    if(x%2 == 0){
      data[i] = x/2;
    }else{
      data[i] = 3*x+1;
    }
    x = data[i];
  }
  //ここから配列の同じ要素を探す
  for(int i = 0;i < 1000000;i++){
    for(int j = i+1;j < 1000000;j++){
      if(data[i] == data[j]){
        printf("%d",j+1);
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, bool> P;
#define MOD 1000000007

int main() {
    int N;
    cin >> N;
    vector<P> a(2 * N);
    for(int i=0; i<2*N; ++i) {
        cin >> a[i].first;
        a[i].second = (i < N ? true : false);
    }
    sort(begin(a), end(a));

    long long res = 1;
    int P = 0, C = 0;
    for(int i=0; i<2*N; ++i) {
        if(a[i].second) {
            if(C == 0) ++P;
            else {
                res *= C;
                res %= MOD;
                --C;
            }
        } else {
            if(P == 0) ++C;
            else {
                res *= P;
                res %= MOD;
                --P;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
    int X, Y;
    
    scanf("%d %d",&X,&Y);
    if(Y%2==1){
      printf("No");
    }else if(2*X<=Y && Y<=4*X){
      printf("Yes");
    }else{
      printf("No");
    }
return 0;
}

Measured memory_bytes: 1720
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> S;

signed main()
{
    cin >> N;
    S.resize(N);
    REP(i, N) { cin >> S[i]; }

    ll ans = 0;

    // C = A - B とすると、
    // B 移動では C * k の場所を取得でき、
    // A 移動では A + C * k の場所を取得する
    for(ll C = 1; C < N; ++C) {
        ll prev_val_a = 0;
        ll prev_ind_a = N-1;
        ll prev_val_b = 0;
        ll prev_ind_b = 0;
        if((N - 1)  % C == 0) {
            // A 移動でとる位置と B 移動でとる位置がかぶったらだめ
            // -> C が N - 1 の約数の場合
            for(ll k = 1; k < N / C; ++k) {
                // C を固定した場合、1 つ前のループの値が使いまわせる
                ll A = N - 1 - C * k;
                ll B = A - C;
                if(A <= 0 || B <= 0 || A <= B) { continue; }
                prev_ind_b += C;
                prev_val_b += S[prev_ind_b];
                if(prev_ind_a == prev_ind_b) { break; }
                prev_ind_a -= C;
                prev_val_a += S[prev_ind_a];
                if(prev_ind_a == prev_ind_b) { break; }
                if(prev_ind_a <= 0 || prev_ind_b >= N - 1) { break; }
                ans = max(ans, prev_val_a + prev_val_b);
            }
        }
        else {
            for(ll k = 1; k < N / C; ++k) {
                // C を固定した場合、1 つ前のループの値が使いまわせる
                ll A = N - 1 - C * k;
                ll B = A - C;
                if(A <= 0 || B <= 0 || A <= B) { continue; }
                prev_ind_b += C;
                prev_val_b += S[prev_ind_b];
                prev_ind_a -= C;
                prev_val_a += S[prev_ind_a];
                if(prev_ind_a <= 0 || prev_ind_b >= N - 1) { break; }
                ans = max(ans, prev_val_a + prev_val_b);
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

const int N = 2e5 + 10;

typedef long long ll;

ll n, t, a[ N ], ans;

int main() {
  cin >> n >> t;
  for ( int i = 0 ; i < n ; ++i )
    cin >> a[ i ];

  for ( int i = 0 ; i < n - 1 ; ++i ) {
    if ( a[ i + 1 ] - a[ i ] <= t )
      ans += a[ i + 1 ] - a[ i ];
    else
      ans += t;
  }
  cout << ans + t << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cctype>
#include <algorithm>

using namespace std;

typedef long long int lli;

int xdir[4] = {0, 1, 0, -1};
int ydir[4] = {-1, 0, 1, 0};
char a[101][101];
char dir[4] = {'N', 'E', 'S', 'W'};
int cnt[101][101][4];

int main()
{
  int h, w, p, q, d, dx, dy;
  lli l, dst;

  while(cin>>h>>w>>l && h+w+l){
    fill(&cnt[0][0][0], &cnt[101][0][0], -1);

    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j){
	cin >> a[i][j];
	if(isalpha(a[i][j])){
	  p = i; q = j;
	  if(a[i][j] == 'E') d = 1;
	  if(a[i][j] == 'N') d = 0;
	  if(a[i][j] == 'W') d = 3;
	  if(a[i][j] == 'S') d = 2;
	  a[i][j] = '.';
	  cnt[i][j][d] = 0;
	}
      }

    bool f = false;
    for(lli i = 1; i <= l; ++i){
      dy = p+ydir[d]; dx = q+xdir[d];
      if(0 <= dx && dx < w && 0 <= dy && dy < h && a[dy][dx] == '.'){
	p = dy; q = dx;
	if(!f){
	  if(cnt[p][q][d] == -1) cnt[p][q][d] = i;
	  else {
	    i = ((l-cnt[p][q][d])/(i-cnt[p][q][d]))*(i-cnt[p][q][d])+cnt[p][q][d];
	    f = true;
	  }
	}
      } else {
	--i;
	d = (d+1)%4;
      }
    }

    cout << (p+1) << " " << (q+1) << " " << dir[d] << endl;
  }

  return 0;
}

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

int64_t MOD = 1e9+7;

int64_t fact[1000005];

int64_t factorial(int n, int p) {
    return fact[n]%p;
}

//-RECIPE-START-//
// Use 64 bits integers to avoid overflow errors during multiplication.
int64_t modPow(int64_t a, int64_t x, int64_t p) {
    //calculates a^x mod p in logarithmic time.
    int64_t res = 1;
    while (x > 0) {
        if (x % 2)
            res = (res * a) % p;
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

int64_t modInverse(int64_t a, int64_t p) { // (assuming p is prime).
    return modPow(a, p-2, p); //calculates the modular multiplicative of a mod m.
}
int64_t modBinomial(int64_t n, int64_t k, int64_t p) { // calculates C(n,k) mod p (assuming p is prime).
    int64_t numerator = factorial(n, p); // n!
    int64_t denominator = (factorial(k, p)*(factorial(n-k, p)))%p; // k!*(n-k)!
    return ( numerator* modInverse(denominator,p) ) % p; // numerator / denominator mod p.
}

int main() {
    fact[0] = 1;
    for (int64_t i = 1; i <= 1e6; ++i) {
        fact[i] = (fact[i-1]*i)%MOD;
    }
    int R, C;
    cin >> R >> C;

    int d = C+R;

    if (d%3) {
        cout << 0 << endl;
        return 0;
    }

    int cb = d/3, rb = 2*(d/3);

    if (R > rb || C < cb) {
        cout << 0 << endl;
        return 0;
    }


    int diff = C-cb;

    // cout << "here " << cb << " " << rb << " " << diff << endl;
    if (R != rb-diff) {
        cout << 0 << endl;
        return 0;
    }

    if (diff > d/3) {
        cout << 0 << endl;
        return 0;
    }

    cout << modBinomial(d/3, diff, MOD) << endl;

}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef tuple<int,int,int>T;
const int mod =1e9+7;
vector< vector<int> >ab;

int ans;
void bfs(int x,vector<bool> a)
{
    if(find(a.begin(),a.end(),false)==a.end())
    {
        ans++;
        return ;
    }
    rep(i,ab[x].size())
    {
        if(!a[ab[x][i]])
        {
            a[ab[x][i]]=true;
            bfs(ab[x][i],a);
            a[ab[x][i]]=false;

        }
    }
    
    

}


int main()
{
    int n,m;
    cin>>n>>m;
    ans=0;
    ab=vector< vector<int> >(n);
    rep(i,m)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }
    vector<bool> temp(n,false);
    temp[0]=true;
    bfs(0,temp);
    cout<<ans;
    
}


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

#define SIZE 8
int q[SIZE], x[SIZE], data;

bool can_set(int n, int j)
{
    if(n == 0) return true;
    for(int i = 0; i < n; i++){
        if(q[x[i]] == j || x[i] + q[x[i]] == x[n] + j || x[i] - q[x[i]] == x[n] - j){ return false; }
	}
    return true;
}

bool set_queen()
{
    int n, j, s;
    n = data, s = 0;
    while((n < SIZE) && (n >= 0)){
        for(j = s; j < SIZE; j++){
            if(can_set(n, j)){
                q[x[n]] = j; n++; s = 0; break;
            }
        }
        if(j == SIZE){ n--; if(n >= 0){ s = q[x[n]] + 1; } }
    };
    if(n == SIZE) return true;
    return false;
}

void show_queen()
{
    for(int i = 0; i < SIZE; i++){
        for(int j = 0; j < SIZE; j++){
            (q[i] == j ? printf("Q") : printf(".") );
        }
        printf("\n");
    }
}

int main()
{
    scanf("%d", &data);
    int i, j;
    int a = (1 << 8) - 1;

    for(int k = 0; k < data; k++){
        scanf("%d %d", &i, &j);
        x[k] = i; a = a & ~(1 << i); q[i] = j; }
    i = 0;
    for(int k = 0; k < SIZE; k++){
        if(!!(a & (1 << k))){
            x[data + i] = k; i++; }
    }

    if(set_queen()) show_queen();
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

char st[1000000];

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s; cin >> s;
    int i = 500000, j = 500000;
    f(k, sz(s)){
      st[j] = s[k];
      j++;
    }
    bool reversed = 0 ;
    int q; cin >> q;
    while(q--){
      int t; cin >> t;
      if(t==1) reversed = !reversed;
      else{
        ll f; char c; cin >> f >> c;
        f--;
        if(!(reversed ^ f)){
          st[--i] = c;
        }else{
          st[j++] = c;
        }
      }
    }
    string t;
    fo(k, i, j){
      t +=  st[k];
    }
    if(reversed) reverse(all(t));
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 1364
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> p(n),q(n),a(n);
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  for(int i=0;i<n;i++){
    cin >> q[i];
  }
  for(int i=0;i<n;i++){
    a[i]=i+1;
  }
  int s,t,cnt=0;
  do{
    bool e=true,f=true;
    cnt++;
    for(int i=0;i<n;i++){
      if(p[i]!=a[i]){
        e=false;
      }
      if(q[i]!=a[i]){
        f=false;
      }
    }
    if(e){
      s=cnt;
    }
    if(f){
      t=cnt;
    }
  }while(next_permutation(a.begin(),a.end()));
  cout << abs(t-s) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<tuple>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll n, sum = 0;
	cin >> n;
	ll a[n];
	rep(n){
		cin >> a[i];
		sum += a[i];
	}
	if(sum % (n*(n+1)/2) != 0){
		cout << "NO";
		return 0;
	}
	ll m = sum / (n*(n+1) / 2);
	ll diff[n];
	diff[0] = a[0] - a[n-1] - m;
	reppp(i, 1, n-1){
		diff[i] = a[i] - a[i-1] - m;
	}
	bool flag = true;
	int count = 0;
	rep(n){
		if(diff[i] > 0 || diff[i] % n != 0){
			flag = false;
			break;
		}else{
			count += -diff[i] / n;
		}
	}

	if(flag){
		cout << "YES";
	}else{
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int A[400000];
int B[400000];
int main()
{
    int N,i,j,k,m;
    cin>>N;
    for(i=1; i<N; i++)
    {
        cin>>A[i];
    }
    sort(A+1,A+N);
    j=1;
    for(k=1;k<=N;k++)
    {
        B[k]=0;
    }
    for(i=1; i<N-1; i++)
    {
        if(A[i]==A[i+1])
        {
            j=j+1;
        }
        else
        {
            B[A[i]]=j;
            j=1;
        }
    }
    B[A[N-1]]=j;
    for(m=1; m<=N; m++)
    {
        cout<<B[m]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5156
A,B = map(int,input().split())
S = list(input())
judge = 1

if(len(S) < A):
  judge = 0
for i in range(len(S)):
 if(i == A):
  if(S[i] != '-'):
    judge = 0
    break
 else:
  if(S[i] == '-'):
    judge = 0
    break
    
if(judge == 0):
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3064
n, m = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
d = {0:0}
for i in range(1, n + 1):
    min_ = n + 1
    for j in C:
        if i - j in d:
            tmp = d[i - j] + 1
            if tmp < min_:
                min_ = tmp
    d[i] = min_
print(d[n])


Measured memory_bytes: 11944
//SILENT KILLER
#include<bits/stdc++.h>
//typedef long long ll;
using namespace std;
#define PI 3.14159265358979323846
int main()
{
    long double A,B,H,M;
    cin >> A >> B >> H >> M;
   long double theta = 2*PI*((H+M/60)/12 - M/60);
    long double c = sqrtl(A*A + B*B - 2*A*B*cos(theta));
    cout  << setprecision(20) << c << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, h, w, d);
    
    vc<pair<int, int>> pos(h*w+1);
    For(i, h) For(j, w){
        Cin(int, a);
        pos[a] = {i, j};
    }
    
    vc<int> sum(h*w, 0);
    for(int i = d+1; i <= h*w; i ++){
        sum[i] = sum[i-d] + abs(pos[i].first - pos[i-d].first) + abs(pos[i].second - pos[i-d].second);
    }
    
    Cin(int, q);
    Rep(q){
        Cin(int, l, r);
        Cout(sum[r] - sum[l]);
    }
}




Measured memory_bytes: 2176
#include <stdio.h>

int sort(int *p_num, int nn){
	int i, v, j, k;

	for(i=1; i<=nn-1; i++){
		v = p_num[i];
		j = i - 1;
		while( j >= 0 && p_num[j]> v ){
			p_num[j+1] = p_num[j];
			j--;
		}
		p_num[j+1] = v;
		for( k=0; k<nn; k++ ){
			printf("%d", p_num[k]);
			if(k == nn-1) continue;
			printf(" ");
		}
		printf("\n");
	}
	return 0;
}
int main(){
	int i, n, num[1000];

	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf(" %d", &num[i]);
	}

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

	sort(&num[0], n);

//	printf("hello\n");

	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 608
from collections import deque
N, M, Q = map(int, input().split())
A = [list(map(int, input().split())) for i in range(Q)]

def calc(x): # type(x) == str型
    ans = 0
    for a, b, c, d in A:
        if int(x[b-1]) - int(x[a-1]) == c:
            ans += d
    return ans

q = deque([[1]]) # 外の括弧はdeque()にイテラブル渡すため、内の括弧は数列を[1, 2, 3]というようにリストで管理するため
ans = 0
while q:
    tmp = q.popleft() #>>> [1]
    if len(tmp) == N:
        ans = max(ans, calc(tmp))
    else:
        for i in range(tmp[-1], M+1): # range(1, M+1)
            q.append(tmp+[i])

print(ans)

Measured memory_bytes: 16300
par , rank = [],[] #par[x] = yでxの親がyであることを表す rank[x]はxが属する木の高さ

def find(x):#xの根を求める
    if par[x] == x : return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y): #x,yが属する集合を合併
    x = find(x)
    y = find(y)
    if (x != y):
        if rank[x] < rank[y]:
            par[x] = y
        else :
            par[y] = x
            if (rank[x] == rank[y]) : rank[x] += 1

v,e = map(int, input().split())

edge = []

for i in range(e):
    s,t,w = map(int, input().split())
    edge.append((w,s,t))

edge.sort()
mincost = 0

for i in range(v): #初期化　任意の要素が根 
    par.append(i)
    rank.append(0)

for ee in edge:
    w,s,t = ee
    if (find(s) != find(t)) :
        unite(s,t)
        mincost += w

print(mincost)


Measured memory_bytes: 23176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> v = {a,b,c};
  sort(v.begin(), v.end(), ::greater<int>());
  string A = to_string(v[0]);
  string B = to_string(v[1]);
  int r = stoi(A+B);
  cout << r+v[2] << "\n";

}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int max_h = 51;

int h,w;
string s[max_h];
int g[max_h][max_h];

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

int dfs(int x, int y){
	int ans = 1;
	g[x][y] = 0;

	rep(i, 4){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(0 <= nx && nx < h && 0 <= ny && ny < w && g[nx][ny] == 1){
			ans += dfs(nx, ny);
		} 
	}

	return ans;
}

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

	cin >> h >> w;
	rep(i, h) cin >> s[i];

	rep(i, h) rep(j, w) g[i][j] = s[i][j] == '#' ? 1 : 0;

	rep(i, h){
		rep(j, w){
			if(g[i][j] == 1){
			 	int tmp = dfs(i, j);
			 	// cout << i << "," << j << "," << tmp;

			 	if(tmp == 1){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl '\n'
const double PI =3.141592653589793238463;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
	cout<<n*2*PI;
    return 0;
}

Measured memory_bytes: 3800
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int C = in.nextInt();

            int[] B = new int[M];
            for (int i = 0; i < M; i++) {
                B[i] = in.nextInt();
            }

            int count = 0;
            for (int i = 0; i < N; i++) {
                int sum = C;
                for (int j = 0; j < M; j++) {
                    sum += B[j] * in.nextInt();
                }
                if (sum > 0) {
                    count++;
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 21844
import Control.Monad
import Control.Applicative
import Data.List

-- String, Int, Char, IO, Bool, True, False
-- putStrLn
-- e.g.
-- 1
-- [a] <- map read . words <$> getLine => [1] -> a == 1
-- 1
-- a <- readLn
-- 1 2 3
-- lst <- map read . words <$> getLine => [1, 2, 3]
-- 1 2 3
-- [l, m, n] <- map read . words <$. getLine :: IO [Int] => [1, 2, 3]
-- 'a'
-- c <- getChar => c == 'a'
--
-- slst <- replicateM h getLine

getBysplit = map read . words <$> getLine

main :: IO()
main = do
  [a, b] <- getBysplit :: IO [Int]
  let ans = if b `mod` a == 0
              then a + b
              else b - a
  print ans


Measured memory_bytes: 508
/*****************************************************************************************
******************************AUTHOR:***************************************************
****************************ASHISH RANJAN***********************************************
*****************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
int main(){
  fast();
ll n,k,x,y;
  cin>>n>>k>>x>>y;
  if(n<=k){cout<<n*x;return 0;}
  else {cout<<(n-k)*y+k*x;return 0;}
 return 0;
  
}


Measured memory_bytes: 3560