akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
//円と円の交点
public class Main{
	public static void cross_cl(Circle c, Line l){
		if(l.x1 == l.x2){
			double ans1 = (double)c.y - Math.sqrt(Math.pow((double)c.r,2)-Math.pow((double)(l.x1-c.x),2));
			double ans2 = (double)c.y + Math.sqrt(Math.pow((double)c.r,2)-Math.pow((double)(l.x1-c.x),2));
			System.out.printf("%.8f %.8f %.8f %.8f\n",l.x1,ans1,l.x1,ans2);
		}
		else if(l.y1 == l.y2){
			double ans1 = (double)c.x - Math.sqrt(Math.pow((double)c.r,2)-Math.pow((double)(l.y1-c.y),2));
			double ans2 = (double)c.x + Math.sqrt(Math.pow((double)c.r,2)-Math.pow((double)(l.y1-c.y),2));
			System.out.printf("%.8f %.8f %.8f %.8f\n",ans1,l.y1,ans2,l.y1);
		}
		else{
			double a = (l.y2 - l.y1) / (l.x2 - l.x1);
			double ans1 = 1.0 + Math.pow(a,2);
			double ans2 = (double)c.x + a * a * l.x1 + a * c.y - a * l.y1;
			double ans3 = (double)(c.x * c.x) + Math.pow(a* l.x1 + (double)(c.y - l.y1),2) - (double)(c.r * c.r);
			double ansx1 = (ans2 - Math.sqrt(Math.pow(ans2,2)- ans1 * ans3))/ans1;
			double ansx2 = (ans2 + Math.sqrt(Math.pow(ans2,2)- ans1 * ans3))/ans1;
			double ansy1 = (ansx1 - l.x1) * a + l.y1;
			double ansy2 = (ansx2 - l.x1) * a + l.y1;
			System.out.printf("%.8f %.8f %.8f %.8f\n",ansx1,ansy1,ansx2,ansy2);
		}
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Circle c1 = new Circle(sc.nextLong(),sc.nextLong(),sc.nextLong());
		Circle c2 = new Circle(sc.nextLong(),sc.nextLong(),sc.nextLong());
		Line l = new Line(0.0,0.0,0.0,0.0);
		if(c1.x == c2.x){
			l.x1 = 0.0;
			l.x2 = 1.0;
			l.y1 = l.y2 = (c1.y + c2.y)/2.0 - (c1.r*c1.r - c2.r*c2.r)/(2.0*(c1.y - c2.y));
		}
		else if(c1.y == c2.y){
			l.y1 = 0.0;
			l.y2 = 1.0;
			l.x1 = l.x2 = (c1.x + c2.x)/2.0 - (c1.r*c1.r - c2.r*c2.r)/(2.0*(c1.x - c2.x));
		}
		else{
			l.x1 = 0.0;
			l.y1 = (c1.x*c1.x - c2.x*c2.x + c1.y*c1.y - c2.y*c2.y + c2.r*c2.r - c1.r*c1.r) / (2.0 * (c1.y - c2.y));
			l.x2 = (c1.x*c1.x - c2.x*c2.x + c1.y*c1.y - c2.y*c2.y + c2.r*c2.r - c1.r*c1.r) / (2.0 * (c1.x - c2.x));
			l.y2 = 0.0;
		    if(l.x1 == l.y1 && l.x2 == l.y2){
		        l.x1 = 1.0;
		        l.y1 = (c1.x*c1.x - c2.x*c2.x + c1.y*c1.y - c2.y*c2.y + c2.r*c2.r - c1.r*c1.r) / (2.0 * (c1.y - c2.y)) - (double)(c1.x-c2.x)/(c1.y-c2.y);
		    }
		}
		cross_cl(c1,l);
	}
}
class Circle{
	long x;
	long y;
	long r;
	Circle(long x, long y, long r){
		this.x = x;
		this.y = y;
		this.r = r;
	}
}
class Line{
	double x1;
	double y1;
	double x2;
	double y2;
	Line(double x1, double y1, double x2, double y2){
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
}


Measured memory_bytes: 26652
N, W = map(int, input().split())
INF, V = 1 << 40, 100
dp = [[INF for j in range(N*V+1)] for i in range(N+1)]


def main():
    v, w = [0 for i in range(N)], [0 for i in range(N)]
    for i in range(N):
        v[i], w[i] = map(int, input().split())

    dp[0][0] = 0
    for i in range(1, N+1):
        for j in range(N*V+1):
            if j < v[i-1]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1])

    ans = 0
    for i in range(N*V+1):
        if dp[N][i] <= W:
            ans = i

    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 17564
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c, x, y = sc.nextInt()
  if (a + b <= 2 * c) {
    println(a * x + b * y)
  } else {
    var ans = 0
    if (x <= y) {
      ans += 2 * c * x
      ans += (y - x) * b.min(2 * c)
    } else {
      ans += 2 * c * y
      ans += (x - y) * a.min(2 * c)
    }
    println(ans)
  }
}


Measured memory_bytes: 55372
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a, b; cin >> a >> b;
    int p[n];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int cnt[3] = {0};
    for (int i = 0; i < n; ++i) {
        if (p[i] <= a) {
            cnt[0]++;
        } else if (p[i] <= b) {
            cnt[1]++;
        } else {
            cnt[2]++;
        }
    }
    int mmin = cnt[1];
    if (cnt[0] < mmin) {
        mmin = cnt[0];
    }
    if (cnt[2] < mmin) {
        mmin = cnt[2];
    }
    cout << mmin << endl;
    return 0;
}


Measured memory_bytes: 256
N,K = list(map(int, input().split()))
S = input()

#n_l,n_r, n
S_ = []

pre = 0
for s in S:
  if s==pre:
    S_[-1] += 1
  else:
    S_.append(1)
    pre = s
    



ans = sum([n-1 for n in S_]) + min(2*K, len(S_)-1)
print(ans)
               

Measured memory_bytes: 4724
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = []
for i in range(N):
	D.append(A[i] - B[i])
D.sort()
ans = 0
shortage = 0
for i in D:
	if i >= 0:
		break
	ans += 1
	shortage += i
if shortage < 0:
	D.reverse()
	for i in D:
		if i < 0:
			ans = -1
			break
		shortage += i
		ans += 1
		if shortage >= 0:
			break
print(ans)

Measured memory_bytes: 18292
fun main() {
    val s = readLn()

    if (s.length == 2) println(if (s[0] == s[1]) "1 2" else "-1 -1")
    else {
        for (i in 0 until s.length - 2) {
            if (setOf(s[i], s[i + 1], s[i + 2]).size < 3) {
                println("${i + 1} ${i + 3}")
                return
            }
        }
        println("-1 -1")
    }
}

// Input Reader
private fun readLn() = readLine()!!


Measured memory_bytes: 54652
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}


signed main(){
	IOS
	int n, k;	cin >> n >> k;
	int power = 0,cur_n = 1;
	while(1){
		if(n < cur_n)	break;
		cur_n *= k, power++;
	}
	cout << power << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
long long temp;
long long f(long long x){
	temp=0;
	while(x/5!=0){
		temp+=x/5;
		x/=5;
	}
	return temp;
}

int main(){
	long long n;
	cin>>n;
	
	if(n%2==1){
		cout<<"0"<<endl;
	}
	else{
		cout<<f(n/2)<<endl;
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n, m ;
    cin >> n >> m ;
    vll cnt(n,0) ;

    REP(i,m){
        ll a, b ;
        cin >> a >> b ;
        a-- ;
        b-- ;
        cnt[a]++ ;
        cnt[b]++ ;
    }
    bool f = true ;
    REP(i,n){
        if(cnt[i]%2==1){
            f = false ;
        }
    }
    if(f){
        yes() ;
    }
    else{
        no() ;
    }


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3988
// oh, the less I know the better
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz
#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define pb push_back
#define sz(x) int(x.size())
#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N = 2e5+20;
const ll INF = 1e18;

struct STree{ // example: range sum with range addition
	vector<ll> st,lazy;int n;
	STree(int n): st(4*n+5,0), lazy(4*n+5,0), n(n) {}
	void push(int k, int s, int e){
		if(!lazy[k])return; // if neutral, nothing to do
		st[k]+=lazy[k]; // update st according to lazy
		if(s+1<e){ // propagate to children
			lazy[2*k]+=lazy[k];
			lazy[2*k+1]+=lazy[k];
		}
		lazy[k]=0; // clear node lazy
	}
	void upd(int k, int s, int e, int a, int b, ll v){
		push(k,s,e);
		if(s>=b||e<=a)return;
		if(s>=a&&e<=b){
			lazy[k]+=v; // accumulate lazy
			push(k,s,e);return;
		}
		int m=(s+e)/2;
		upd(2*k,s,m,a,b,v);upd(2*k+1,m,e,a,b,v);
		st[k]=min(st[2*k],st[2*k+1]); // operation
	}
	ll query(int k, int s, int e, int a, int b){
		if(s>=b||e<=a)return INF; // operation neutral
		push(k,s,e);
		if(s>=a&&e<=b)return st[k];
		int m=(s+e)/2;
		return min(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b)); // operation
	}
	void upd(int a, int b, ll v){upd(1,0,n,a,b,v);}
	ll query(int a, int b){return query(1,0,n,a,b);}
};  // usage: STree rmq(n);rmq.init(x);rmq.upd(s,e,v);rmq.query(s,e);

vector<ii> intv[N];

int main(){

	fastio;
	int n,m;
	cin >> n >> m;
	ll ans = 0;
	for(int i = 0; i < m; ++i){
		int l,r,a;
		cin >> l >> r >> a;
		ans += a;
		intv[r].pb(ii(l,a));
	}

	ll res = INF;
	STree st(n+5);
	for(int i = 1; i <= n+1; ++i){
		for(auto par : intv[i-1]){
			int l = par.fst, val = par.snd;
			st.upd(0,l,val);
		}
		st.upd(i,i+1,st.query(0,i));
	}
	res = st.query(0,n+1);
	cout << ans-res << endl;

	return 0;
}


Measured memory_bytes: 26672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
#define int ll
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=2e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
string s[maxn],q[maxn];
map<string,int>p;
bool cmp(string a,string b){
    return a<b;
}
signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i){
        cin>>s[i];
        p[s[i]]++;
    }//cout<<endl;
    int Max=0,len=0;
    for(int i=1;i<=n;++i)Max=max(Max,p[s[i]]);
    for(int i=1;i<=n;++i){
        if(p[s[i]]==Max){
            p[s[i]]=-1;
            q[++len]=s[i];
        }
    }sort(q+1,q+1+len);
    for(int i=1;i<=len;++i){
        for(int j=0;j<q[i].size();++j){
            cout<<q[i][j];
        }cout<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    
    int n;
    vector<int> vec;
    
    cin>>n;
    int k;
    cin>>k;
    
    for(int i=0;i<n;i++){
        
        int x;
        cin>>x;
        vec.push_back(x);
    }
    
    vector<int> dp;
    
    dp.push_back(0);
    
    int y;
    
    
    for(int i=1;i<n;i++){
        
        y=INT_MAX;
        
        for(int j=i-1;j>=i-k;j--){
            
            if(j>=0)
            y = min(y,abs(vec[i]-vec[j])+dp[j]);
            
            
        }
        
        dp.push_back(y);
        
    }
    
    cout<< dp[n-1];
    
    return 0;
    
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    for(int i = 0; i < 5; i++){
        int a;
        cin >> a;
        if(a == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn=1E6+5;
int n;
ll ans;
string str[maxn];
int tot,ch[maxn][26],have[maxn][27];
int bucket[26];
inline void insert(string s)
{
	int p=0;
	for(int i=s.size()-1;i>=0;--i)
		++bucket[s[i]-'a'];
	for(int i=s.size()-1;i>=0;--i)
	{
		int x=s[i]-'a';
		if(ch[p][x])
			p=ch[p][x];
		else
		{
			ch[p][x]=++tot;
			p=tot;
		}
		--bucket[x];
		for(int j=0;j<26;++j)
			if(bucket[j])
				++have[p][j];
		if(i==1)
		{
			x=s[0]-'a';
			for(int j=0;j<26;++j)
				if(j!=x)
					ans+=have[ch[p][j]][x];
		}
		if(i==0)
			ans+=have[p][26];
		++have[p][26];
	}
	if(s.size()==1)
		for(int i=0;i<26;++i)
			if(i!=s[0]-'a')
				ans+=have[ch[0][i]][s[0]-'a'];
	++have[p][26];
}
inline void solve()
{
	tot=0;
	memset(ch,0,sizeof(ch));
	memset(have,0,sizeof(have));
	for(int i=1;i<=n;++i)
		insert(str[i]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>str[i];
	solve();
	reverse(str+1,str+n+1);
	solve();
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 243476
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a[100000];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    if(n%2==0){
        for(int i=0;i<n;i++){
            if(a[i]!=((i/2)*2)+1){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    else{
        for(int i=0;i<n;i++){
            if(a[i]!=i+(i%2)){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    long long ans=(long long)1;
    for(int i=0;i<n/2;i++){
        ans*=(long long)2;
        ans%=(long long)1000000007;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int dp[11][46]={0};
	dp[0][0]=1;
	for(int k=0; k<10; k++)
	{
		for(int i=k; i>=0; i--)
		for(int j=0; j<46-k; j++)
		{
			dp[i+1][j+k] += dp[i][j];
		}
	}

	int N,S;
	while(cin>>N>>S, N||S)
	{
		if(0<=N && N<11 && 0<=S && S<46)
		{
			cout << dp[N][S] << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
}

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

using namespace std;

int main()
{
    //system("chcp 65001");

    int P,Q,R;
    cin >> P >> Q >> R;

    int ans = min({(P+Q),(R+Q),(P+R),(Q+R),(R+P),(Q+P)});

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
/*
void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  int n; cin>>n;
  vi A(n);
  rep(i,n){
    int p; cin>>p;
    A[p-1]=i+1; // 添え字のずれ
  }
  outv(A);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 2432
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;
std::vector<int> c(26);
int D;
std::vector<int>last(26);
std::vector<vector<int>>s;
int go(int indx,int S,int depth){
	if(indx == D || depth == 3)return S;
	
	for(int j=0;j<26;j++){
		S-=c[j]*(indx-last[j]);
	}
	int mx = 0;
	for(int j=0;j<26;j++){
		int takeback = s[indx][j] + c[j]*(indx-last[j]);
		mx = max(mx,go(indx+1,S+takeback,depth+1));
	}
	return mx;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	scanf("%d",&D);
	
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	s = vector<vector<int>>(D,vector<int>(26));
	for(int i = 0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	int S = 0;
	
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			S-=c[j]*(i-last[j]);
		}
		int who = 1;
		int mx = -1e9;
		int take = 0;
		for(int j=0;j<26;j++){
			int takeback = s[i][j] + c[j]*(i-last[j]);
			int wa = go(i+1,S+takeback,0);
			if(mx < wa){
				mx = wa;
				take = takeback;
				who = j+1;
			}
		}
		last[who-1] = i;
		S+= take;
		printf("%d\n",who );
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<string> ans[n];
  rep(i,n) {
    if(i == 0) {
      string s = "a";
      ans[i].push_back(s);
    } else {
      for(auto s : ans[i-1]) {
        char d = 'a';
        for(auto t : s) d = max(d,t);
        int k = d - 'a';
        rep(j,k+2) {
          char c = 'a' + j;
          string t = s + c;
          ans[i].push_back(t);
        }
      }
    }
  }
  for(auto s : ans[n-1]) cout << s << endl;
  return 0;
}


Measured memory_bytes: 11380
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
int a[maxn],n;
int main(){
	read(n);rep(i,1,n)read(a[i]);long long ans=0;
	rep(i,1,n-1){
		ans+=a[i]/2;
		a[i]%=2;
		int tmp=min(a[i],a[i+1]);
		a[i]-=tmp;a[i+1]-=tmp;
		ans+=tmp;
	}ans+=a[n]/2;
	cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int a,b,c,d,x,y;
	scanf("%d\n%d\n%d\n%d\n",&a,&b,&c,&d);
	1<=x<=59;
	1<=y<=59;
	x=(a+b+c+d)/60;
	y=(a+b+c+d)%60;
	printf("%d\n%d\n",x,y);
	return 0;
}

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

const int ac = 1e6 + 10, mod = 1e9 + 7;
ll A[ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, m; cin >> n >> m;
	if (abs(n - m) >= 2) { cout << 0 << '\n'; return 0; }
	ll w = 1;
	for (int i = 0; i < n; i++)
		w = w * (i + 1) % mod;
	for (int i = 0; i < m; i++)
		w = w * (i + 1) % mod;
	if (n == m) w = w * 2 % mod;
	cout << w << '\n';

}


Measured memory_bytes: 256
h, w = map(int, input().split())
pic = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if pic[i][j] == "#":
            # 上下左右の順に判定
            # １つでもあれば次へ
            if ((i-1 >= 0 and pic[i-1][j] == "#")
                or 
                (i+1 < h and pic[i+1][j] == "#")
                or
                (j-1 >= 0 and pic[i][j-1] == "#")
                or
                (j+1 < w and pic[i][j+1] == "#") ):
                continue
            else:
                print("No")
                exit()

print("Yes")


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

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

	if (s == t.substr(0, s.size())) {
		pYes;
	}
	else {
		pNo;
	}


}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll A, B;

int main()
{
    cin >> A >> B;
    ll ans = B % A == 0 ? A + B : B - A;
    OUT(ans);
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ote(x) cout<<(x)<<endl

int main(){
	int N; ll K; cin>>N>>K;
	vector<pair<int,int>> AB;
	rp(i,N){
		int a,b;
		cin>>a>>b;
		AB.emplace_back(a,b);
	}
	sort(AB.begin(), AB.end());
	for(auto p:AB){
		int a,b; tie(a,b)=p;
		K -= (ll)b;
		// cout<<a<<","<<b<<"\n";///
		if(K<=0){
			ote(a);
			return 0;
		}
	}
}


Measured memory_bytes: 1400
from itertools import permutations

N, M = map(int, input().split())
g = [[0] * N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    g[a][b] = 1
    g[b][a] = 1
# print(g)
check = set()

path = list(permutations(range(N)))

for t in path:
    if t[0] != 0:
        continue
    flag = True
    for i in range(N - 1):
        if g[t[i]][t[i + 1]] != 1:
            flag = False
            break
    if flag:
        check.add(t)

# print(check)
print(len(check))


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


int N, W;
vector<pair<int, int>> goods;
vector<vector<long long>> map1(101, vector<long long>(100001, -1));

long long knapsack(int i, int w){ //i番以降の品物で合計重さw以内の最大値
  if(i == N){
    return 0;
  }

  if(map1.at(i).at(w) != -1){
    return map1.at(i).at(w);
  }

  if(w - goods.at(i).first >= 0){
    return map1.at(i).at(w) = max(knapsack(i + 1, w), knapsack(i + 1, w - goods.at(i).first) + goods.at(i).second);
  } else{
    return map1.at(i).at(w) = knapsack(i + 1, w);
  }
}

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

  cin >> N >> W;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    pair<int, int> p = make_pair(a, b);
    goods.push_back(p);
  }

  cout << knapsack(0, W) <<endl;
}

Measured memory_bytes: 80256
#include<stdio.h>
int main(void)
{
    int N,k[10000],i,c,n;
    scanf("%d",&N);
    while(N!=0){
        n=0;
        c=0;
        for(i=0;i!=N;i++){
            scanf("%d",&k[i]);
        }
        for(i=0;i!=N;i++){
            if(k[i]>1){
                c++;
            }
            if(k[i]==0){
                n++;
            }
        }
        if(c!=0){
            printf("%d\n",N+1-n);
        }
        else{
            printf("NA\n");
        }
    scanf("%d",&N);
    }
    return 0;
}

Measured memory_bytes: 652
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                           
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        boolean can = false;

        for(int i=0; i<= M; i++){
            for(int j=0; j <= N; j++){
                if(K == j*(M-i) + i*(N-j) && !can){
                    System.out.println("Yes");
                    can = true;
                }
            }
        }
        if(!can) System.out.println("No");

    }
}


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

int n;
char s[2000000];
char ioi[2000000] = {0};

int main(void)
{
	while (scanf("%d", &n), n != 0){
		int i, j;
		int m;
		int len;
		int count;
		
		scanf("%d", &m);
		scanf("%s", s);
		ioi[0] = 'I';
		for (i = 0, j = 1; i < n; i++, j += 2){
			ioi[j] = 'O';
			ioi[j + 1] = 'I';
		}
		ioi[j] = 0;
		len = strlen(ioi);
		count = 0;
		for (i = 0; i <= m; i++){
			if (strncmp(s + i, ioi, len) == 0){
				count++;
				i++;
			}
		}
		printf("%d\n", count);
	}
	
	return 0;
}

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

using namespace std;



int main(){
  int N;
  cin >> N;
  
 
  
  vector<long long> V(N);
 
  for(int i = 0;i<N;i++){
    long long L;
    cin >> L;
    V[i]=L;
  }
  
  sort(V.begin(), V.end());
  
  
  int counter =0;
  for(int i = 0;i<N;i++){
    for(int j = i+1;j<N;j++){
      for(int k = j+1;k<N;k++){
        if(V[i]!=V[j]&&V[j]!=V[k]&&V[k]!=V[i]){
          if(V[i]+V[j]>V[k]){
            //cout << V[i] << V[j] << V[k] << endl;
              counter++;
          }
        }
      }
    }
  }
  cout << counter << endl;
    
  
  
  
 
}



Measured memory_bytes: 3544
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "homework"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;
	
int gcd(int a, int b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 200000;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int h[MAXN], a[MAXN], dp[MAXN + 1], t[MAXN*4];

int query(int v, int tl, int tr, int l, int r) {
	if (l >= r) return 0;
	else if (tl == l && tr == r) return t[v];
	else {
		int tm = (tl + tr) / 2;
		int r1 = query(2*v + 1, tl, tm, l, min(r, tm));
		int r2 = query(2*v + 2, tm, tr, max(l, tm), r);
		return max(r1, r2);
	}
}

void update(int v, int tl, int tr, int i, int x) {
	if (tl == tr - 1) t[v] = x;
	else {
		int tm = (tl + tr) / 2;
		if (i < tm) {
			update(2*v + 1, tl, tm, i, x);
		} else {
			update(2*v + 2, tm, tr, i, x);
		}
		t[v] = max(t[2*v + 1], t[2*v + 2]);
	}
}

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

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

	for (int i = 0; i <= 4*n; i++) {
		t[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		dp[i + 1] = query(0, 0, n, 0, h[i] + 1) + a[i];
		update(0, 0, n, h[i], dp[i + 1]);
	}

	cout << *max_element(dp, dp + n + 1);
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ull cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

int main() {
    cin >> n;
    bool is_even = n % 2 == 0;

    map<ll, ll> m;
    NREP() {
        cin >> tmp;
        if ((is_even && tmp % 2 == 0) || (!is_even && tmp % 2 != 0)) {
            END(0)
        }
        if (tmp == 0) {
            if (m[tmp] >= 1) {
                END(0)
            }
        } else {
            if (m[tmp] >= 2) {
                END(0)
            }
        }
        m[tmp]++;
    }

    MSG(mod_pow(2, n / 2) % MOD)
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
char s[2000005];
int main()
{
	int n,a,b,c,d;
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	scanf("%s",s+1);
	if(c==d)
	return printf("No"),0;
	if(c<d)
	{
		for(int i=b;i<d;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		return printf("No"),0;
		for(int i=a;i<c;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		return printf("No"),0;
	}
	if(c>d)
	{
		int f=0,ff=0;
		for(int i=b;i<d;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		return printf("No"),0;
		s[d]='#';
		for(int i=a;i<c;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		{
			ff=1;
			break;
		}
		if(!ff)
		return printf("Yes"),0;
		s[d]='.';
		for(int i=b;i<d;i++)
		if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')
		{
			f=1;
			break;
		}
		if(!f)
		return printf("No"),0;
		for(int i=a;i<c;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		return printf("No"),0;
	}
	printf("Yes");
} 

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <stdio.h>
#include <sstream>


using namespace std;
void swap(int &a, int &b);

int main()
{

	string sInput;
	cin >> sInput;
	int numOfOrder;
	cin >> numOfOrder;

	stringstream sOutput;

	for (int i = 0; i < numOfOrder; ++i)
	{
		string sOrder;
		cin >> sOrder;
		int a, b;
		cin >> a >> b;

		int num = b - a + 1;

		if (sOrder == "reverse")
		{
			string stemp;
			for (int j = b; j >= a; --j)
				stemp.push_back(sInput[j]);// << sInput[i];
			sInput.replace(a, num, stemp);
		}
		else if (sOrder == "replace")
		{
			string srep;
			cin >> srep;
			sInput.replace(a, num, srep);
		}
		else
		{
			//sOutput << sInput.substr(a, num) << endl;
			cout<< sInput.substr(a, num) << endl;
		}
	}

	//cout << sOutput.str() << endl;

	return 0;
}





Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
int xx[6],yy[6];
int inv[2000005],c[2000005];
const int mod=1e9+7;
int ans;
long long qpow(long long x,long long y){
     long long res=1;
	 while(y){
	    if(y&1)res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	 }
	 return res;
}
int getans(int x,int y){
   return 1ll*c[x+y]*inv[x]%mod*inv[y]%mod;
}
int calc(int x,int y){
    int res=0;
	res=(res+getans(x-xx[2],y-yy[2]))%mod;
	res=(res+getans(x-xx[1]+1,y-yy[1]+1))%mod;
	res=(res-getans(x-xx[1]+1,y-yy[2])+mod)%mod;
	res=(res-getans(x-xx[2],y-yy[1]+1)+mod)%mod;
	return res;
}
int calc2(int x,int y){
   int res=0;
   res=(res+getans(xx[5]-x,yy[5]-y))%mod;
   res=(res+getans(xx[6]-x+1,yy[6]-y+1))%mod;
   res=(res-getans(xx[6]-x+1,yy[5]-y)+mod)%mod;
   res=(res-getans(xx[5]-x,yy[6]-y+1)+mod)%mod;
   return res;
}
int main () {
	F(i,1,6)xx[i]=read();
	F(i,1,6)yy[i]=read();
	c[0]=1;
	F(i,1,2000000)c[i]=1ll*c[i-1]*i%mod;
	inv[2000000]=qpow(c[2000000],mod-2);
	f(i,1999999,0)inv[i]=1ll*(i+1)*inv[i+1]%mod;
	ans=0;
	F(i,xx[3],xx[4]){
	   ans=(ans+1ll*(mod-i-yy[3])*calc(i,yy[3]-1)%mod*calc2(i,yy[3])%mod)%mod;
	   ans=(ans+1ll*(i+yy[4]+1)*calc(i,yy[4])%mod*calc2(i,yy[4]+1)%mod)%mod;
	}
	F(i,yy[3],yy[4]){
	  ans=(ans+1ll*(mod-i-xx[3])*calc(xx[3]-1,i)%mod*calc2(xx[3],i)%mod)%mod;
	   ans=(ans+1ll*(i+xx[4]+1)*calc(xx[4],i)%mod*calc2(xx[4]+1,i)%mod)%mod;
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 15872
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, M, X, CA):
    ans = 10**10
    for p in range(1 << N):
        AA = [0] * (M + 1)
        C = 0
        for i in range(N):
            if p & (1 << i):
                C += CA[i][0]
                for j in range(1, M + 1):
                    AA[j] += CA[i][j]
        for i in range(1, M + 1):
            if AA[i] < X:
                break
        else:
            ans = min(ans, C)
    print(ans if ans < 10**10 else -1)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M, X = map(int, input().split())
    CA = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, M, X, CA)


Measured memory_bytes: 74188
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

const int MAX_N = 100000;
const int MAX_M = 20;
const int INF = 1 << 30;

template<typename T>class BIT {
    public:
    int n;
    vector<T> bit;
    
    BIT(int n): n(n){
        bit.resize(n);
        fill(bit.begin(), bit.end(), (T)0);
    }

    void add(int idx, int x){
        for(int i=idx;i<=this->n;i+=i&-i) bit[i] += x;
    }

    //bit[1]からbit[end]までの和 (閉区間)
    T sum(int end){
        T ret = (T)0;
        for(int i=end;i>=1;i-=i&-i) ret += bit[i];
        return ret;
    }

    //bit[1]からbit[end]までの和 (閉区間)
    T sum_range(int start, int end){
        return sum(end) - sum(start-1);
    }
};

int a[MAX_N], count_toy[MAX_M], dp[1<<MAX_M], count_dp[1<<MAX_M];
vector< BIT<int> > trees(MAX_M, BIT<int>(MAX_N+1));

int main() {
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        a[i]--;
        count_toy[a[i]]++;
        trees[a[i]].add(i+1, 1);
    }

    count_dp[0] = 0;
    for(int bit=0;bit<(1<<m);++bit) {
        for(int i=0;i<m;i++) {
            if(bit & (1 << i) || count_dp[bit|(1<<i)]) continue;
            count_dp[bit|(1<<i)] = count_dp[bit] + count_toy[i];
        }
    }

    fill(dp, dp+(1<<m), INF);
    dp[0] = 0;
    for(int bit=0;bit<(1<<m);++bit) {
        for(int i=0;i<m;++i) {
            if(bit & (1 << i)) continue;
            dp[bit | (1<<i)] = min(
                dp[bit | (1<<i)], 
                dp[bit] + count_toy[i] - trees[i].sum_range(count_dp[bit]+1, count_dp[bit]+count_toy[i])
            );
        }
        // cerr << bitset<4>(bit) << ": " << dp[bit] << endl;
    }

    cout << dp[(1<<m)-1] << endl;
}


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


int main(){
    int x, a, b;
    cin >> x >> a >> b;

    x -= a;
    x %= b;
    cout << x << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int H,W; cin>>H>>W;
    vector<vector<char>>h(H+2,vector<char>(W+2,'.'));
    /*rep(i,W+2){
        h[0][i]='.';
        h[H+1][i]='.';
    }
    rep(i,H+2){
        h[i][0]='.';
        h[i][W+1]='.';
    }*/
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            char s;
            cin>>s;
            h[i][j]=s;
        }
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(h[i][j]=='#'&&h[i-1][j]=='.'&&h[i+1][j]=='.'&&h[i][j-1]=='.'&&h[i][j+1]=='.'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
        cout << "error" << endl;
    else
        cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 3596
n = int(input())
l = [int(i) for i in input().split()]
x = str()
for i in range(n):
  if (l[i] % 2 == 0 and (l[i] % 3 == 0 or l[i] % 5 == 0)) or l[i] % 2 == 1:
    x = 'APPROVED'
    continue
  else:
    x = 'DENIED'
    break
print(x)

Measured memory_bytes: 2940
(declaim (ftype (function (string &optional) (values (vector string *) &optional)) split))
(defun split (text &optional (delim #\Space))
    (let* ((result (make-array 0
                               :element-type 'string
                               :adjustable t
                               :fill-pointer 0)))
          (loop :for c :across text
                :with temp = ""
                :do
                (cond ((char= c delim)
                       (vector-push-extend temp result)
                       (setf temp ""))
                    (t
                     (setf temp (concatenate 'string temp (string c)))))
                :finally
                (vector-push-extend temp result))
          result))

(declaim (ftype (function (integer integer) (values string &optional)) solve))
(defun solve (a b)
    (cond ((and (<= a 8) (<= b 8))
           "Yay!")
        (t ":(")))

(defun main ()
    (let* ((input (map 'vector #'parse-integer (split (read-line))))
           (a (aref input 0))
           (b (aref input 1)))
          (format t "~A~%" (solve a b))))

(main)

Measured memory_bytes: 16872
#include<cstdio>
#include<algorithm>
using namespace std;
int W, H, n;
int Num(int x, int y) {
	if (x == 0) return y;
	else if (y == H) return H + x;
	else if (x == W) return H + W + H - y;
	else if(y == 0)return (H + W) * 2 - x;
	return -1;
}
struct point {
	int x, num;
	bool operator <(const point &p)const {
		return x < p.x;
	}
}w[201000];
int cnt, st[201000], top;
int main() {
	int i, x1, y1, x2, y2;
	scanf("%d%d%d", &W, &H, &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d%d", &x1, &y1,&x2,&y2);
		int t;
		int b = Num(x1, y1), e = Num(x2, y2);
		if (b>=0&& e>=0) w[cnt++] = { b,i }, w[cnt++] = { e,i };
	}
	sort(w, w + cnt);
	for (i = 0; i < cnt; i++) {
		if (top && st[top] == w[i].num)top--;
		else st[++top] = w[i].num;
	}
	if (top)printf("NO\n");
	else printf("YES\n");
}

Measured memory_bytes: 2048
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(n: i64);
    let mut fac = vec![];
    for i in 1..1000000 {
        if i * i > n { break; }
        if n % i == 0 {
            fac.push(i);
            if i * i != n {
                fac.push(n / i);
            }
        }
    }
    let mut tot = 0;
    for r in fac {
        let m = n / r - 1;
        if m > 0 && r < m {
            tot += m;
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <cstdint>
#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 <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<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#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 mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#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 rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{    
    ll k, s;
    cin >> k >> s;
    ll r = 0;
    
    rep(i, k+1) {
        rep(j, k+1) {
            if(s-i-j >= 0 && s-i-j <= k) r++;
        }
    }
    
    mes(r);
	
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

void solve()
{
	string s;
	ll k;
	cin >> s;
	cin >> k;
	string t = s + s;
	int n = s.size();
	ll cnt[3] = {0, 0,0};
	int succ = 1;
	bool first=true;
	ll a,b;
	rep(i, n - 1)
	{
		if (s[i] == s[i + 1])
		{
			succ++;
		}
		else if (succ >= 2)
		{
			cnt[0] += floor((double)succ / 2);
			if(first){
				first=false;
				a=succ;
			}
			succ = 1;
		}
		else
		{
			succ = 1;
		}
	}
	b=succ;
	if(succ==n){
		cout<<(ll)(n)*k/2<<endl;
		return;
	}
	if (succ >= 2)
	{
		cnt[0] += floor((double)succ / 2);
		succ = 1;
	}
	else
	{
		succ = 1;
	}
	ll ans=0;
	if(s[0]==s[n-1]){
		ans=cnt[0]*k-(ll)((a/2)+(b/2)-(a+b)/2)*(k-1);
	}else{
		ans=cnt[0]*k;
	}
	


	cout << ans << endl;
	
	

		
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256