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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

#ifdef OJ
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#else
#define debug(x)
#define debugv(x)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return ;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e6+3;
const int INF = 1e9;

int solve() {
    int n; cin >> n;
    string s; cin >> s;

    int ones = 0;
    for(char c: s) ones += c == '1';
    if(ones == 0) {
        fori(i,n) cout << 1 << '\n';
        return 0;
    }

    auto nbits = [](int x) {
        int c = 0;
        while(x) {
            c += x%2;
            x /= 2;
        }
        return c;
    };

    auto f = [&](int x) {
        int c = 0;
        while(x) {
            int b = nbits(x);
            x = x%b;
            c++;
        }
        return c;
    };

    vector<int> dp(2e5+10);
    fore(i,1,2e5+9) dp[i] = f(i);

    vector<vector<int>> rem(2, vector<int>(n));
    auto run = [&](int k, int v) {
        int r = 1;
        int t = 0;
        ford(i,n-1,0) {
            if(s[i] == '1') {
                t += r;
                if(t >= v) t -= v;
            }
            rem[k][i] = r;
            r *= 2;
            if(r >= v) r -= v;
        }
        return t;
    };

    int t0 = 0;
    if(ones > 1) t0 = run(0,ones-1);
    int t1 = run(1,ones+1);

    fori(i,n) {
        if(s[i] == '0') {
            int t = t1 + rem[1][i];
            if(t >= ones+1) t -= ones+1;
            cout << 1+dp[t] << '\n';
        } else {
            if(ones == 1) {
                cout << 0 << '\n';
            } else {
                int t = t0 - rem[0][i];
                if(t < 0) t += ones-1;
                cout << 1+dp[t] << '\n';
            }
        }
    }
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        solve();
    }

    return 0;
}



Measured memory_bytes: 6728
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return

# D
# 解説AC
# 後方から見ていくのはわかったけど。。。
# i日前に選べるバイトの中から一番報酬が大きいを選んでいく
def D():
    n, m = LI()
    q = []
    d = defaultdict(list)
    ans = 0
    for _ in range(n):
        a, b = LI()
        d[a].append(b)
    for i in range(m):
        for di in d[i+1]:
            heappush(q, -di)
        if q:
            ans -= heappop(q)
    print(ans)
    return

#E
def E():
    n,m,p = LI()
    dag = [-inf] * n
    edg = LIR_(m)
    dag[0] = 0
    for i in range(n):
        for a, b, c in edg:
            c += 1
            c -= p
            if dag[a] + c > dag[b]:
                dag[b] = dag[a] + c
    ans = dag[n - 1]
    for i in range(n):
        for a, b, c in edg:
            c += 1
            c -= p
            if dag[a] + c > dag[b]:
                dag[b] = inf
    if ans != dag[n - 1]:
        print(-1)
    else:
        print(max(ans, 0))

    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()


Measured memory_bytes: 48604
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

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

//std::ios::sync_with_stdio(false);
vii v;
main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n,t=0,a,b;
	cin>>n;
	int i;
	rep(i,n){
		cin>>a>>b;
		v.pb(mp(b,a));
	}
	sort(all(v));
	t=0;
	rep(i,n){
		if(t+v[i].ss>v[i].ff){
			cout<<"No"<<endl;
			return 0;
		}
		t+=v[i].ss;
	}
	cout<<"Yes"<<endl;
	return 0;
} 
	

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

int main(){
  ll n,k; cin>>n>>k;
  ll ans=0;
  for(ll i=1;i<=n;i++){
    if(0<(i-k)*(n/i)) ans+=(i-k)*(n/i);
    if(0<n%i-k+1) ans+=n%i-k+1;
  }
  if(k==0) ans-=n;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import bisect
N=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    # ans+=bisect.bisect_left(L,L[i]+L[j])-j-1
    ans+=bisect.bisect_left(L,L[i]+L[j],j)-j-1
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
bool isPal(string s){
    string p = s;
    reverse(s.begin(), s.end());
    if(s==p) {
        return 1;
    } return 0;
}
int main(){
  string s;
  cin>>s;
//   cout<<s<<' '<<s.substr(0,s.length()/2)<<' '<<s.substr(s.length()/2 + 1, s.length()/2)<<'\n';
  if(isPal(s) && isPal(s.substr(0,s.length()/2)) && isPal(s.substr(s.length()/2 + 1, s.length()/2))){
      cout<<"Yes"<<'\n';
      return 0;
  }
  cout<<"No"<<'\n';
  return 0;
}


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

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

  int a, b;
  cin >> a >> b;
  cout << ((b - 1)+ (a - 1) - 1) / (a - 1) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int a[100001];

int main() {

	string s;
	int size=0;
	int o=0;

	cin>>s;
	size=s.size();
	o=size-1;

	rep(i,size){
		if(o%2==0){
			string s2,s3;
			rep(j,o/2){
				s2+=s[j];
			}
			for(int k=o/2; k<o; k++){
				i=0;
				s3+=s[k];
			}
			if(s2==s3){
				cout<<s2.size()*2<<endl;
				return 0;
			}
		}
		o--;
	}

	return 0;
}


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

void EucledeanAlgorithm(long int a, long int b) {
	int step = 0;
	while (b != 0) {
		if (a < b) swap(a, b);
		a = a % b; swap(a, b); step++;
	}
	cout << a << " " << step << endl; return;
}

int main() {
	long int a, b;
	while (1) {
		cin >> a >> b; if (a == 0 && b == 0) break;
		EucledeanAlgorithm(a, b);
	}
	return 0;
}


Measured memory_bytes: 2984
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<pair<int,int>> pq;
    rep(i, n){
        int a; cin >> a;
        pq.push(make_pair(a,1));
    }
    rep(i, m){
        int a,b; cin >> b >> a;
        pq.push(make_pair(a,b));
    }
    ll sum = 0; int cnt = 0;
    while(cnt != n){
        int a,b;
        a = pq.top().first; b = pq.top().second;
        pq.pop();
        ll able = min(b, n - cnt);
        cnt += able;
        sum += able * a;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2420
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int_fast64_t ll;

ll M;
ll d, c;
ll sd = 0, sc = 0;

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char readchar() {
    if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
    return *ci++;
}
 
inline ll readint() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = readchar()) >= '0') A = A * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
    return A;
}

int main() {
    M = readint();
    REP(i, M) {
        d = readint();
        c = readint();
        sd += d * c; sc += c;
    }
    cout << sc - 1 + (sd-1) / 9 << "\n";
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;

#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][110005];

void Main() {
    int N, W;
    cin >> N >> W;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    fill(dp[0], dp[105], INF);

    rep(i, N) {
        dp[i][0] = 0;
    }
    rep(i, N) {
        rep(j, N * 1100) {
            if (j - items[i].second >= 0) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - items[i].second] + items[i].first);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = INF;
    rrep(i, 110005, 0) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 90496
#include <bits/stdc++.h>
using namespace std;
typedef pair<double,string> P;

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> v(n);
    for(int i=0; i<n; i++) {
      string s;
      double a[9];
      cin >> s;
      for(int j=0; j<9; j++) cin >> a[j];
      double t=a[1]+a[2]+a[3]+(a[4]+a[5])*a[8];
      double r=a[6]*a[7]*a[8]-a[0];
      v[i]=P(-r/t,s);
    }
    sort(v.begin(),v.end());
    for(int i=0; i<n; i++) cout << v[i].second << endl;
    cout << "#" << endl;
  }
  return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;


typedef string::const_iterator State;
int number(State&);

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    //debug(ret)
    return ret / 2 + ret % 2;
}

int solve(State &begin, State end){
    vector<int> v;
    int ret = 0;
    while(begin != end){
        if(*begin == '['){
            //cout << "[ " << endl;
            begin++;
            v.emplace_back(solve(begin, end));
        }else if(*begin == ']'){
            begin++;
            sort(all(v));
            rep(i,INF){
                if(2 * i > v.size()) break;
                ret += v[i];
            }
            //cout << "] " << ret << endl;
            return ret;
        }else{
            v.emplace_back(number(begin));
        }
    }
    //cout << "return size() " << v.size()<< endl;
    return v[0];
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;

        State begin = s.begin();
        State end = s.end();

        cout << solve(begin, end) << endl;
    }
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 5003
#define MAXM 200
#define MAXV 1000000009

string s;
int K;
vector<string> t;

int main()
{
    cin >> s >> K;
    REP(i, 0, s.size()){
        REP(j, 1, K + 1){
            t.push_back(s.substr(i, j));
        }
    }
    sort(t.begin(), t.end());
    unique(t.begin(), t.end());
    cout << t[K - 1] << endl;

    return 0;
}
/*

bcdea
4

*/















Measured memory_bytes: 1660
#include<iostream>
using namespace std;
struct cus {
	int l;
	int r;
};
int main() {
	int n, t;
	cin >> n >> t;
	int* arr = new int[t+1];
	for (int i = 0; i < t + 1; i++)
		arr[i] = 0;
	for (int i = 0; i < n; i++) {
		int templ, tempr;
		cin >> templ>> tempr;
		arr[templ]++;
		arr[tempr]--;
	}
	int sum = 0;
	int max = 0;
	for (int i = 0; i <= t; i++) {
		sum += arr[i];
		max = (max > sum) ? max : sum;
	}
	cout << max<<endl;
	return 0;
}


Measured memory_bytes: 3492
#include<stdio.h>

int main(void)
{
  int X, A, B;
  int coin;
  int dnum;
  
  scanf("%d", &X);
  scanf("%d", &A);
  scanf("%d", &B);
  
  coin = X - A;
  
  dnum = coin / B;
  
  coin = coin - B * dnum;
  
  printf("%d", coin);
  
  return 0;
}
  
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

struct UnionFind{
	int n;
	vi p;
	UnionFind(int N){
		n=N;
		p.resize(n);
		iota(all(p),0);
	}
	void unite(int a, int b) {p[root(a)]=root(b);}
	int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
};


int main(){
	int n,K,L; cin>>n>>K>>L;
	UnionFind k(n),l(n);
	rep(i,K){
		int p,q; cin>>p>>q;
		k.unite(p-1,q-1);
	}
	rep(i,L){
		int p,q; cin>>p>>q;
		l.unite(p-1,q-1);
	}
	vector<pii> node;
	map<pii,int> nodemap;
	rep(i,n) {
		node.emplace_back(k.root(i),l.root(i));
		if(nodemap.find(node[i])==nodemap.end()) nodemap[node[i]]=0;
		nodemap[node[i]]++;
	}
	rep(i,n){
		cout<<nodemap[node[i]]<<(i+1==n?"\n":" ");
	}	
	return 0;
}


Measured memory_bytes: 15088
W = input()
count_same = 0

while True:
    T = [x for x in input().split(' ')]
    
    if ''.join(T) == 'END_OF_TEXT':
        break
    
    text_lower = []
    for i in range(len(T)):
        one_T = T[i]
        one_T_list = []
        for k in range(len(one_T)):
            if one_T[k].isupper():
                one_T_lower = one_T[k].lower()
            else:
                one_T_lower = one_T[k]
            one_T_list.append(one_T_lower)
        text_lower.append(''.join(one_T_list))
    
    count_same += text_lower.count(W)
    
print(count_same)


Measured memory_bytes: 5564
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

int gcd(ll a, ll b) {
    ll x = a * b;
    if (a < b) swap(a, b);
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return x / b;
}

class DSemiCommonMultiple {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll N, M;
        in >> N >> M;
        vector<ll> a(N);
        REP(i,0,N) in >> a[i];
        REP(i,0,N) a[i] /= 2;
        ll x = 1;
        REP(i,0,N) {
            x = gcd(x, a[i]);
        }
        ll answer = M / x;
        answer = answer - answer / 2;
        REP(i,0,N) {
            if ((x / a[i]) % 2 == 0) {
                answer = 0;
                break;
            }
        }
        out << answer << "\n";
    }
};


signed main() {
    DSemiCommonMultiple solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

using namespace std;

bool dp[5001][(1 << 12)];

int main(){
    int n,m,LT,f[5000];
    char P[12][21],LP[12];
    char T[5001];
    bool occ[5001][12];

    while(true){
        scanf("%d %d",&n,&m);
        if(n == 0) break;

        for(int i = 0;i < n;++i){
            scanf("%s",P[i]);
            LP[i] = strlen(P[i]);
        }

        LT = 0;

        for(int i = 0;i < m;++i){
            scanf("%s",T + LT);
            LT += strlen(T + LT);
        }

        f[0] = 0;

        memset(occ,0,sizeof occ);

        for(int i = 0;i < n;++i){
            for(int j = 1,k = 0;j < LP[i];++j){
                while(k > 0 && P[i][j] != P[i][k]) k = f[k - 1];
                if(P[i][j] == P[i][k]) ++k;
                f[j] = k;
            }


            for(int j = 0,k = 0;j < LT;++j){
                while(k > 0 && T[j] != P[i][k]) k = f[k - 1];
                if(T[j] == P[i][k]) ++k;

                if(k == LP[i]){
                    occ[j - k + 1][i] = true;
                    k = f[k - 1];
                }
            }
        }

        memset(dp,0,sizeof dp);

        int M = (1 << n) - 1;
        dp[LT][0] = 1;

        for(int i = LT - 1;i >= 0;--i){
            dp[i][0] = 1;

            for(int mask = 1;mask <= M;++mask){
                int aux = mask;

                while(aux && !dp[i][mask]){
                    int j = __builtin_ctz(aux);
                    aux ^= (1 << j);

                    if(occ[i][j]) dp[i][mask] = dp[i][mask] || dp[i + LP[j]][mask ^ (1 << j)];
                }
            }
        }

        int ans = 0;

        for(int i = 0;i < LT;++i)
            if(dp[i][M]) ++ans;

        printf("%d\n",ans);
    }

    return 0;
}

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

using namespace std;

typedef struct node_{
    int id;
    int d;
    int k;//出次数
    int visited;
    vector<int> v;
}* node;

int main(){
    int n;
    scanf("%d", &n);
    vector<node> graph;
    node dummy;
    graph.push_back(dummy);
    for(int i = 1; i <= n; i++){
        node nd = new node_;
        nd -> d = -1;
        nd -> visited = 0;
        int id, k;
        scanf("%d %d", &id, &k);
        nd -> id = id;
        nd -> k = k;
        for(int i = 0; i < k; i++){
            int v1;
            scanf("%d", &v1);
            nd -> v.push_back(v1);
        }
        graph.push_back(nd);
    }
    graph[1] -> d = 0;

    queue<int> q;
    q.push(1);
    while(q.empty() != 1){
        int num = q.front();
        q.pop();
        node nd = graph[num];
        for(int i = 0; i < nd -> k; i++){
            if(graph[nd -> v[i]] -> d < 0){
                graph[nd -> v[i]] -> d = nd -> d + 1;
                q.push(nd -> v[i]);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        node nd = graph[i];
        printf("%d %d\n", nd -> id, nd -> d);
    }
    return 0;
}


Measured memory_bytes: 3252
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	ll ans(1);
	ll m = pow(10, 18);
	bool f = true;
	rep(i, n) {
		ll k;
		cin >> k;
		if (k == 0) {
			cout << 0;
			return 0;
		}
		ll bans = ans;
		ans *= k;
		if (ans > m) {
			f = false;
		}
		if (bans>m/k) {
			f = false;
		}
	}
	if (f) {
		cout << ans;
	}
	else {
		cout << -1;
	}

	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};


signed main(){
  cin.tie(0);	
  // ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  int n;
  cin>>n;
  int mp[h+2][w+2]={0};
  rep(i,h+2){
    mp[i][0]=mp[i][w+1]=-1;
  }
  rep(i,w+2){
    mp[0][i]=mp[h+1][i]=-1;
  }

  int nex=0;
  PII p={1,1};
  rep(i,n){
    int num;
    cin>>num;
    rep(j,num){
      mp[p.F][p.S]=(i+1);
      p.F+=dx[nex];
      p.S+=dy[nex];
      int cnt=0;
      while(mp[p.F][p.S]!=0 && cnt!=4){
	p.F-=dx[nex];
	p.S-=dy[nex];
	nex++;
	nex%=4;
	p.F+=dx[nex];
	p.S+=dy[nex];
	cnt++;
      }
      if(cnt==4){p.F-=dx[nex];p.S-=dy[nex];}
    }
  
  }
  repi(i,1,h+1){
    repi(j,1,w+1){
      cout<<mp[i][j];
      if(j!=w) cout<<" ";
    }
    cout<<endl;
  }
      
  return 0;
}


Measured memory_bytes: 384
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC081 A- Placing Marbles
int main(void) {
	char c1, c2, c3;
	int  ans=0;
	
	scanf("%c%c%c",&c1,&c2,&c3);
	
	if (c1 == 'o') ans++;
	if (c2 == 'o') ans++;
	if (c3 == 'o') ans++;

	printf("%d\n",700+100*ans);

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;




int main() {

    ll k;
    cin>>k;
    ll n=50;
    ll t=k/n;
    ll r=k-t*n;
    vll v(n,n-1+t);
    rep(i,r){
        v[i]+=n-r+1;
    }
    for(int i=r;i<n;i++)v[i]-=r;
    fin(n);
    dump(v);

}


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

int main(){
  int n,c;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++)
    cin >> vec.at(i);
  c=0;
  bool w=false;
  for(int i=0;i<30;i++){
    for(int j=0;j<n;j++){ 
      if(vec.at(j)%2==1){
        w=true;
        break;
      }
      vec.at(j)/=2;
    }
    if(w)
      break;
    c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <string>
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
  string S, front="", back="";
  int Q, D, F;
  char C;
  cin >> S;
  cin >> Q;
  bool rev = false;
  
  for(int i=0; i<Q; i++){
    cin >> D;
    if(D==1){
      rev = !rev;
    }else if(D==2){
      cin >> F >> C;
      if(rev){
        if(F==1){
          back = back+C;
        }else if(F==2){
          front = front+C;
        }
      }else if(!rev){
        if(F==1){
          front = front+C;
        }else if(F==2){
          back = back+C;
        }
      }
    }
      
  }
  reverse(front.begin(),front.end());
  S = front + S + back;
  if(rev)reverse(S.begin(), S.end());
 
  cout << S;
  return 0;
}

Measured memory_bytes: 1620
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,M;
char s[410][410];
int A[410][410];
bool F[410][410];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
P X;
int ans=0;

void DFS(int p,int q){
	F[p][q]=true;
	if(s[p][q]=='#')X.second++;
	else X.first++;
	REP(i,4){
		int nx=p+dx[i];
		int ny=q+dy[i];
		if(nx<0||ny<0||nx>=N||ny>=M||F[nx][ny]==true)continue;
		if(s[p][q]==s[nx][ny])continue;
		DFS(nx,ny);
		F[nx][ny]=true;
	}
}

signed main(){
	
	cin>>N>>M;
	REP(i,N){
		cin>>s[i];
	}
	REP(i,N)REP(j,M){
		X={0,0};
		DFS(i,j);
		ans+=X.first*X.second;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8064
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n-1];
        int[] b = new int[n-1];
        int[] pi = new int[n];
        int[] pc = new int[n];
        int[] ec = new int[n-1];
        Map<Long, Integer> map = new HashMap<>();
        List[] lists = new List[n];

        for(int i=0; i<n-1; i++) {
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
            map.put((((long)a[i]) << 20) + b[i], i);
            List list1 = lists[a[i]];
            if(list1 == null) {
                lists[a[i]] = new ArrayList<Integer>();
                list1 = lists[a[i]];
            }
            list1.add(b[i]);
            List list2 = lists[b[i]];
            if(list2 == null) {
                lists[b[i]] = new ArrayList<Integer>();
                list2 = lists[b[i]];
            }
            list2.add(a[i]);
        }

        Queue<Integer> q = new LinkedList<Integer>();
        q.add(0);
        pi[0] = -1;
        pc[0] = -1;
        int maxc = 0;
        while(!q.isEmpty()) {
            int w = q.poll();
            int nc = 0;
            if (pc[w] == 0)
                nc++;
            for (Integer next : (List<Integer>) lists[w]) {
                if (next != pi[w]) {
                    int min = Math.min(w, next);
                    int max = Math.max(w, next);
                    long key = (((long) min) << 20) + max;
                    ec[map.get(key)] = nc;
                    pi[next] = w;
                    pc[next] = nc;
                    maxc = Math.max(nc, maxc);
                    nc++;
                    if (pc[w] == nc)
                        nc++;
                    q.offer(next);
                }
            }
        }

        System.out.println(maxc + 1);
        for(int i=0; i<n-1; i++) {
            System.out.println( ec[i] + 1);
        }



    }
}


Measured memory_bytes: 111968
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

typedef pair<int,int> pii;
typedef long long int ll;
typedef long double ld;

const int DMAX = 110;

vector <int> ans[DMAX];

int V[DMAX];

int n;

void fct();

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

    int t,i,j;

    cin>>n;
    if(n <= 2){
        cout<<"-1\n";
        return 0;
    }
    if(n%2 == 1){
        fct();
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++)
            ans[i].pb(j);
        for(j=1;j<i;j++)
            ans[i].pb(j);
    }
    for(i=1;i<=n/2;i++){
        for(j=1;j<n;j+=2)
            swap(ans[i][j],ans[i][j+1]);
    }
    for(i=1;i<=n;i++){
        for(j=0;j<n-1;j++)
            cout<<ans[i][j]<<' ';
        cout<<'\n';
    }
    return 0;
}
void fct(){
    int i,j;
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++)
            cout<<j<<' ';
        for(j=1;j<i;j++)
            cout<<j<<' ';
        cout<<'\n';
    }
}


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

const int INF = 1e9;
ll n, m, x;
vector<vector<ll>> a;
vector<ll> c, current;

ll best(int j, ll acm){
    if(j==n){
        for(int i=0;i<m;i++){
            if(current[i]<x){
                return -1;
            }
        }
        return acm;
    }
    ll t1, t2;
    for(int i=0;i<m;i++){
        current[i] += a[j][i];
    }
    t1 = best(j+1,acm+c[j]);

    for(int i=0;i<m;i++){
        current[i] -= a[j][i];
    }
    t2 = best(j+1,acm);
    if(t1==-1 || t2==-1){
        return max(t1,t2);
    }
    return min(t1,t2);
}


int main(){
    

    cin >> n >> m >> x;
    a.assign(n,vector<ll>(m,0));
    c.assign(n,0);
    current.assign(m,0);

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

    ll answ = best(0,0);
    cout <<  answ << '\n';

    return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<int> p;
	string t = "";
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'x') {
			t += s[i];
			p.emplace_back(i);
		}
	}
	string u = t;
	reverse(u.begin(), u.end());
	if (t != u) {
		cout << -1 << endl;
		return 0;
	}
	if (p.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> a(1, 0), b(1, 0);
	for (int i = 0; i < p[p.size() / 2]; i++) {
		if (s[i] == 'x') a.back()++;
		else a.emplace_back(0);
	}
	for (int i = s.size() - 1; p[(p.size() - 1) / 2] < i; i--) {
		if (s[i] == 'x') b.back()++;
		else b.emplace_back(0);
	}
	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		ans += abs(a[i] - b[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long h1, w1, h2, w2; scan(h1, w1, h2, w2);
      if( w2 == 1 and h2 == 1 ) {
         puts("No");
      }
      // else if( w2 == 1 or h2 == 1 ) {
      //    bool res = (h1 / h2) * (w1 / w2) < h1 * w1 - (h1 / h2 * h2) * (w1 / w2 * w2);
      //    puts(res ? "Yes" : "No");
      //    if( res ) {
      //       for(long r = 0; r < h1; ++r) {
      //          printf("%ld", (r % h2 == h2 - 1) and (0 % w2 == w2 - 1) ? -h2 * w2 : 1);
      //          for(long c = 1; c < w1; ++c) {
      //             printf(" %ld", (r % h2 == h2 - 1) and (c % w2 == w2 - 1) ? -h2 * w2 : 1);
      //          }
      //          putchar('\n');
      //       }
      //    }
      // }
      else {
         long big = 500000000;
         bool res = h1 % h2 != 0 or w1 % w2 != 0;
         puts(res ? "Yes" : "No");
         if( res ) {
            for(long r = 0; r < h1; ++r) {
               printf("%ld", (r % h2 == h2 - 1) and (0 % w2 == w2 - 1) ? -h2 * w2 - big : (r % h2 == 0 and 0 % w2 == 0 ) ? big + 1 : 1);
               for(long c = 1; c < w1; ++c) {
                  printf(" %ld", (r % h2 == h2 - 1) and (c % w2 == w2 - 1) ? -h2 * w2 - big : (r % h2 == 0 and c % w2 == 0 ) ? big + 1 : 1);
               }
               putchar('\n');
            }
         }
      }
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 2816
N, M = list(map(int, input().split()))
ans = ['0' for i in range(N)]
conditions = [list(map(int, input().split())) for i in range(M)]
for c in conditions:
    if N > 1 and c[0] == 1 and c[1] == 0:
        print(-1)
        break
    elif ans[c[0] - 1] == '0' or ans[c[0] - 1] == str(c[1]):
        ans[c[0] - 1] = str(c[1])
    else:
        print(-1)
        break
else:
    if N > 1 and ans[0] == '0':
        ans[0] = '1'
    print(''.join(ans))



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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n >> a >> b;
    cout <<min(a,b) << " "<< max(0ll, a+b-n)  << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

using ll = long long int;
string S;
int pos;
int N, L;
vector<int> sequence() {
	vector<int> now;
	for (int i = 0; i < N*N; i++) now.push_back(i);
	while (pos < L && S[pos] != ')') {
		if (S[pos] == '(') {
			pos++;
			vector<int> ret = sequence();
			pos++;
			int num = 0;
			while (isdigit(S[pos])) {
				num *= 10;
				num += S[pos] - '0';
				pos++;
			}
			// (ret)num
			vector<vector<int>> d(30, vector<int>(N*N));
			d[0] = ret;
			for (int i = 1; i < 30; ++i) {
				// d[i]
				for (int j = 0; j < N*N; ++j) {
					d[i][j] = d[i - 1][d[i - 1][j]];
				}
			}

			// numを2べきで分解
			for (int i = 0; i < 30; ++i) {
				if (num & 1 << i) {
					for (int j = 0; j < N*N; ++j) {
						now[j] = d[i][now[j]];
					}
				}
			}
		}
		else {
			char shift = S[pos];
			pos++;
			int num = 0;
			while (isdigit(S[pos])) {
				num *= 10;
				num += S[pos] - '0';
				pos++;
			}
			num--;
			if (shift == 'L') {
				for (int i = 0; i < N*N; ++i) {
					int y = now[i] / N, x = now[i]%N;
					if (y == num) {
						if (x == 0) x = N - 1;
						else x--;
						now[i] = x + y*N;
					}
				}
			} else if (shift == 'R') {
				for (int i = 0; i < N*N; ++i) {
					int y = now[i] / N, x = now[i] % N;
					if (y == num) {
						if (x == N-1) x = 0;
						else x++;
						now[i] = x + y*N;
					}
				}
			}
			else if (shift == 'U') {
				for (int i = 0; i < N*N; ++i) {
					int y = now[i] / N, x = now[i] % N;
					if (x == num) {
						if (y == 0) y = N - 1;
						else y--;
						now[i] = x + y*N;
					}
				}
			}
			else if (shift == 'D') {
				for (int i = 0; i < N*N; ++i) {
					int y = now[i] / N, x = now[i] % N;
					if (x == num) {
						if (y == N-1) y = 0;
						else y++;
						now[i] = x + y*N;
					}
				}
			}
		}
	}
	return now;
}
int main() {
	cin >> N >> L;
	cin >> S;
	pos = 0;

	vector<int> ret = sequence();
	vector<vector<int>> ans(N, vector<int>(N));
	for (int i = 0; i < N*N; ++i) {
		int x = ret[i]%N, y = ret[i] / N;
		ans[y][x] = i+1;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cout << ans[i][j] << (j == N-1 ? '\n' : ' ');
		}
	}
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int cnt = 0;

    for (int i = 1; i <= n; i++) {
        int d = 0;
        int tmp = i;
        while (tmp) {
            tmp/=10;
            d++;
        }
        if (d % 2) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split(" "))
m = min(X,Y)
ans = m * min((A+B),(C+C))
X -= m
Y -= m
if X != 0:
	ans += (min(A,C+C) * X)
else:
	ans += (min(B,C+C) * Y)

print(ans)

Measured memory_bytes: 3064
/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n: u64 = io.r();
    let sum: u64 = (1..=n).filter(|i| i % 3 != 0 && i % 5 != 0).sum();
    io.w(sum);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define 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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll sum = 1000;
  rep(i,n-1){
    if(vec[i+1] > vec[i]){
      sum += sum / vec[i] * (vec[i+1] - vec[i]);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
N = int(input())

ST_list = []
for i in range(N):
  s, t = map(str, input().split())
  ST_list.append([
    s ,int(t)
  ])
  
X = str(input())
  
cnt = sum(list( node[1] for node in ST_list ))

for node in ST_list:
  cnt -= node[1]
  if X == node[0]:
    break
  
print(cnt)

Measured memory_bytes: 3064