akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<vector>
#include<cstring>
#include<queue>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;

map<char, int> dx, dy;
int idx[4] = {1, 0, -1, 0};
int idy[4] = {0, -1, 0, 1};

int main(int argc, char *argv[]){
  dx['U'] = 0,  dy['U'] = -1;
  dx['D'] = 0,  dy['D'] = 1;
  dx['R'] = 1,  dy['R'] = 0;
  dx['L'] = -1,  dy['L'] = 0;

  int w, h, n, csx, csy, ctx, cty;
  cin >> w >> h >> n;
  cin >> csx >> csy >> ctx >> cty;
  int grid[2*h + 5][2*w + 5];
  int dp[h + 1][w + 1];
  memset(grid, 0, sizeof(grid));

  for (int i = 0; i <= h; i++) {
    for (int j = 0; j <= w; j++) {
      dp[i][j] = 1e9;
    }
  }
  
  int nx, ny , count;
  string dist;
  for (int i = 0; i < n; i++) {
    cin >> nx >> ny >> count >> dist;
    for (int j = 0; j < dist.length()*count; j++) {
      char d = dist[j%dist.length()];
      if(0 <= ny + dy[d] && ny + dy[d] < h &&
         0 <= nx + dx[d] && nx + dx[d] < w){
        grid[2*ny + dy[d] + 1][2*nx + dx[d] + 1]++;
        ny += dy[d], nx += dx[d];
      }
    }
  }
  dp[csy][csx] = 0;
  priority_queue<piii ,vector<piii>, greater<piii> > que;
  que.push(mp(0, mp(csx, csy)));
  while(!que.empty()){
    piii v = que.top();que.pop();
    int x, y, c;
    c = v.first;
    x = v.second.first;
    y = v.second.second;
    if(x == ctx && y == cty)break;
    for (int i = 0; i < 4; i++) {
      int nx = x + idx[i], ny = y + idy[i];
      if(0 <= nx && nx <= w &&
         0 <= ny && ny <= h &&
         dp[ny][nx] > c + grid[2*y + idy[i]][2*x + idx[i]]){
        dp[ny][nx] = c + grid[2*y + idy[i]][2*x + idx[i]];
        que.push(mp(dp[ny][nx], mp(nx, ny)));
      }
    }
  }

  // std::cout << "grid:" << std::endl;
  // for (int i = 0; i <= 2*h; i++) {
  //   for (int j = 0; j <= 2*w; j++) {
  //     std::cout << grid[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  // std::cout << "dp:" << std::endl;
  // for (int i = 0; i <= h; i++) {
  //   for (int j = 0; j <= w; j++) {
  //     std::cout << dp[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  
  std::cout << dp[cty][ctx] << std::endl;
  return 0;
}

Measured memory_bytes: 9828
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){if(a<b)swap(a,b); return (b?gcd(a%b,b):a);}
#define N 1010
ll n,m;
vector<ll> g[N];
namespace bipma{
  bool vis[N];
  ll match[N];
  bool dfs(ll x){
      if(vis[x])return 0; vis[x]=1;
      for(auto y:g[x]){
	  if(!~match[y]||dfs(match[y])){
	      match[y]=x;
	      return 1;
	  }
      }
      return 0;
  }
  void main(){
      for(int i=0;i<n+m;i++)match[i]=-1;
      ll ans=0;
      for(int i=0;i<n;i++){
	  for(int j=0;j<n+m;j++)vis[j]=0;
	  ans+=dfs(i);
      }
      cout<<ans<<endl;
  }  
};
int main(){
    ll a[N],b[N];
    while(cin>>n>>m&&n+m){
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<N;i++)g[i].clear();
	for(int i=0;i<n;i++){
	    for(int j=0;j<m;j++){
		if(gcd(a[i],b[j])>1){
		    g[i].push_back(j+n);
		    g[j+n].push_back(i);
		}
	    }
	}
	bipma::main();
    }
    return 0;
}



Measured memory_bytes: 7328
#include <iostream>
using namespace std;
int max(int a,int b,int c)
{
    int m = max(a,b);
    return max(m,c);
}
int max(int a,int b)
{
    if(a>b)
        return a;
    return b;
}

int count(int a[][3],int day,int n,int prev)
{
    if(day > n || day<0)
        return 0;
    
    int res=0;
    if(prev == 0)
        res += max(count(a,day-1,n,1) + a[day][1] ,count(a,day-1,n,2) + a[day][2]);
    else if(prev == 1)
        res += max(count(a,day-1,n,0) + a[day][0] ,count(a,day-1,n,2) + a[day][2]);
    else if(prev == 2)
        res += max(count(a,day-1,n,0) + a[day][0] ,count(a,day-1,n,1) + a[day][1]);
    else
        res += max(count(a,day-1,n,0) + a[day][0] ,count(a,day-1,n,1) + a[day][1],count(a,day-1,n,2) + a[day][2]);
    return res; 
}
int main() {
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++)
	{
	    for(int j=0;j<3;j++)
	        cin>>a[i][j];
	}
	
	
	int dp[3][n];
	dp[0][0] = a[0][0];
	dp[1][0] = a[0][1];
	dp[2][0] = a[0][2];
	//dp[0][1] = max(dp[1][0]+a[1][0], dp[2][0]+a[1][0])
	for(int i=1;i<n;i++)
	{
	    
	    dp[0][i] = max( dp[1][i-1]+a[i][0] , dp[2][i-1]+a[i][0]);
	    dp[1][i] = max( dp[0][i-1]+a[i][1] , dp[2][i-1]+a[i][1]);
	    dp[2][i] = max( dp[1][i-1]+a[i][2] , dp[0][i-1]+a[i][2]);
	    
	}
	cout<<max(dp[0][n-1],dp[1][n-1],dp[2][n-1]);
	//cout<<count(a,n-1,n,-1);
	
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
using namespace std;

struct student {
    int number;
    int rank;
    
    student() {number = 1; rank = 0;}
};

int N;
vector<student> a;

bool PX (student x, student y) {
    return x.rank < y.rank;
}

int main() {
    cin>>N;
    int r;
    student t;
    for (int x = 1; x <= N; x++) {
        cin>>r;
        t.number = x; t.rank = r;
        a.push_back(t);
    }
    sort(a.begin(), a.end(), PX);
    for (int x = 0; x < N; x++) {
        cout<<a[x].number<<" ";
    }
    return 0;
}


Measured memory_bytes: 1780
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long X){
  for(ll i=-1000; i<1000; i++) {
    for(ll j=-1000; j<1000; j++) {
      if(pow(i,5)-pow(j,5)==X) {
	std::cout << i << ' ' << j << std::endl;
	return;
      }
    }
  }
}

int main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
  return 0;
}



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

//highlight color RGB = [70,70,70]
#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES "<<x<<endl;
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x<(b);x++)
#define FOR(x,n) for(int x=0;x<(n);x++)
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define m_p make_pair
asll M=1e9+7;
int n,m,tc;
int p,q,r;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	srand(time(0));
	ll a[2],b[2];
	FOR(i,2){
		cin>>a[i];
	}
	FOR(i,2){
		cin>>b[i];
	}
	ll maks=-2e9-10;
	maks=max(max(a[0]*b[0],a[1]*b[0]),max(a[0]*b[1],a[1]*b[1]));
	/*
	FOR(i,2){
		FOR(j,2){
			if(1){
				//co a[i]*b[j] ml
				if(maks<a[i]*b[j]){
					maks=a[i]*b[j];
				}
				//maks=max(maks,);
				//maks=max(maks,b[i]*a[j]);
			}
		}
	}
	*/
	co maks ml
	
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>


std::vector<int> V[100000];
int C[100000];
int color;
int maxi;

int main () {
    int n, m, q;
    std::cin >> n >> m;

    for (int i; i < m; i++) {
        int s, t;
        std::cin >> s >> t;
        V[s].push_back(t);
        V[t].push_back(s);
    }

    for (int i = 0; i < n; i++) {
        if(C[i] == 0) {
            color++;
            std::queue<int> Q;
            Q.push(i);
            while (Q.size()) {
                C[Q.front()] = color;
                for (auto t: V[Q.front()]) {
                    if (C[t] == 0) {
                        C[t] = color;
                        Q.push(t);
                    }
                }
                Q.pop();
            }
        }
    }

    std::cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        std::cin >> s >> t;
        if ((C[s] == C[t]) && (C[s] != 0)) {
            std::cout << "yes" << std::endl;
        }
        else{
            std::cout << "no" << std::endl;
        }
    }

}


Measured memory_bytes: 9020
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>

using namespace std;

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

	vector<int> all;

	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;

		all.push_back(t);
	}

	sort(all.begin(), all.end());
	long long price = 0;

	for (int i = 0; i < n - 1; i++)
	{
		price += all[i];
	}

	price += all.back() / 2;
	cout << price << "\n";
}



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

int main() {
  // 全体の範囲は0~101
  // そこから、pで選ばれた数字を取り除く
  int x,n; cin>>x>>n;
  vector<int> p(n);
  int diff=1000, ans;
  // 0=101の範囲で配列内外の判定
  vector<bool> isElem(102,false);
  for(int i=0; i<n; i++) {
    cin>>p[i];
    isElem[p[i]] = true;
  }
  // pに選ばれなかった数字の配列を求める
  vector<int> fList;
  for(int i=0; i<isElem.size(); i++) {
    if(!isElem[i]) fList.push_back(i);
  }
  for(int i=0; fList.size(); i++) {
    if(diff>abs(x-fList[i])) {
      diff = abs(x-fList[i]);
      ans = fList[i];
    }
    else break;
  }
  cout << ans << endl;
}


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

int n, m, cnt, sum, a[200];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
	if (sum % (4 * m) != 0) sum = sum / (4 * m) + 1;
		else sum = sum / (4 * m);
	for (int i = 1; i <= n; i++)
		if (a[i] >= sum) cnt++;
	if (cnt >= m) printf("Yes");
		else printf("No");
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  Cinint(s);
  Cinint(w);
  if (w >= s) {
    cout << "unsafe" << endl;
  }
  else {
    cout << "safe" << endl;
  }
}


Measured memory_bytes: 3476
s=input()

mod=2019
tc=[0]*2019

lens=len(s)

tc[0]=1
tim=0
p10=1
for i in range(len(s)-1,-1,-1):
    ti=(tim+int(s[i])*p10)%mod
    tc[ti]+=1
#    print(i,(10*tim+int(s[i]))%mod,ti,tc[ti])    
    tim=ti
    p10=p10*10%mod

#tc[0]=1
#for i in range(len(s)-1,-1,-1):
#    ti=int(s[i:lens])%mod
#    tc[ti]+=1
#    print(i,s[i:lens],ti,tc[ti])    
    
tsum=0
for i in tc:
    tsum+=(i*(i-1))//2
    
print(tsum)


Measured memory_bytes: 9376
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++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)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ins insert
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define unmap unordered_map
#define pq priority_queue
#define minEle min_element
#define maxEle max_element
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define bp __builtin_popcount
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
typedef pair <ll, ld> pld;
typedef pair <ll, pll> pllp;
typedef pair <pll, ll> ppll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <pii> vpii;
typedef map <int, int> mii;
typedef map <ll, ll> mll;
typedef string BigNum;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const ld PI = acos(-1);

//Remember limit for IT, etc..., and +1 in limit of any array
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;
//If TLE let's use int instead of ll because it's as slow as your WPM :)))

/*----IMPORTANT THINGS----*/
pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
//right down left up rightdown leftdown rightup leftup
pii NON = {-1, -1};
/*------------------------*/

ll n, m;
vll g[limit];
ll f[limit];
bool visited[limit];

void dfs(ll u) {
    visited[u] = true;

    for (auto it : g[u]) {
        if (!visited[it]) {
            dfs(it);
        }

        f[u] = max(f[u], f[it] + 1);
    }
}

void solveProblem() {
    ll ans = 0;

    REP(i, 1, n) if (!visited[i]) dfs(i);
    REP(i, 1, n) ans = max(ans, f[i]);

    cout << ans << endl;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> n >> m;
    REP(i, 1, m) {
        ll u, v;
        cin >> u >> v;
        g[u].pb(v);
    }
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



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

int main() {

    int n, k, ans = 1;
    cin >> n >> k;
    while(n--) {
        if(ans * 2 < ans + k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    cout << ans << endl;
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   vector<int> ing(n);
   for(int& x : ing){
      cin >> x;
   }
   sort(all(ing));
   double res=(double)(ing[0]+ing[1])/2;
   for(int i=2;i<n;i++){
      res=(double)(res+ing[i])/2;
   }
   cout << res;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;

int main()
{
    IOS

    string s;
    cin >> s;

    if ( s[2] == s[3] && s[4] == s[5] ) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif
 
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}
 
template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

int N, C, K;
int t[MAX];

void solve() {
	cin >> N >> C >> K;
	rep(i, N) cin >> t[i];
	sort(t, t+N);
	int yet_id = 0;
	int cnt = 0;
	int i = 0;
	while (i < N) {
		yet_id = i;
		dump(i);
		while (i < N &&
					 (i - yet_id + 1) <= C &&
					 t[i] <= t[yet_id] + K) {
			i++;
		}
		cnt++;
	}
	cout << cnt << endl;
}

signed main() {
	cout << fixed << setprecision(20);
	while(true) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}


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

typedef long long ll;

const ll mod = 10007;
const int inf = 101234567;

using Graph = vector<vector<int>>;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    map<int, int>m;

    Graph G(N+1);

    for (int i = 1; i <= N-1; i++) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X].push_back(Y);
    G[Y].push_back(X);

    for (int s = 1; s <= N; s++) {
        vector<int> dist(N+1, -1);
        queue<int> que;

        dist[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                m[dist[nv]]++;
                que.push(nv);
            }
        }
    }

    for (int k = 1; k <= N-1; k++) {
        cout << m[k]/2 << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}

void execute()
{
    int N, M;
    cin >> N >> M;

    multimap<int, int> route;
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
         route.insert(multimap<int, int>::value_type(A, B));
         route.insert(multimap<int, int>::value_type(B, A));
    }

    int frm[200001]={};
    queue<int> que;;

    int find_num = 1;
    frm[1] = 1;
    que.push(1);
    while (!que.empty()) {
        int v = que.front();
        que.pop();

        auto p = route.equal_range(v);
        for (auto it = p.first; it != p.second; ++it) 
        {
            int idx = it->second;
            if(frm[idx] == 0){
                frm[idx] = v;
                que.push(idx);
                if(++find_num == N) {
                    // 結果出力
                    cout << "Yes" << endl;
                    for(int i = 2; i <= N; i++){
                        cout << frm[i] << endl;
                    }
                    return;
                }
            }
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 23296
#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>

using std::string;

bool isAlphabet(const char c) {
    return (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'));
}
int calcIndex(const char c) {
    if ('a' <= c && c <= 'z') {
        return c - 'a';
    }
    if ('A' <= c && c <= 'Z') {
        return c - 'A';
    }
    return -1;
}

int main(){
    string buffer;
    std::array<int, 26> sums = {};

    while(getline(std::cin, buffer)) {
        if(buffer.empty()) break;
        for (auto c: buffer) {
            if (!isAlphabet(c)) {
                continue;
            }
            sums[calcIndex(c)] += 1;
        }
    }

    for(int i = 0; i < sums.size(); i++) {
        printf("%c : %d\n", 'a' + i, sums[i]);
    }

}


Measured memory_bytes: 3232
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int dis[105][105];
int a;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<=9;i++){
    	for(int j=0;j<=9;j++){
    		scanf("%d",&dis[i][j]);
		} 
	}
	for(int k=0;k<=9;k++){
		for(int i=0;i<=9;i++){
			for(int j=0;j<=9;j++){
				dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a);
			if(a!=-1)ans+=dis[a][1];
		}
	}
	printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


ll dp[51][51][2501];

int main()
{
	int n, a;	cin >> n >> a;
	vi x(n);
	REP(i, n)
		cin >> x[i];

	memset(dp, 0LL, sizeof dp);
	dp[0][0][0] = 1;

	REP1C(i, n) // lim of id, open-end
		REPC(nc, i) // no of using cards
		REPC(s, 2500) // sum
	{
		dp[i][nc][s] += dp[i - 1][nc][s];

		if (nc >= 1 && s - x[i - 1] >= 0)
			dp[i][nc][s] += dp[i - 1][nc - 1][s - x[i - 1]];
	}

	ll ans = 0;
	REP1C(nc, n)
		ans += dp[n][nc][nc * a];
	cout << ans << endl;
}


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

int main()
{
	string str;
	string str1 = " ";
	cin >> str;
	int cnt = 0;
	int i = 0;
	for(i = 0; i < str.size();){
		int t = 1;
		while(str1 == str.substr(i, t)){
			t++;

			if(i + t > str.size()){
				i = str.size();
				break;
			}
		}if(i == str.size() )break;
		str1 = str.substr(i,t);
		i += t;
		cnt++;	
	}
	cout << cnt ;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;


int main(){
    int a,b,choice;cin >> a >> b;
    if(a%2 == 0){
        choice = a/2;
    }else{
        choice = (a+1)/2;
    }
    if(choice>=b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
S=list(input())
#print(S)
A=[0 for i in range(len(S)+1)]
for i in range(len(S)):
    if S[i]=="<":
        A[i+1]=A[i]+1
for i in range(len(S)):
    if S[len(S)-1-i]==">":
        A[len(S)-i-1]=max(A[len(S)-i]+1,A[len(S)-i-1])
    
#print(A)
#print(len(A))
print(sum(A))

Measured memory_bytes: 27488
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int i, j, k;
	string S;
	int flag = 0;
	cin >> S;
	for (i = 0; i < S.size(); ++i) {
		for (j = i+1; j < S.size(); ++j) {
		//	cout << "S[i]" << S[i] << " S[j]" << S[j] << endl;
			if (S[i] == S[j]) {
				++flag;
			}
		}
	//	cout << endl;
	}

	if (flag == 0) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sqr(a) (a)*(a)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void solve(){
    int n;
    cin >> n;
    int el;
    int res = true;
    for(int i = 0; i < n; ++i){
        cin >> el;
        if(res && el % 2 == 0){
            if(!(el % 3 == 0 || el % 5 == 0)){
                res = false;
            }
        }
    }
    cout << (res ? "APPROVED" : "DENIED");
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
}

Measured memory_bytes: 384
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    string s; cin >> s;
    
    int ans = 0;
    
    for (int i = 0; i < n-1; i++) {
        if(s[i]==s[i+1]) ans++;
    }
    
    cout << n - ans << endl;
   
}



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

int main() {
    int n,m;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }
    cin >> m;
    int t[m];
    for(int i = 0 ; i < m; i++){
        cin >> t[i];
    }
    map<int,int> x,y;
    for(int i = 0; i < n; i++){
        x[d[i]]++;
    }
    for(int j = 0; j < m; j++){
        y[t[j]]++;
    }
    for(int i = 0; i < m; i++){
        int p = t[i];
        if(x[p] < y[p]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 20608
import queue
h,w = map(int,input().split())
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
s = [input() for i in range(h)]

ans = 0
que = queue.Queue()
for i in range(h * w):
    c = 0
    d = [[h*w] * w for i in range(h)]
    p = (i//w, i%w)
    if s[p[0]][p[1]] == '#':
        continue
    d[p[0]][p[1]] = 0
    que.put(p)
    while not que.empty():
        y,x = que.get()
        c = d[y][x]
        for dy, dx in v:
            yy = y + dy
            xx = x + dx
            if yy < 0 or xx < 0 or h <= yy or w <= xx:
                continue
            if s[yy][xx] == '#':
                continue
            if d[yy][xx] < h*w:
                continue
            que.put((yy, xx))
            d[yy][xx] = c + 1
    ans = max(ans, c)
print(ans)

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, x, m;
  cin >> n >> x >> m;

  vl first(m, INF);
  first[x] = 1;

  ll ans = x;
  vl sum(2);
  sum[1] = x;
  rep2(i, 2, n) {
    x *= x;
    x %= m;

    if(first[x] == INF) {
      first[x] = i;
      sum.push_back(sum.back() + x);
      ans += x;
    }else {
      ll loop_size = i-first[x];
      ll loop_sum = sum[i-1] - sum[first[x]-1];
      ans += (n-i+1)/loop_size*loop_sum;
      rep(_, (n-i+1)%loop_size) {
        ans += x;
        x *= x;
        x %= m;
      }
      break;
    }
  }

  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 4664
import math
import functools
import operator

N=int(input())
P=list(map(int, input().split()))
Q=list(map(int, input().split()))

A = list(range(1, N+1))

def permutation(n, r):
  if(n < r):
    return 0
  return int(math.factorial(n) / math.factorial(n - r))

def permutationList(data, r):
  length = len(data)
  total = permutation(length, r)
  result = []
  for i in range(total):
    element = []
    copyData = data[:]
    for digit in range(r):
      l = len(copyData)
      countUp = total / functools.reduce(operator.mul, range(l, length + 1))
      index = int(i / countUp) % l
      element.append(copyData.pop(index))
    result.append(element)
  return result

n_A = permutationList(A, N)
n_A = sorted(n_A)

index_p = n_A.index(P)
index_q = n_A.index(Q)

print(abs(index_q - index_p))

Measured memory_bytes: 9972
while(h,w=gets.split.map &:to_i)[n=0]>0
m=(1..h).map{gets+?a}<<?a*w
h.times{|i|w.times{|j|(c=m[i][j])<?a&&(n+=1)&&(s=[[i,j]]
(x,y=s.pop;m[x][y]=?a
[[x,y+1],[x,y-1],[x+1,y],[x-1,y]].map{|a,b|m[a][b]==c&&s<<[a,b]})while s[0])}}
p n
end

Measured memory_bytes: 6768
d,l = [list(map(int, s.split())) for s in open(0)]
d = d[0]

ans = 0
v_max = [1]
for i in range(d+1):
    if v_max[i] - l[i] < 0:
        ans = -1
        break
    v_max.append((v_max[i] - l[i])*2)
else:
    _max = 0
    for i in range(d, -1, -1):
        _max = min(_max + l[i], v_max[i])
        ans += _max
print(ans)

Measured memory_bytes: 674404
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=[0]*n
  for x in l:
    x-=1
    ans[x]+=1

  for i in ans:
    print(i)

main()
# print(main())


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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main() {
    int n,m;
    cin>>n>>m;
    int A[1000], B[1000];
    rep(i,n) cin>>A[i];
    int c[1000]={};
    rep(i,m) cin>>B[i];
    rep(j,m)rep(i,n){
        if(B[j]>=A[i]){
            c[i]++;
            break;
        }
    }
    int mx=0, num=0;
    rep(i,n){
        if(mx<c[i]){
            num=i; mx=c[i];
        }
    }
    cout<<num+1<<endl;
}

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

using namespace std;
#define PI              3.1415926536

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	//c_p_c();
	FIO;


	int n;
	cin >> n;

	cout << (n * (n - 1)) / 2;



}








Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


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

	map<int, int> M;
	for(int i=0; i<3; i++){
		int v;
		cin >> v;
		if(M.count(v) == 0){
			M[v] = 1;
		}
		else{
			M[v]++;
		}
	}
	if(M[5]==2 && M[7]==1){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string s;
 cin >> s;
 rep(i,3)
  if(s[i]==s[i+1]){
      cout << "Bad" << endl;
      return 0;
  }
  cout << "Good" << endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

vector<string> maze;
vector<vector<int>> vis;
int w,h;

bool out(pair<ll,ll> p){
    return p.first<0||p.first>=w||p.second<0||p.second>=h||maze[p.second][p.first]=='#'||vis[p.second][p.first]!=-1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w;
    maze = vector<string>(h);
    for(int i=0; i<h; i++){
        string s;cin>>s;
        maze[i]=s;
    }
    int ans = 0;
    //startを決め打ちしてBFS
    for(int sy=0; sy<h; sy++){
        for(int sx=0; sx<w; sx++){
            if(maze[sy][sx]=='#')continue;
            vis = vector<vector<int>>(h,vector<int>(w,-1));
            ll d = 0;
            queue<P> q;q.push({sx,sy});vis[sy][sx]=0;
            while(!q.empty()){
                P p = q.front();q.pop();
                int x = p.first;
                int y = p.second;
                ans = max(ans,vis[y][x]);
                if(!out({x+1,y})){q.push({x+1,y});vis[y][x+1]=vis[y][x]+1;}
                if(!out({x-1,y})){q.push({x-1,y});vis[y][x-1]=vis[y][x]+1;}
                if(!out({x,y+1})){q.push({x,y+1});vis[y+1][x]=vis[y][x]+1;}
                if(!out({x,y-1})){q.push({x,y-1});vis[y-1][x]=vis[y][x]+1;}

            }

        }
    }
    cout<<ans;
    return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int flag = 0;//0のときa->c, 1のときc->a
    while(min(a, c) > 0){
        if(flag == 0){
            c -= b;
            flag = 1 - flag;
        }
        else{
            a -= d;
            flag = 1 - flag;
        }
    }
    if(c <= 0){
        cout <<"Yes" <<endl;
    }
    else{
        cout <<"No" <<endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[3000010],finv[3000010];

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  else return (fac[n]*finv[r]%mod)*finv[n-r]%mod;
}

ll calcsumcomb(ll sum,ll n){
  return comb(sum+n-1,n-1);
}

ll N,M;

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

  fac[0]=1;
  rep(i,3000000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,3000001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>M;
  ll res=0;
  rep(X,M+1){
    ll rest=M-X+2*M;
    if(rest%2!=0)continue;
    rest/=2;
    ll add=0;
    rep(i,2){
      ll crtrest=rest-M*i;
      ll crtn=N-i;
      ll cnt=0;
      rep(j,2){
        ll sgn=(j%2==0?+1:mod-1);
        (cnt+=(calcsumcomb(crtrest-j*M,crtn)*comb(crtn,j)%mod)*sgn%mod)%=mod;
      }
      (cnt*=comb(N,i))%=mod;
      (add+=comb(N-i,X)*cnt%mod)%=mod;
    }
    (res+=add)%=mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vint a(n+1, true);
    rep(i, m) {
        int b;
        cin >> b;
        a[b] = false;
    }

    vector<ll> dp(n+1);
    dp[0] = 1LL;
    if (a[1]) dp[1] = 1LL;
    else dp[1] = 0LL;
    srep(i, n+1, 2) {
        if (a[i]) dp[i] = dp[i-1] + dp[i-2];
        else dp[i] = 0LL;
        dp[i] = dp[i] % MOD;
    }
    
    ll ans = dp[n];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
typedef long long ll;
using namespace std;
int a[105];
int main() {
	int n, m, i;
	double t = 0;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		t += a[i];
	}
	sort(a, a + n);
	if (a[n - m] >= t / double(4.0 * double(m))) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())

city = []

for i in range(M):
    P, Y = map(int, input().split())
    city.append([i, P, Y])
city.sort(key=lambda x: x[2])

count = defaultdict(lambda: 0)
for c in city:
    count[c[1]] += 1
    c.append(count[c[1]])
city.sort(key=lambda x: x[0])

for _, P, _, n in city:
    print(format(P, '06') + format(n, '06'))

Measured memory_bytes: 35540
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=99999999999999;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> p(n);
    vector<ll> c(n);
    for(ll i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }
    for(ll i=0;i<n;i++){
        cin>>c[i];
    }

    vector<P> memo(n);
    vector<ll> visited(n,0);

    for(ll i=0;i<n;i++){
        ll now = i;
        ll score = 0;
        ll roop = 0;
        while(true){
            now=p[now];
            if(visited[now]==2) break;
            if(visited[now]==1){
                visited[now]++;
                memo[now].first=score;
                memo[now].second=roop;
            }else{
                visited[now]++;
                score+=c[now];
                roop++;
            }
        }
    }

    ll ans=-INF;
    for(ll i=0;i<n;i++){
        //cout<<i<<":";
        ll score=memo[i].first;
        ll roop=memo[i].second;
        ll sub=0;
        if(score>=0 && k>roop){
            sub+=score*(k/roop-1);
            ll now=i;
            ll f=k%roop+roop;
            while(f){
                now=p[now];
                sub+=c[now];
                ans=max(ans,sub);
                f--;
                //cout<<sub<<" ";
            }
        }else{
            ll now=i;
            ll f=min(k,roop);
            while(f){
                now=p[now];
                sub+=c[now];
                ans=max(ans,sub);
                f--;
                //cout<<sub<<" ";
            }
        }
        //cout<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstring>
int main (){
    int n,i,k=0,ans=0;
    scanf("%d",&n);
    int a[n+1],b[n+1],c[n];
    c[0]=0;
    for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++){
    scanf("%d",&b[i]);
    }
    for(i=1;i<=n-1;i++){
    scanf("%d",&c[i]);
    }
    for(i=1;i<=n;i++){
        if(k==a[i]-1){ans=ans+c[a[i]-1];}
        ans=ans+b[i];
        k=a[i];       
    }
    printf("%d",ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
 
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
 
const int INF = 1145141919;
const long long INFL = 1LL<<60;
 
int main()
{
	int n;
	cin >> n;
	int a[110000], b[110000], c[110000];
	int dp[110000][3] = {};
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; ++i)
	{
		dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
		dp[i][1] = max(dp[i-1][2] + b[i], dp[i-1][0] + b[i]);
		dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll arr[21][21];
ll dp[(1<<21)+1];
ll m = 1000000007;
ll f(ll s,ll n){
  ll j = __builtin_popcount(s);
  if(s == (1<<n)-1){return 1;}
  if(j==n){return 0;}
  if(dp[s]!=-1){return dp[s];}
//   cout<<j<<"\n";
  ll ans = 0;
  rep(i,0,n-1){
      if( (s & 1<<i)==0 && arr[i][j]==1){
          ans = (ans%m + f((s | 1<<i),n)%m)%m;
      }
  }
  dp[s] = ans;
  return ans;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n; cin>>n;
    memset(dp,-1,sizeof(dp));
    rep(i,0,n-1){
        rep(j,0,n-1){
            cin>>arr[i][j];
        }
    }
    cout<<f(0,n);
}


Measured memory_bytes: 19996