akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <list>
#define fst first
#define snd second
#define mp make_pair
#define fore(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;

#define MAXN 100005

set<int> g[MAXN];
int n,m;int xx,yy;
bool r=false;

void go(int z, int p){
    if(z==xx){r=true;return;}
    if(z==yy)return;
    for(int t:g[z]){
        if(t==p)continue;
        go(t,z);
    }
}

int main(){
    scanf("%d%d",&n,&m);
    fore(i,0,m){
        int x,y;
        scanf("%d%d",&x,&y);x--;y--;
        g[x].insert(y);
        g[y].insert(x);
    }
    fore(i,0,n)if(SZ(g[i])%2){puts("No");return 0;}
    fore(i,0,n)if(SZ(g[i])>=6){puts("Yes");return 0;}
    int q=0;
    vector<int> z;
    fore(i,0,n)if(SZ(g[i])==4)q++,z.pb(i);
    if(q>2){puts("Yes");return 0;}
    if(q<2){puts("No");return 0;}
    int x=z[0],y=z[1];
    xx=x;yy=y;
    for(int t:g[x])go(t,x);
    puts(r?"Yes":"No");
    return 0;
}


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

int gcd(int x, int y){
    if(y>x){
        int t = x;
        x = y;
        y = t;
    }
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",gcd(a,b));
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
long long ans,N,A,B,s,x;
int main(){
    cin>>N>>A>>B>>s;
    while(N-->1){
        cin>>x;
        ans+=min(A*(x-s),B);
        s=x;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> trees(n);
    for(int i = 0; i < n; i++){
        cin >> trees[i];
    }
    ll ans = 1145141919810364;
    sort(trees.begin(),trees.end());
    for(int i = 0; i <= n - k; i++){
        ans = min(trees[i + k - 1] - trees[i],ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	ll n,a[100];
	cin >> n;
	ll amax=0, amin=(int)1e9;
	REP(i, n)cin >> a[i];
	REP(i, n) {
		amin = min(amin, a[i]);
		amax = max(amax, a[i]);
	}
	cout << amax - amin << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

bool cmp(pair<int,ll> lhs, pair<int,ll> rhs){
    if(lhs.second == rhs.second){
    return  lhs.first < rhs.first;
}    
    return lhs.second < rhs.second;
}
int N;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    vector<pair<int,ll> > a_i_num;
    int tempNum;
    pair<int,ll> tempPair;
    int sum_a = 0;
    REP(i,N){
        cin >> tempNum;
        sum_a += tempNum;
        tempPair.first = i;
        tempPair.second = tempNum*N;
        a_i_num.push_back(tempPair);
    }
    REP(i,N){
        a_i_num[i].second = abs(a_i_num[i].second - sum_a);
    }
    sort(ALL(a_i_num),cmp);

    cout << a_i_num[0].first << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=10005;
int n,k;
char mi,mx,s[N],t[N],ans[N];
void ckmin(){
	bool flag=false;
	for(int i=1;i<=n;i++){
		if(t[i]>ans[i]){
			break;
		}else if(t[i]<ans[i]){
			flag=true;
			break;
		}
	}
	if(flag){
		for(int i=1;i<=n;i++){
			ans[i]=t[i];
		}
	}
}
void gao(char s[],int k){
	int len=1;
	while(len<n&&s[n-len]==mi){
		len++;
	}
	int now=n-len+1;
	while(k&&len<n){
		len*=2;
		k--;
	}
	if(len>=n){
		for(int i=1;i<=n;i++){
			t[i]=mi;
		}
		ckmin();
	}else{
		for(int i=1;i<=len;i++){
			t[i]=mi;
		}
		for(int i=len+1;i<=n;i++){
			t[i]=s[--now];
		}
		ckmin();
	}
}
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	mi='z',mx='a';
	for(int i=1;i<=n;i++){
		s[2*n-i+1]=s[i];
		mi=min(mi,s[i]);
		mx=max(mx,s[i]);
		ans[i]='z';
	}
	if(mx==mi){
		puts(s+1);
		return 0;
	}
	if(s[n]==mi){
		gao(s,k);
	}
	for(int i=n;i<=2*n;i++){
		if(s[i]==mi){
			gao(s+i-n,k-1);
		}
	}
	puts(ans+1);
	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int a, b, c; cin >> a >> b >> c;
    if (a == b) cout << c << endl;
    else if (b == c) cout << a << endl;
    else cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    cout << (s < t ? "Yes" : "No") << endl;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    if(n<1000) print("ABC");
    else print("ABD");
    return 0;
}

Measured memory_bytes: 256
import sys

S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
alpnum = {}

for i in range(26):
    alpnum[alp[i]] = i

dic = {}

for i in S:

    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

if len(dic) < 26:

    for i in range(26):

        if alp[i] not in dic:
            print (S+alp[i])
            break

else:

    now = alpnum[S[-1]]
    lis = []
    for i in range(26):

        if now > alpnum[S[-1]]:

            lis.sort()
            ans = ""
            for j in lis:

                if alpnum[j] > alpnum[S[-1]]:
                    ans = j
                    break
                    
            print ( S[:-1] + ans )
            sys.exit()
        else:
            lis.append(S[-1])
            now = alpnum[S[-1]]
            S = S[:-1]

    
    print (-1)
    


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

const long long MOD = 1000000000 + 7;
const int MAX = 100010;

long long fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod_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;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> index(100001, -1);
    int l = 0, r = 0;
    for (int i = 0; i < n + 1; i++) {
        cin >> a.at(i);
        
        if (index.at(a.at(i)) == -1) index.at(a.at(i)) = i;
        else {
            l = index.at(a.at(i));
            r = i;
        }
    }
    
    comb_init();
    
    long long ans;
    for (int k = 1; k <= n + 1; k++) {
        ans = mod_comb(n + 1, k) - mod_comb(l + (n + 1) - (r + 1), k - 1);
        if (ans < 0) ans += MOD;
        
        cout << ans << endl;
    }
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    ll ans = 0;
    ll max_h = 0;

    rep(i, n){
        if(i==0){
            max_h = a.at(i);
            continue;
        }
        if(max_h > a.at(i)) ans += (max_h - a.at(i));
        if(max_h < a.at(i)) max_h = a.at(i);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;
typedef long long int ll;

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

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

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> p(N+10);
    for (int i = 1; i <= N; ++i) {
        cin >> p[i];
    }

    int cnt = 0;
    for (int i = 1; i <= N; ++i) {
        if (p[i] != i) cnt++;
    }
    if (cnt == 0 || cnt == 2) printf("%s\n", "YES");
    else printf("%s\n", "NO");
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin >> n;
    //cout<<n<<endl;
    int dp[100010];
    for(int i=0;i<100010;i++) dp[i]=inf;
    dp[0]=0;
    for(int i=1;i<=n;i++){
        //cout<<"Yes"<<n<<endl;
        dp[i]=dp[i-1]+1;
        for(int j=6;j<=i;j*=6){
            if(i-j>=0){
                dp[i]=min(dp[i-j]+1,dp[i]);
            }
        }
        for(int j=9;j<=i;j*=9){
            if(i-j>=0){
                dp[i]=min(dp[i-j]+1,dp[i]);
            }
        }
    }
    //cout<<endl;
    //cout<<"dp end"<<n<<endl;
    //ep(i,n+1) cout<<dp[i]<<" ";
    //cout<<endl<<n<<endl;
    //cout<<endl;
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3644
// Problem : A - Circle
// Contest : AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#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 RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0);
	int r;
	cin >> r;
	cout << r * r << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<vector<int>> matrix(n, vector<int>(m));
  vector<int> vector(m);
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      cin >> matrix[i][j];
    }
  }
  for (int i = 0; i < m; i++){
    cin >> vector[i];
  }
  for (int i = 0; i < n; i++){
    int x = 0;
    for (int j = 0; j < m; j++){
      x += matrix[i][j] * vector[j];
    }
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 3176
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

n,k = na()
a = na()

def is_ok(arg):
    if arg == 0: return False
    j = 0
    for i in a:
        j += math.ceil(i/arg)-1
        if j > k:
            return False
    return True

ok = max(a)
ng = 0
while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print(ok)

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

int main()
{
  string w; cin >> w;
  int cnt[26] = {};
  
  for (int i = 0; i < w.size(); i++) {
    cnt[w[i] - 'a']++;
  }
  
  for (int i = 0; i < 26; i++) {
    if (cnt[i] % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }



vector<ll> A(2 * 100005);

ll N;
ll sumR[2 * 100005], sumL[2 * 100005];
map<ll, ll> m;
int main() {

	cin >> N;

	rep(i, N) {
		cin >> A[i + 1];
	}
	A[0] = 0;
	A[N+1] = 0;

	m[0] += 1;
	rep(i, N) {
		sumL[i + 1] = sumL[i] + A[i + 1];
		sumR[N - i] = sumR[N - i + 1] + A[N - i];
		m[sumR[N - i]] += 1;
	}

	ll ans = 0;

	for (int i = 1; i <= N; i++) {

		m[sumR[i + 1]]--;

		if (m[sumL[N] - sumL[i]] > 0) {
			ans += m[sumL[N] - sumL[i]];
		}

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

Measured memory_bytes: 17408
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(),(a).end()
#define X first
#define Y second
#define inf 2e9+5
using namespace std;
const int N=1e5+5;
int wt[100],val[100];
int dp[N];
void solve()
{
  int n,w,ans; cin>>n>>w;
  for(int i=0;i<n;i++)cin>>wt[i]>>val[i];
  for(int i=0;i<=N;i++)dp[i]=-1; dp[0]=0;
  for(int i=0;i<n;i++)
  {
      for(int j=N-val[i];j>=0;j--)
      {
          if(dp[j]==-1)continue;
          if(dp[j+val[i]]==-1)dp[j+val[i]]=dp[j]+wt[i];
          else dp[j+val[i]]=min(dp[j+val[i]],dp[j]+wt[i]);
      }
  }
  for(int i=1;i<=N;i++)if(dp[i]!=-1&&dp[i]<=w)ans=i;
  cout<<ans;
  return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    while(t--)solve();
    return 0;
}


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

struct Strongly_Connected_Component {
  int n, k;
  vector<vector<int>> G, reverseG;
  vector<int> vs, cmp;
  vector<bool> used;
  Strongly_Connected_Component(int newv = 1) {
    n = newv;
    G.resize(n);
    reverseG.resize(n);
    used.resize(n, 0);
    cmp.resize(n);
  }

  bool add(int from, int to) {
    G[from].push_back(to);
    reverseG[to].push_back(from);
    return 1;
  }
  void dfs(int v) {
    used[v] = true;
    for (auto to : G[v])
      if (!used[to]) dfs(to);
    vs.push_back(v);
  }
  void rdfs(int v) {
    used[v] = true;
    cmp[v] = k;
    for (auto to : reverseG[v])
      if (!used[to]) rdfs(to);
  }
  int solve() {
    used.assign(n, 0);
    vs.clear();
    for (int v = 0; v < n; ++v)
      if (!used[v]) dfs(v);
    used.assign(n, 0);
    k = 0;
    for (int i = (int)vs.size() - 1; i >= 0; --i)
      if (!used[vs[i]]) {
        rdfs(vs[i]);
        ++k;
      }
    return k;
  }
  vector<vector<int>> make_graph(bool dosolve = 1) {
    if (dosolve) solve();
    vector<vector<int>> res(k);
    for (int i = 0; i < n; ++i)
      for (int to : G[i])
        if (!issame(i, to)) res[cmp[i]].push_back(cmp[to]);
    for (auto& v : res) {
      sort(v.begin(), v.end());
      v.erase(unique(v.begin(), v.end()), v.end());
    }
    return res;
  }
  vector<vector<int>> make_list(bool dosolve = 1) {
    if (dosolve) solve();
    vector<vector<int>> res(k);
    for (int i = 0; i < n; ++i) res[cmp[i]].push_back(i);
    return res;
  }
  bool issame(int l, int r) { return cmp[l] == cmp[r]; }
};

struct Two_SAT {
  int n;
  Strongly_Connected_Component scc;
  Two_SAT(int _n = 1) : n(_n), scc(2 * _n) {}
  // a v c : !a -> c && !c -> a
  void add(int a, bool b, int c, bool d) {
    scc.add(a + b * n, c + (!d) * n);
    scc.add(c + d * n, a + (!b) * n);
  }
  bool solve() {
    scc.solve();
    for (int i = 0; i < n; ++i)
      if (scc.cmp[i] == scc.cmp[i + n]) return 0;
    return 1;
  }
  vector<bool> make_vec() {
    vector<bool> res;
    if (!solve()) return res;
    res.assign(n, 0);
    for (int i = 0; i < n; ++i) res[i] = scc.cmp[i] > scc.cmp[i + n];
    return res;
  }
};

int main() {
  int n, d;
  cin >> n >> d;
  Two_SAT ts(2 * n);
  using P = pair<int, int>;
  vector<P> v(n);
  for (int i = 0; i < n; ++i) ts.add(i, 1, i + n, 1);
  for (auto& p : v) cin >> p.first >> p.second;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      if (abs(v[i].first - v[j].first) < d) ts.add(i, 0, j, 0);
      if (abs(v[i].first - v[j].second) < d) ts.add(i, 0, j + n, 0);
      if (abs(v[i].second - v[j].first) < d) ts.add(i + n, 0, j, 0);
      if (abs(v[i].second - v[j].second) < d) ts.add(i + n, 0, j + n, 0);
    }
  auto res = ts.make_vec();
  if (res.size()) {
    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i)
      cout << (res[i] ? v[i].first : v[i].second) << endl;
  } else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 4072
def main():
    n, m = [int(e) for e in input().split()]
    X = [int(e) for e in input().split()]

    if n >= m:
        print(0)
        exit()

    X.sort()
    Xd = []
    prev = X[0]
    for i in range(1, m):
        Xd.append(X[i] - prev)
        prev = X[i]

    d = 0
    Xd.sort()
    for i in range(n - 1):
        Xd.pop()

    print(sum(Xd))

if __name__ == "__main__":
    main()


Measured memory_bytes: 56744
import sys
N,M,Q=map(int,input().split())
nums=[]
for i in range(Q):
  nums.append(list(map(int,input().split())))
ans=0
bit=[1]*N


while True:
  tmp=0
  for num in nums:
    if bit[num[1]-1]-bit[num[0]-1]==num[2]:
      tmp+=num[3]
  if tmp>ans:
    ans=tmp
  n=-1
  while True:
    if (-1)*n>N:
      print(ans)
      sys.exit()
    if bit[n]<M:
      bit[n]+=1
      for j in range(n*(-1)):
        j=(-1)*(j+1)
        bit[j]=bit[n]
      break
    n-=1
print(ans)

Measured memory_bytes: 9240
program ABC074B
    implicit none
    integer(8)::N,K,ans,i
    integer(8),allocatable,dimension(:)::X
    read*,N,K
    allocate(X(N))
    read*,X
    ans=0

    do i=1,N
        ans=ans+2*min(X(i),K-X(i))
    end do

    print'(i0)',ans
end program ABC074B

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int N;
  scanf("%d",&N);

  int NumberOfDigits = 1;
  while(1){
    if(N/(int)pow(10,NumberOfDigits) == 0) break;
    NumberOfDigits++;
  }
  
  int digit[NumberOfDigits];
  int i;
  int temp = 0;
  for(i = 0; i < NumberOfDigits; i++){
    digit[i] = (int)((N%(int)pow(10,i+1) - temp)/pow(10,i));
    temp = (int)(digit[i] * pow(10,i)) + temp;
  }
  
//  for(i = 0; i < NumberOfDigits; i++){
//    printf("digit[%d] : %d\n",NumberOfDigits - i,digit[NumberOfDigits - i - 1]);
//  }

  int flag = 1;
  for(i = 0; i < NumberOfDigits; i++){
    if(digit[i] == 9){
      printf("Yes\n");
      flag--;
      break;
    }
  }
  if(flag){
    printf("No\n");
  }
  return 0;
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)a[i]--;
  vector<ll>b(n+1);
  rep(i,0,n)b[i+1]=a[i]+b[i];
  //debug(b,n+1);
  map<ll,map<ll,ll>>mp;
  rep(i,0,n+1){
    mp[b[i]%k].emplace(i,mp[b[i]%k].size());
  }
  for(auto &z:mp){
    z.se.emplace(INF,z.se.size());
    for(auto idx:z.se){
      if(idx.fi==INF)break;
      res+=(z.se).lower_bound(idx.fi+k)->se - idx.se - 1;
      //cout<<idx.fi spa idx.se spa res<<endl;
    }
  }
  cout<<res<<endl;
  return 0;
}

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

int main() {
  int a, b, ans=0;
  string s;
  cin >> a >> b;

  rep2(i, a, b+1)
  {
    if(i%10 == i/10000%10 &&
       i/10%10 == i/1000%10
      )
    {
      ans++;
    }
  }

  cout << ans << endl;

}


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

using namespace std;
typedef long long ll;
typedef double d;

int main()
{
	ll n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0)
            sum+=i;
	}
	cout<<sum;
	return 0;
}



Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 2000001
#define vmax 10000
constexpr long long int inf = 1000000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

struct edge{
   long long int from,to,cost;
};

vector<edge> es;
vector<long long int> d;
int n;

bool be(int s){
    d.resize(n);
   fill(d.begin(),d.end(),rinf);
   d[s]=0;
   for(int j = 0 ; j < 2*n; ++j){
       for(int i=0;i<es.size();i++){
           edge e=es[i];
           if(d[e.from]!=rinf&&d[e.from]+e.cost>d[e.to]){
            if(j==2*n-1&&d[n-1]==inf){
                return false;
            }
               if(j >= n- 1){
                   d[e.to]=inf;continue;
               }
               d[e.to]=d[e.from]+e.cost;
           }
       }
   }
   return true;
}

int main() {
  long long int  m,a,b,c;
  cin>>n>>m;
  for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      a--;
      b--;
      es.push_back({a,b,c});
   }
   if(be(0)){
       cout<<d[n-1]<<endl;
   }else{
       cout<<"inf"<<endl;
   }
  return 0;
}


Measured memory_bytes: 384
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
string s;
int n;
int y;
bool ans=true;
int err(){
	ans=false;
	return -1;
}
int S(int x){
	// cout<<x<<endl;
	if(s[x]!='m'){
		return err();
	}
	if(x+1>=n){
		return err();
	}
	if(s[x+1]=='m'){
		x=S(x+1);
		if(x==-1){
			return err();
		}
	}
	if(s[x+1]=='e'){
		x++;
		if(x+1>=n) return err();
		if(s[x+1]=='m') x=S(x+1);
	}
	else return err();
	if(x==-1||x+1>=n) return err();
	if(s[x+1]=='w'){
		return y=x+1;
	}
	return -1;
}
void mainmain(){
	cin>>s;
	n=s.size();
	// cout<<s<<endl;
	S(0);
	if(ans&&y==n-1) cout<<"Cat\n";
	else cout<<"Rabbit\n";
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1164
S = list(input())
if len(S) == 1:
  print("No")
  exit()
flg = True
for i, s in enumerate(S):
  if i%2 == 0:
    if s != "h":
      flg = False
  else:
    if s != "i":
      flg = False
if flg and len(S)%2 == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}

//ifstream f(".in");
//ofstream g(".out");

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif

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

  vector<int> a(n + 2);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }

  vector<bool> win_state(k + 2);
  for (int i = 1; i <= n; ++i) {
    win_state[a[i]] = true;
  }

  for (int i = 1; i <= k; ++i) {
    if (!win_state[i]) {
      for (int j = 1; j <= n; ++j) {
        if (i + a[j] <= k) {
          win_state[i + a[j]] = true;
        } else {
          break;
        }
      }
    }
  }

  cout << (win_state[k] ? "First\n" : "Second\n");

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 256
//
// Created by Kiran Chavhan on 26/09/2020.
//

#include<bits/stdc++.h>

#define int long long
#define MOD 1000000007
#define sort(a) sort(a.begin(),a.end())
#define endl '\n'

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>k;
    for(int i=0;i<k;i++){
        cout<<"ACL";
    }
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

ll n, a[100010], sum, su, b[100010];

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	if(sum%((n+1)*n/2)!=0){
		cout << "NO" << endl;
		return 0;
	}
	b[0] = a[n-1] - a[0]; 
	for(int i=1;i<n;i++){
		b[i] = a[i-1] - a[i];
	}
	bool f = true;
	for(int i=0;i<n;i++){
		if((b[i]+sum/((n+1)*n/2))%n!=0 || (b[i]+sum/((n+1)*n/2))/n<0) f = false;
	}
	if(su==0 && f){
		cout << "YES" << endl;
	}else{
		cout << "NO" <<endl;
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

  int C0 = 0, C1 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0')
      C0 += 1;
    else if (S[i] == '1')
      C1 += 1;
  }

  cout << 2 * min(C0, C1) << endl;

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stack>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, l, c, t;
  stack<ll> s;
  scanf("%lld", &l);
  bool b[200];
  for(i = 0; i < 200; ++i) b[i] = false;
  for(i = 0; i < l; i++) {
    scanf("%lld", &c);
    if(c > 0) {
      if(b[c]) {
        printf("%lld\n", i + 1);
        return 0;
      }
      s.push(c);
      b[c] = true;
    } else {
      if(s.empty()) {
        printf("%lld\n", i + 1);
        return 0;
      }
      t = s.top(), s.pop();
      if(t != -c) {
        printf("%lld\n", i + 1);
        return 0;
      }
      b[-c] = false;
    }
  }
  printf("OK\n");
  return 0;
}


Measured memory_bytes: 2768
def binarySearch(A,key):
    left=0
    right=len(A)
    while left<right:
        mid=int((left+right)/2)
        if A[mid]==key:
            return mid
        else:
            if key<A[mid]:
                right=mid
            else:
                left=mid+1
    return -1

n=int(input())
s=list(input().split())
q=int(input())
t=list(input().split())


s.sort()

cnt=0
for i in range(q):
    x=binarySearch(s,t[i])
    if x!=(-1):
        cnt+=1

print(cnt)


Measured memory_bytes: 15920
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void print (i32 a, i32 b) {
  printf ("%" PRIi32 " %" PRIi32 "\n", a, b);
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  if (n == (n & -n)) {
    puts ("No");
    return;
  }
  puts ("Yes");
  print (1, 2);
  print (2, 3);
  print (3, n + 1);
  print (n + 1, n + 2);
  print (n + 2, n + 3);
  if (n % 2 != 0) {
    for (i32 i = 4; i < n; i += 2) {
      print (i, i + 1);
      print (i + 1, 1);
      print (1, n + i);
      print (n + i, n + i + 1);
    }
  } else {
    for (i32 i = 4; i < n - 1; i += 2) {
      print (i + 1, i);
      print (i, 1);
      print (1, n + i + 1);
      print (n + i + 1, n + i);
    }
    i32 b = n & -n;
    print (n, b);
    print (2 * n, n + (n ^ 1 ^ b));
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h> //ABC 154_d
using namespace std;
double ans;
int a[200005],sum[200005];
int n,k,x,ans1,tmp;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=1;i<=n-k+1;i++){
		if(sum[i+k-1]-sum[i-1]>=ans1)
			ans1=sum[i+k-1]-sum[i-1],tmp=i;
	}
	for(int i=tmp;i<=tmp+k-1;i++) 
		ans+=(1+a[i])/2.0;
	printf("%.12lf",ans);
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ret = A+B;
    if (A > B) {
      ret = 2*A-1;
    } else if (A < B) {
      ret = 2*B-1; 
    }
    System.out.println(ret);
  }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, cnt=0;
    cin >> n;
    vector<int> a;
    rep(i, n){
        int x;
        cin >> x;
        a.push_back(x);
    }
    rep3(i, 0, n, 2){
        if(a[i]%2){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
string s;
cin>>s;
for(int i=0;i<s.size();){
string ss;
    if(s[i]=='e'){
        ss=s.substr(i,5);
        if(ss=="erase"){
            ss=s.substr(i,6);
                if(ss=="eraser"){
                    i+=6;
                }else{
                    i+=5;
                }

        }else{
            cout<<"NO"<<endl;return 0;
        }

    }else if(s[i]=='d'){
        ss=s.substr(i,5);
        if(ss=="dream"){
            ss=s.substr(i,7);
                if(ss=="dreamer"){
                    if(s.substr(i,11)=="dreameraser"){
                        i+=11;
                    }else if(s.substr(i,10)=="dreamerase"){
                        i+=10;
                    }else {
                        i += 7;
                    }
                }else{
                    i+=5;
                }

        }else{
            cout<<"NO"<<endl;return 0;
        }


    }else{
        cout<<"NO"<<endl;
        return 0;
    }
}
cout<<"YES"<<endl;


    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>

using namespace std;

int main(){
    while (1){
        int n, p;
        cin >> n >> p;
        if (n == 0){
            break;
        }

        vector<int> player(n);

        int stone = p;
        bool flag = false;
        int ans = 0;
        while (1){
            for (int i = 0; i < n; i++){
                if (stone > 0){
                    --stone;
                    ++player[i];
                }
                else{
                    stone = player[i];
                    player[i] = 0;
                }

                if (player[i] == p){
                    flag = true;
                    ans = i;
                    break;
                }
            }
            if (flag) break;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
s = input()
n = len(s)
acgt = 0
ans = 0
for i in range(n):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        acgt += 1
        if acgt > ans:
            ans = acgt
    else:
        acgt = 0
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

const int MAX = 2000005;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
ll COM(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;
}

// youtube editorial
void solve() {
  ll n, m, k;
  cin >> n >> m >> k;

  ll ans = 0;
  COMinit();
  rep(x, k + 1) {
    add(ans, m * modpow(m - 1, n - x - 1, mod) % mod * COM(n - 1, x) % mod);
  }
  cout << ans << endl;
}


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

int main()
{
  int l, r, d;
  cin >> l >> r >> d;
  cout << r / d - (l - 1) / d << endl;
  return 0;
}

Measured memory_bytes: 3560
import java.util.Scanner;
class Main{
	
	
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			//Input
			boolean A=sc.next().equals("H");
			boolean B=sc.next().equals("H");
			//calculate
			
			
			System.out.println((!(A^B))?"H":"D");
		
			
			
		}
	}
}


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

int solve(vector<int> v) {
    int n = v.size();
    vector<int> st(n, -1), dr(n, n); 
    vector<int> s;

    for(int i = 0; i < n; ++i) {
        while(not s.empty() and v[i] < v[s.back()]) {
            dr[s.back()] = i;
            s.pop_back();
        }
        s.push_back(i);
    }

    s.clear();

    for(int i = n - 1; i >= 0; --i) {
        while(not s.empty() and v[i] < v[s.back()]) {
            st[s.back()] = i;
            s.pop_back();
        }
        s.push_back(i);
    }

    int ans = 0;

    for(int i = 0; i < n; ++i) {
        ans = max(ans, v[i] * (dr[i] - (st[i] + 1) + 1));
    }    

    return ans;
}

int main() {
    //ifstream cin("d.in");

    int n, m; cin >> n >> m;
    vector<string> a(n);

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

    vector<vector<int>> dp(n, vector<int> (m, 0)), dp_flip(n, vector<int> (m, 0));

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m - 1; ++j) {
            if(a[i][j] == a[i][j + 1]) {
                dp[i][j] = 1;
                dp_flip[i][j] = 0;
                if(i - 1 >= 0) {
                    dp[i][j] += dp[i - 1][j];
                }
            } else {
                dp[i][j] = 0;
                dp_flip[i][j] = 1;
                if(i - 1 >= 0) {
                    dp_flip[i][j] += dp_flip[i - 1][j];
                }
            }
        }
    }

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            dp[i][j] = max(dp[i][j], dp_flip[i][j]);
    
    int ans = max(n, m);
    
    for(int i = 0; i < n; ++i) {
        ans = max(ans, solve(dp[i]));
    }

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

Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// 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; }
 
using namespace std;
 
int main()
{
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
  
  long long sum=0;
  
  if(A<K){
    sum+=A;
    if(B<K-A){
      if(C<K-A-B){
        sum-=C;
      }
      else{
        sum-=(K-A-B);
      }
    }
    else{
      ;
    }
  }
  else{
    sum+=K;
  }
  
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int d;
        cin >> d;
        mp[d]++;
    }
    int m;
    cin >> m;;
    rep(i, m) {
        int t;
        cin >> t;
        if(mp[t] > 0) mp[t]--;
        else {
            puts("NO");
            return 0;
        }
    }
    puts("YES");

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#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 sz(a) int((a).size())
#define pconent(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef long double ld;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ost;
const ll MOD =  1e13;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(v) (cout<<#v<<" = "<<v<<endl)
#define endln (cout<<endl)
template <class T> inline void dbv(T a) {  for(auto x : a){ cout<<x<<", " ;} cout<<endl;}
using namespace std;
void output(ll tx)
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	FOR(i,0,n)
	{
		cin>>a[i];
	}
	ll win = 1;
	FOR(i,0,n)
	{
		if(a[i]%2==1)
		{
			win = 0;
		}
	}
	if(win==0)
	{
		cout<<"first"<<endl;
	}
	else
	{
		cout<<"second"<<endl;
	}
}
int main()
{
    ll t = 1;
    // cin>>t;
    FOR(i,0,t)
    {
    	// cout<<"Case #"<<(i+1)<<": ";
        output(i+1);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
//#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int maxv = 10005;
const int inf = 1e9 + 7;
int main(){
	int n;
	scanf("%d",&n);
	int a,b;
	ll ans=0;
	for(int i=1;i<=n-1;i++){
		b=(n-1)/i;
		ans+=b;
	} 
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1688
//%std
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define lovelive long long
#define lc son[x][0]
#define rc son[x][1]
#define lowbit(x) (x&(-x))
#define pt vc
const int N=1e5+100; 
void read(int &x)
{
  int p=1;
  x=0;
  char c=getchar();
  while(c<'0'||c>'9')
  {
    if(c=='-')
      p=-1;
    c=getchar();
  }
  while(c>='0'&&c<='9')
  {
  	x=x*10+c-48;
  	c=getchar();
  }
  x*=p;
}
int fir[N],nxt[N<<1],to[N<<1],tot;
void add_edge(int x,int y)
{
  nxt[++tot]=fir[x];
  fir[x]=tot;
  to[tot]=y;
} 
int sg[N];
void dfs(int i,int f)
{
  for(int j=fir[i];j;j=nxt[j])
    if(to[j]!=f)
      dfs(to[j],i),sg[i]^=(sg[to[j]]+1);  
} 
int main()
{
  int n,x,y;
  read(n);
  for(int i=1;i<n;i++)
  {
    read(x);read(y);
    add_edge(x,y);
    add_edge(y,x);
  }
  dfs(1,0);
  if(sg[1])
    puts("Alice");
  else
    puts("Bob");
  return 0;
}


Measured memory_bytes: 7296