akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
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 vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
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, k;
  cin >> n >> k;
  cout << (n+k-3)/(k-1) << newl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val p = Array<Int>(n, { cin.nextInt() })
    var count = 0
    for (i in 1..n-2) {
        if (p[i] >= p[i-1] && p[i+1] >= p[i]) {
            count += 1
        } else if (p[i-1] >= p[i] && p[i] >= p[i+1]) {
            count += 1
        }
    }
    println(count)
}

Measured memory_bytes: 31252
n,x=list(map(int ,input().split()))
sample_gram=0
l1=[]
for i in range(0,n):
    m=int(input())
    sample_gram+=m
    l1.append(m)

if(sample_gram > x):
    noofdonut=(sample_gram//x)
    print(int(noofdonut))
elif(sample_gram==x):
    print(int(sample_gram/m))
elif(sample_gram < x):
    initial_donut=n
    reamaning_gram=x-sample_gram
    l=[]
    for j in range(0,n):
        a=reamaning_gram/l1[j]
        l.append(int(a))

    print(initial_donut+int(max(l)))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)

const int inf=1001001001;
int n;
vector<int> to[1005];

vector<int> bfs(int sv){
    vector<int> dist(n, inf), pre(n, -1);
    queue<int> q;
    dist[sv]=0;
    q.push(sv);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u : to[v]){
            if(dist[u] != inf) continue;
            pre[u]=v;
            dist[u] = dist[v]+1;
            q.push(u);
        }
    }
    pair<int, int> best(inf, -1);
    rep(v,n) {
        if(v==sv) continue;
        for(int u : to[v]) {
            if(u==sv){
                best=min(best, make_pair(dist[v], v));
            }
        }
    }
    if (best.first==inf) return vector<int>(n+1, 0);
    int v = best.second;
    vector<int> res;
    while(v != -1){
        res.push_back(v);
        v=pre[v];
    }
    return res;
}

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

    int m; cin >> n >> m;
    rep(i, m){
        int a, b; cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
    }

    vector<int> ans(n+1);
    rep(s, n){
        vector<int> now=bfs(s);
        if(now.size() < ans.size()) ans=now;
    }
    if(ans.size() == n+1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for(auto v:ans){
        cout << v+1 << endl;
    }
    
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(c) (c).begin(),(c).end()
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

struct RollingHash {
  const int base = 9973;
  const vector<int> mod = {999999937LL, 1000000007LL};
  string S;
  vector<int> hash[2], power[2];

  RollingHash() {}
  RollingHash(const string &cs) { init(cs); }
  void init(const string &cs) {
    S = cs;
    int n = S.size();
    for (int iter = 0; iter < 2; iter++) {
      hash[iter].assign(n+1,0);
      power[iter].assign(n+1,1);
      for (int i = 0; i < n; i++) {
        hash[iter][i+1] = (hash[iter][i]*base + S[i]) % mod[iter];
        power[iter][i+1] = power[iter][i]*base % mod[iter];
      }
    }
  }
  // get hash of S[left:right)
  inline int get(int l, int r, int id) const {
    int res = hash[id][r] - hash[id][l] * power[id][r-l] % mod[id];
    if (res < 0) res += mod[id];
    return res;
  }
};

int n,m;
string s;

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

  cin >> n >> m >> s;
  RollingHash rh(s);
  set<pii> st;
  int l = 0, r = 1;
  REP(i,m) {
    string q;
    cin >> q;
    if (q == "R++") r++;
    else if (q == "R--") r--;
    else if (q == "L++") l++;
    else l--;
    st.insert(pii(rh.get(l,r,0),rh.get(l,r,1)));
  }
  cout << st.size() << endl;

  return 0;
}


Measured memory_bytes: 31584
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<string.h>
using namespace std;
#define maxn 100010
#define MAX 1e15
#define INF 0x3f3f3f3f
struct node
{
    int to,next;
    long long  w;
}edge[200000*2+100];
bool flag;//无负环
int k;
int head[maxn],visit[maxn];
long long  dis[maxn];

void add_edge(int from,int to,long long  weight)
{

    edge[k].to=to;
    edge[k].w=weight;
    edge[k].next=head[from];
    //printf("edge[%2d].to=%-4d edge[%2d].w=%lld edge[%2d].next=%-4d head[%2d]=%-4d\n",k,edge[k].to,k,edge[k].w,k,edge[k].next,from,k);
    head[from]=k++;
}
void init_spfa()
{
    for(int i=0;i<=100005;i++)
        dis[i]=1e15;
    memset(visit,0,sizeof(visit));
    memset(head,-1,sizeof(head));
    k=0;
    flag=true;
}
void SPFA_dfs(int u)
{
    visit[u]=1;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int to=edge[i].to;
        if(dis[u]+edge[i].w<dis[to])
        {
            //printf("i=%d  edge[%d]=%.4lf\n",i,i,edge[i].w);
            if(visit[to]||!flag)
            {
                flag=false;//有负环
                break;
            }
            dis[to]=dis[u]+edge[i].w;
            SPFA_dfs(to);
        }
    }
    visit[u]=0;
}

bool SPFA(int n)
{
    for(int i=1;i<=n;i++)
    {
        //printf("i=%d\n",i);
        SPFA_dfs(i);
        if(!flag)
            return flag;
    }
    return true;
}
int main()
{
    int N,M;
    int l,r;
    long long d;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        init_spfa();
        while(M--)
        {
            scanf("%d%d%lld",&l,&r,&d);
            add_edge(l,r,d);
            add_edge(r,l,-d);
        }
        if(SPFA(N))
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 9856
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

struct Edge{
	int to, cost, time;
};

typedef pair<int, int> P;

const int MAX_V = 3010;
const int INF = 1 << 30;

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

	int n, m;
	while(cin >> n >> m && n != 0 && m != 0){

		vector<Edge> vec[MAX_V];
		int d[MAX_V];

		for(int i = 0; i < n; ++i){
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			--a, --b;
			vec[a].push_back(Edge{b, c, t});
			vec[b].push_back(Edge{a, c, t});
		}

		int k;
		cin >> k;

		while(k > 0){
			--k;
			priority_queue<P, vector<P>, greater<P> > que;
			fill(d, d + n, INF);

			int p, q, r;
			cin >> p >> q >> r;
			--p, --q;

			d[p] = 0;
			que.push(P(0, p));

			while(!que.empty()){
				P p0 = que.top();
				que.pop();
				int v = p0.second;
				if(d[v] < p0.first) continue;
				for(int i = 0; i < vec[v].size(); ++i){
					Edge e = vec[v][i];
					if(r == 0 && d[e.to] > d[v] + e.cost){
						d[e.to] = d[v] + e.cost;
						que.push(P(d[e.to], e.to));
					}
					if(r == 1 && d[e.to] > d[v] + e.time){
						d[e.to] = d[v] + e.time;
						que.push(P(d[e.to], e.to));
					}
				}
			}

			cout << d[q] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <string>

using namespace std;

unsigned char dict[30517579];

unsigned int mhash(string str) {
	unsigned int res = 0;
	for(char e:str) {
		res = res * 5;
		switch(e) {
			case 'A':
				res += 1;
				break;
			case 'C':
				res += 2;
				break;
			case 'G':
				res += 3;
				break;
			case 'T':
				res += 4;
				break;
		}
	}
	return res;
}

int main(void) {
	int n;
	string cmd,prm;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> cmd >> prm;
		unsigned int hs = mhash(prm);
		if(cmd == "insert") {
			dict[hs/8] = dict[hs/8] | (1<<(hs%8));
		} else {
			if(dict[hs/8] & (1 << (hs%8))) cout << "yes";
			else cout << "no";
			cout << endl;
		}
	}
}



Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> iv;

const int INF = 1e8;
const int N = 5010;

int a,b;

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

    if(a <= 8 && b<=8)
        cout<<"Yay!\n";
    else
        cout<<":(\n";
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

typedef pair<int, int> P;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<tuple<int, int, int>> a(N);
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        a[i] = make_tuple(x, s - x, t - x);
    }
    sort(a.begin(), a.end());

    set<P> s;
    rep(i, Q) {
        int q;
        cin >> q;
        s.insert({q, i});
    }

    vector<int> ans(Q, -1);
    rep(i, N) {
        int x, l, r;
        tie(x, l, r) = a[i];

        auto it = s.lower_bound(P(l, -1));
        while (it != s.end()) {
            if (it->first >= r) break;
            ans[it->second] = x;
            s.erase(it++);
        }
    }

    rep(i, Q) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 14336
#include <iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>

using namespace std;

int calc(int x){
    if(x%2==0){
        return x/2;
    }
    else{
        return 3*x+1;
    }
}

int main(){
    int s;
    int count=1;
    cin >> s;
    while(s!=4&&s!=2&&s!=1){
        s=calc(s);
        count++;
    }
    cout << count + 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,a[100005],b,g;
    cin >> n >> k;
    rep(i,n){
        cin >> b;
        if (i == 0) g = b;
        a[i] = b;
        g = gcd(g,b);
    }
    bool ans = 0;
    rep(i,n){
        if (a[i] >= k && (a[i]-k)%g == 0) ans = 1;
    }
    if (ans) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll a0_plus_sum = 0;
    ll a0_plus_count = 0;
    ll a0_minus_sum = 0;
    ll a0_minus_count = 0;

    //a0 = plus
    for(int i = 0; i < n; i++){
        if(i % 2 == 1){
            if(a0_plus_sum + a[i] < 0){
                a0_plus_sum += a[i];
            }else{
                a0_plus_count += 1 + (a0_plus_sum + a[i]);
                a0_plus_sum = -1;
                }
        }else if(i % 2 == 0){
            if(a0_plus_sum + a[i] > 0){
                a0_plus_sum += a[i];
            }else{
                a0_plus_count += 1 - (a0_plus_sum + a[i]);
                a0_plus_sum = 1;
                }
        }
    }

    //a0 = minus
    for(int i = 0; i < n; i++){
        if(i % 2 == 1){
            if(a0_minus_sum + a[i] > 0){
                a0_minus_sum += a[i];
            }else{
                a0_minus_count += -(a0_minus_sum + a[i]) + 1;
                a0_minus_sum = 1;
                }
        }else if(i % 2 == 0){
            if(a0_minus_sum + a[i] < 0){
                a0_minus_sum += a[i];
            }else{
                a0_minus_count += (a0_minus_sum + a[i]) + 1;
                a0_minus_sum = -1;
                }
        }
    }
    print(min(a0_minus_count,a0_plus_count));
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    int ret = 0;
    for (int i = 0; i < n/2; i++)
    {
        if (s[i] != s[n-1-i])
            ret++;
    }
    cout << ret << endl;
}

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

int main() 
{ 
 ll n;
 cin>>n;
 vector<pair<ll,ll>>v;
for(int i=1;i<=n;i++){ll a; cin>>a;v.push_back(make_pair(a,i));}
sort(v.begin(),v.end());
for(int i=0;i<n;i++) cout<<v[i].second<<" ";
cout<<"\n";
} 

Measured memory_bytes: 2544
s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = [0] * (total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    for j in range(total_X - i, -1, -1):
        if lst_X[j] == 1:
            lst_X[j + i] = 1

# print (lst_X)

lst_Y = [0] * (total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    for j in range(total_Y - i, -1, -1):
        if lst_Y[j] == 1:
            lst_Y[j + i] = 1

# print (lst_Y)
if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and lst_X[(total_X - x) // 2] == 1 and lst_Y[(total_Y - y) // 2]:
    print ('Yes')
else:
    print ('No')

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<int> > A(n,vector<int>(m,0));
  vector<vector<int> > B(m,vector<int>(l,0));
  for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> A[i][j];
  for(int j=0; j<m; j++) for(int k=0; k<l; k++) cin >> B[j][k];
  for(int i=0; i<n; i++){
    for(int k=0; k<l; k++){
      long long sum = 0;
      for(int j=0; j<m; j++) sum += A[i][j] * B[j][k];
      if(k != 0) cout << " ";
      cout << sum;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>  
#define endl "\n"
using namespace std;
	typedef long long ll;
	const int maxn=100050;
	const int inf=0x3f3f3f3f;
	ll w[105];
	ll v[105];
	ll dp[maxn];
	ll n,m;
	int main(){
		IOS
		cin>>n>>m;
		ll sum=0;
		for(int i=1;i<=n;i++){
			cin>>w[i]>>v[i];
			sum+=v[i];
		}
		memset(dp,0x3f,sizeof(dp));
		dp[0]=0;	
		for(int i=2;i<=n+1;i++)
			for(ll j=sum;j>=0;j--)
				if(j-v[i-1]>=0)
					dp[j]=min(dp[j],dp[j-v[i-1]]+w[i-1]);
			
		ll ans=-1;
		for(ll j=sum;j>=0;j--){
			if(dp[j]<=m){
				ans=j;
				break;
			}
		}
		cout<<ans<<endl;
	}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 p[n];
    REP(i,n)cin >> p[i];
    int32 cnt = 0;
    FOR(i,1,n-1){
        if((p[i+1] - p[i]) * (p[i] - p[i-1]) > 0)cnt++;
    }
    ANS(cnt);
    return 0;
}

Measured memory_bytes: 256
using namespace std;
class UnionFind {
    private:
        unsigned n_;
        unsigned *parents_;
    public:
        UnionFind(unsigned n = 0): n_(n), parents_(new unsigned[n_]) {
            for (unsigned i = 0; i < n_; ++i) {
                parents_[i] = i;
            }
        }
        virtual ~UnionFind() {
            delete[] parents_;
        }
        UnionFind &operator=(const UnionFind &uf) {
            delete[] parents_;
            n_ = uf.n_;
            parents_ = new unsigned[n_];
            for (unsigned i = 0; i < n_; ++i) {
                parents_[i] = uf.parents_[i];
            }
            return *this;
        }
        unsigned find(unsigned i) {
            if (parents_[i] == i) {
                return i;
            }
            return parents_[i] = find(parents_[i]);
        }
        void unite(unsigned i, unsigned j) {
            unsigned pi = find(i);
            parents_[pi] = find(j);
        }
};

#include <iostream>
int main() {
    unsigned n, q, com, x, y;
    UnionFind uf;
    cin >> n >> q;
    uf = UnionFind(n);
    for (unsigned i = 0; i < q; ++i) {
        cin >> com >> x >> y;
        if (com == 0) {
            uf.unite(x, y);
        } else {
            cout << (uf.find(x) == uf.find(y)? 1: 0) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1340
#include <stdio.h>

int main(void) {
	int x[10000];
	int i;
	for(i=0; i<10000; i++) {
	scanf("%d",&x[i]); 
		if(x[i]==0) {
		break;
		}
	}
	for(i=0; i<10000; i++) {
	printf("Case %d: %d\n",i+1,x[i]);
	}
	return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;

struct inf{
	int x,l;
}a[N];

bool cmp(inf a,inf b){
	return a.x+a.l<b.x+b.l||a.x+a.l==b.x+b.l&&a.x<b.x;
}

int main()
{
	int n,i,j,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].l);
	sort(a+1,a+n+1,cmp);
	a[0].x=-1e9;
	for(i=1,j=0;i<=n;i++)
		if(a[i].x-a[i].l>=a[j].x+a[j].l)
			++ans,j=i;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
function main(arg) {
	arg = arg.trim().split(' ').map(str => parseInt(str, 10));
  	var a = arg[0], b = arg[1], k = arg[2],
		num = Math.min(a, k);
  	a -= num;
  	k -= num;
  	num = Math.min(b, k);
  	b -= num;
	console.log(a, b)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

// input
int N;
vector<int> A;


void input() {
    cin >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}


int main() {
    input();
    sort(A.rbegin(), A.rend());
    int s = 0;
    rep(i, N) s += A[i];
    int a = 0;
    for (int i = 0; i < N; i += 2) a += A[i];
    int ans = a - (s - a);
    cout << ans << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  string ans = (n == 0 ? "0" : "");
  while(n != 0)
  {
    ans += (n % 2 == 0 ? '0' : '1');
    n -= (n % 2 == 0 ? 0 : 1);
    n /= -2;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3604
#n=int(input())
n,m,q=map(int,input().split())
al=[0]*q
bl=[0]*q
cl=[0]*q
dl=[0]*q
for i in range(q):
    al[i],bl[i],cl[i],dl[i]=map(int,input().split())

def score(A):
    res=0
    for ai,bi,ci,di in zip(al,bl,cl,dl):
        if A[bi-1]-A[ai-1]==ci:
            res+=di
    return res
scorelist=[]
def dfs(A):
    global scorelist
    lastone=A[-1] if len(A)>0 else 1
    if len(A)==n:
        scorelist.append(score(A))
        return 
    for v in range(lastone,m+1):
        A.append(v)
        dfs(A)
        A.pop()

dfs([])
print(max(scorelist))


Measured memory_bytes: 12608
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(void){
    // Your code here!
string A;
char B;
cin >> A;
long long C;
C=0;
int D;
for(long long i=0;i<A.length();i++)
{
    B=A.at(i);
    D=B-48;
    C+=D;
}
if(C%9==0){cout << "Yes" << endl;}else{cout << "No" << endl;}
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }

    ll psum = max(1LL, a.at(0));
    ll pcost = abs(psum - a.at(0));
    ll nsum = min(-1LL, a.at(0));
    ll ncost = abs(nsum - a.at(0));
    for(int i = 1; i < n; ++i){
        // p
        if(i % 2 == 1){
            if(psum + a.at(i) < 0){
                psum += a.at(i);
            }else{
                pcost += abs(-1 - psum - a.at(i));
                psum = -1;
            }
        }else{
            if(psum + a.at(i) > 0){
                psum += a.at(i);
            }else{
                pcost += abs(1 - psum - a.at(i));
                psum = 1;
            }
        }

        // n
        if(i % 2 == 1){
            if(nsum + a.at(i) > 0){
                nsum += a.at(i);
            }else{
                ncost += abs(1 - nsum - a.at(i));
                nsum = 1;
            }
        }else{
            if(nsum + a.at(i) < 0){
                nsum += a.at(i);
            }else{
                ncost += abs(-1 - nsum - a.at(i));
                nsum = -1;
            }
        }
    }
    cout << min(pcost, ncost) << endl;
    return 0;
}


Measured memory_bytes: 1024
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    cs = sRaw()
    ac_sums =[0]
    for c in cs:
        if c=="W":
            ac_sums.append(ac_sums[-1]+1)
        else:
            ac_sums.append(ac_sums[-1])
    ans = 0
    nW = ac_sums[-1]
    nR = N-nW
    ans = INF
    for n_idx,ac_sum in enumerate(ac_sums):
        ans = min(ans,max(ac_sum,nR-(n_idx-ac_sum)))
    print(ans)
    
main()


Measured memory_bytes: 85580
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int a, b; cin >> a >> b;
    int h; cin >> h;
    out((a + b) * h / 2);
}



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

int main( ) {
	string s ; 
	cin >> s ; 
	for( int i = 0 ; i < s.length() ; ++ i ) {
		if( s[i] == '1' ) cout << 9 ; 
		else if( s[i] == '9' ) cout << 1 ; 
		else cout << s[i] ; 
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    if (A>B){

        if(B==1)
            cout<<"Bob"<<endl;
        else
        cout<<"Alice"<<endl;
    }
    else if (B>A){
        if(A==1)
            cout<<"Alice"<<endl;
       else
        cout<<"Bob"<<endl;

    }
    else
        cout<<"Draw"<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
def dfs(s,c):
    if len(s)==n:
        print(s)
        return
    for i in range(ord("a"),ord(c)+2):
        if i>ord(c):
            dfs(s+chr(i),chr(i))
        else:
            dfs(s+chr(i),c)

dfs("a","a")

Measured memory_bytes: 4404
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct node{
  int p, l, r;
} Node;

Node T[MAX];
int n, D[MAX];

void print(int u);
int rec(int u, int p);

int main(){
  int i, j, d, v, c, l, r;
  scanf("%d",&n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d%d",&v ,&d);
    for(j=0; j<d; j++){
      scanf("%d",&c);
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0; i<n; i++){
    if(T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for(i=0; i<n; i++) print(i);

  return 0;
}

void print(int u){
  int i, c;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if (T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c!=NIL; i++, c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p+1);
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vll a(n + 1);
  REP(i, n + 1) {
    cin >> a[i];
  }

  vll ans(n + 1);
  for (int i = n; i >= 1; i--) {
    ll sum = 0;
    for (int j = i * 2; j <= n; j += i) {
      sum += ans[j];
    }
    sum %= 2;
    ans[i] = sum ^ a[i];
  }

  cout << accumulate(all(ans), 0ll) << endl;
  REP(i, n + 1) {
    if (ans[i]) {
      cout << i << " ";
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3968
#include <iostream>

using namespace std;
int main(){
  string s;
  int n;
  cin >> n;
  int i,cntf=0,cnts=0;
  cin >> s;
  for(i=0;i<n;i++){
    if(s[i]=='(')cntf++;
    if(s[i]==')'){
      if(cntf>0)cntf--;
      else cnts++;
    }
  }
  for(i=0;i<cnts;i++)cout << '(';
  cout << s;
  for(i=0;i<cntf;i++)cout << ')';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
s=input()
if len(s)&1:
    print("No")
else:
    d={}
    c=0
    for i in s:
        d[i]=d.get(i,0)+1
    for i in d:
        if d[i]&1:
            c=1
            break
    if c:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

using namespace std;
string repeat(string s, ll n) {
    string s1 = "";
    for (ll i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  // ll n,l=0;
  // cin>>n;
  //
  // ll a[n],b[n];
  // vector<ll> c(n,-1);
  //
  // map<ll,ll> m1,m2,llersection;
  // rep(i,0,n){ cin>>a[i]; m1[a[i]]++;}
  // rep(i,0,n) {cin>>b[i]; m2[b[i]]++;}
  // for(auto i:m2) if(m1.find(i.f)!=m1.end()) llersection[i.f]=min(m2[i.f],m1[i.f]);
  //
  // ll pass=0;
  // for(auto i:llersection){
  //   ll fir=i.f,sec=i.s;
  //
  //   while(sec!=0){
  //     if(l==0) pass++;
  //     if(pass==20) break;
  //     if(a[l]==fir) l=(l+1)%n;
  //     else{
  //       c[l]=fir;
  //       l=(l+1)%n;
  //       sec--;
  //     }
  //   }
  //   if(pass==20) break;
  // }
  //
  // rep(i,0,n) if(c[i]!=-1) { m2[c[i]]--; if(m2[c[i]]==0) m2.erase(c[i]);}
  //
  // ll flag1=0;
  // rep(i,0,n){
  //   if(c[i]==-1){
  //     auto itr=m2.begin();
  //     c[i]=itr->first;
  //     m2[c[i]]--;
  //     if(m2[c[i]]==0) m2.erase(c[i]);
  //   }
  //   if(a[i]==c[i]) flag1=1;
  // }
  //
  // if(flag1==0){
  //   cout<<"Yes"<<endl;
  //   rep(i,0,n) cout<<c[i]<<" ";
  //   cout<<endl;
  // }
  // else cout<<"No"<<endl;

  int n;
  cin>>n;
  int a[n],b[n];
  vector<int> c(n,-1);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n) cin>>b[i];
  sort(b,b+n,greater<int>());

  int l=-1,r=-1;
  rep(i,0,n){
    if(a[i]==b[i]){
      if(l==-1) l=i,r=i;
      else r=i;
    }
  }
  if(l!=-1 && r!=-1){
    int l1=0;
    int i=l;
    for(;i<=r && l1<n;){
      if(a[l1]!=b[i] && b[l1]!=b[i]){
        swap(b[l1],b[i]);
        i++;
      }
      l1++;
    }
    if(i<=r){
      cout<<"No\n";
      return;
    }
  }
  cout<<"Yes\n";
  rep(i,0,n) cout<<b[i]<<" ";
  cout<<endl;
}
int main(){
    optimizeIO();
    solve();
}


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) (a.begin(), a.end())
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {
	ll a,b;
	cin >> a >> b;
	ll k = b-a;
	ll s = k*(k-1)/2-a;
	cout << s << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

long long a[100005];
int main()
{
	int n,num;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
		scanf("%lld",&a[i]);
	if(n == 1) {
		if(a[0] == 1) printf("0\n");
		else printf("1\n");
	}
	else {
	sort(a,a+n);
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		num = 1;
		while(a[i] == a[0]) { i = i + 1; num++;}
		if(a[i-1] == num) sum = sum + 0;
		if(a[i-1] > num) sum = sum + num;
		if(a[i-1] < num) sum = sum + num - a[i-1] ;
		a[0] = a[i];
	}
	printf("%d\n",sum);
}
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<ll> tab(n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            tab[j]++;
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += i * tab[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81348
x=int(input())

if 400<=x<=599:
    print(8)
elif x<=799:
    print(7)
elif x<=999:
    print(6)
elif x<=1199:
    print(5)
elif x<=1399:
    print(4)
elif x<=1599:
    print(3)
elif x<=1799:
    print(2)
elif x<=1999:
    print(1)

Measured memory_bytes: 61620
#include <bits/stdc++.h>
typedef long long ll;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define All(x) (x).begin(),(x).end()
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> l(N);
  rep(i,N){
    cin >> l[i];
  }
  sort(All(l));
  int sum=accumulate(All(l),0);
  int max=l[N-1];
  sum -= max;
  if(max<sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main() {
  int n, Y;
  cin >> n >> Y;
  int rx, ry, rz;
  rx = -1;
  ry = -1;
  rz = -1;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      if (n - x - y >= 0 && 10000 * x + 5000 * y + 1000 * (n - x - y) == Y) {
        rx = x;
        ry = y;
        rz = n - x - y;
      }
    }
  }
  cout << rx << ' ' << ry << ' ' << rz << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  long a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;

  long t=0,u=0;

  rep(i,31)rep(j,31){
    long w = a*i+b*j;
    if(100*w > f) continue;
    long cap = min(e*w, f-100L*w);
    if(cap<=0) continue;
    for(int k=0; k<=cap; k+=c){
      long dd = (cap-k)/d;
      dd *= d;
      long tot = 100*w + k + dd;
      if(tot*u <= (k+dd)*t){
        t = tot;
        u = k+dd;
      }
    }
  }

  cout << t << " " << u << endl;

  return 0;
}


Measured memory_bytes: 256
n = input()
k = int(input())

dp = [[[0] * (k+1) for _ in range(2)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(1, len(n) + 1):
    t = int(n[i-1])
    for j in range(k+1):
        if t != 0:
            if j != 0:
                dp[i][0][j] += dp[i-1][0][j-1]
                dp[i][1][j] += dp[i-1][1][j-1] * 9 + dp[i-1][0][j-1] * (t-1)
            dp[i][1][j] += (dp[i-1][1][j] + dp[i-1][0][j])
        else:
            dp[i][0][j] += dp[i-1][0][j]
            if j != 0:
                dp[i][1][j] += dp[i-1][1][j-1] * 9
            dp[i][1][j] += dp[i-1][1][j]

print(dp[len(n)][0][k] + dp[len(n)][1][k])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define r(n) for(int i=0;i<(n);i++)
#define p(a) cout<<a
main(){int a,b,c,d;cin>>a>>b>>c>>d;c-=a;d-=b;r(d)p("U");r(c)p("R");r(d)p("D");c++;d++;r(c)p("L");r(d)p("U");r(c)p("R");p("DR");r(d)p("D");r(c)p("L");p("U");}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

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

int main() {

    
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll c = 0;
    ll ret = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] < 0)
        {
            c++;
            ret -= a[i];
            a[i] = -a[i];
        }
        else
        {
            ret += a[i];
        }
    }
    if (c % 2)
    {
        sort(a.begin(), a.end());
        ret -= (2ll * a[0]);
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std; 
int main(void){
	int a,b,c;
	int sum=0;
	int sum1=0;
	int i=1;
	cin>>a>>b>>c;
	while(1){
		sum+=a;
		sum1+=a;
		if(i%7==0){
			sum1+=b;
		}
		if(sum>=c||sum1>=c)	break;
		i++;
	}
	cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 3096
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

count = 0

(0..A).each do |a|
    (0..B).each do |b|
        (0..C).each do |c|
            count += 1 if X == (500 * a + 100 * b + 50 *c )
        end
    end
end
puts count


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    double m,n;
    cin >> n;
    m=(int)(n/2.00);
    if(m*2.00  <  n)m++;
    cout << m/n;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<s.size();i++)
		if(s[i]!=t[i])
			ans++;
	cout<<ans;
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll n,a;
    cin>>n>>a;
    ll x[n+1];
    rep(i,n){
        cin>>x[i+1];
    }
    //dp
    vvvll dp(n+1,vvll(n+1,vll(a*n+1,0)));
    for (int i=0;i<n+1;i++){
        dp[i][0][0]=1;
    }
    //dp[i][j][k]は1~iの中からjまい選んで合計をkになる組みの数になる組みの個数
    for (int i=1;i<n+1;i++){
        for (int j=1;j<i+1;j++){
            for (int k=1;k<a*n+1;k++){
                if (k-x[i]<0){
                    dp[i][j][k]=dp[i-1][j][k];
                }
                else{
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                }
            }
        }

    }
    ll ans=0;
    for (int i=1;i<n+1;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 52224
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n ;
	cin >> n ;
	int a,b,c=0;
	while(n--){
		cin >> a >> b ;
		c=(a==b)?c+1:0;
		if(c==3){
				cout << "Yes" << endl;
				return 0;
		}
	}
	cout << "No" << endl ;
}


Measured memory_bytes: 3672
#include<cstdio>
int a[2005];
int b[2005];
int c[2005];

int min(int a,int b){ return a>b?b:a; }

int getCnt(int n,int k){
    if(n<k) return 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++) cnt += (c[i]==1);
    return min(cnt,n-(k-1));
}

int isGood(int n,int k,int q,int l,int r){
    for(int i = 1; i <= n; i++){
        if(a[i]<l) b[i] = 0;
        else if(a[i]<=r) b[i] = 1;
        else b[i] = 2;
    }
    int p = 1, cnt = 0;
    while(p<=n){
        if(b[p]==0) p++;
        else{
            int np = p;
            while(np+1<=n && b[np+1]!=0) np++;
            int size = 0;
            for(int i = p; i <= np; i++) c[++size] = b[i];
            cnt += getCnt(size,k);
            p = np+1;
        }
    }
    if(cnt>=q) return 1;
    else return 0;
}

int main(){
    int n,k,q;
    scanf("%d%d%d",&n,&k,&q);
    int minn = 2e9;
    for(int i = 1; i <= n; i++){ 
        scanf("%d",&a[i]);
        minn = min(a[i],minn);
    }
    int ans = 2e9;
    for(int i = 1; i <= n; i++){
        int upper = a[i];
        int L = minn, R = a[i];
        int res = -1;
        while(L<=R){
            int M = (L+R)/2;
            if(isGood(n,k,q,M,upper)){
                res = M;
                L = M+1;
            }
            else R = M-1;
        }
        if(res!=-1) ans = min(ans,upper-res);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

int main(){
  int H, W; cin >> H >> W;
  vector<vector<char>> fld(H,vector<char>(W));
  int counts = 0;
  rep(i,H){rep(j,W){ 
    cin >> fld[i][j];
    if(fld[i][j] == '#') counts++;
  }}
  
  vvi dist(H,vi(W,-1));
  queue<pii> que;
  que.push(pii(0,0));
  dist[0][0]= 0;
  while(que.size()){
    int x = que.front().first;
    int y = que.front().second;
    rep(i,4){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx < 0 || nx >=H || ny<0 || ny>=W) continue;
      if(fld[nx][ny]=='#') continue;
      if(dist[nx][ny]== -1){
        dist[nx][ny]=dist[x][y]+1;
        que.push(pii(nx,ny));
      }
    }
    que.pop();
  }
  if(dist[H-1][W-1]== -1) cout << -1 << endl;
  else cout << H*W-counts-dist[H-1][W-1]-1 << endl;
  return 0;
}

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

int main(){
  ll n, m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) cin >> a[i];
  vector<ll> mx(m+2,0);
  vector<ll> s(m+2,0);
  rep(i,n-1) {
    s[1] += a[i+1]; 
    if(a[i] > a[i+1]) {
      s[a[i+1]] += m - a[i];
      s[a[i]] -= m - a[i];
      mx[1] += 1;
      mx[a[i+1]] -= 1;
      s[a[i]] += m;
      mx[a[i]] += 1; 
    } else {
      mx[a[i]] += 1;
      mx[a[i+1]] -= 1;
      s[a[i+1]] -= a[i];
      s[1] -= a[i];
      s[a[i]] += a[i];
    }
  }
  ll ans = INF;
  for(int i = 1; i <= m; i++) {
    s[i] += s[i-1];
    mx[i] += mx[i-1];
    ans = min(ans,s[i]-mx[i]*i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
N, A, B = map(int, input().split())

sum  = 0

for i in range (1, N+1):
	nyoki = 0
	stri = str(i)
	for j in range (1, len(stri)+1):
		nyoki = nyoki+int(stri[j-1])
	if nyoki >= A and nyoki <= B:
		sum = sum+i

print(sum)


Measured memory_bytes: 2940