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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
vvi dp(1050, vi(1050));

int lcs(string x, string y) {
	int ans = 0;
	int m = x.size();
	int n = y.size();

	x = ' ' + x;
	y = ' ' + y;
	REP3(i, 1, m) {
		REP3(j, 1, n) {
			if (x[i] == y[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
			ans = max(ans, dp[i][j]);
		}
	}

	return ans;
}

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

	int q;
	cin >> q;

	string str1, str2;
	REP(i, q) {
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << "\n";
	}
	return 0;
}

Measured memory_bytes: 7452
a, b, c = map(int, input().split())
s = 0
g = 0
if a < b:
    s = a
    g = b
else:
    s = b
    g = a
if c < s:
    print(str(c) + ' ' + str(s) + ' ' + str(g))
elif g < c:
    print(str(s) + ' ' + str(g) + ' ' + str(c))
else:
    print(str(s) + ' ' + str(c) + ' ' + str(g))
    



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x)                cerr<<#x<<": "<<x<<endl
#define t2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // for (ll p=2; p<=n; p++) 
       // if (prime[p]) 
          // cout << p << " "; 
} 
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
  
int main()
{
    fastio
    long long int t,i,j,k,l,m,n,a,x,b,y,z,c,h,d,f,e,p,o,nl,np,q,r,g;
    string s;
    vector<pair<ll,ll>>v(5);
    rep(i,0,5)
    {
        cin>>x;
        v[i].ff=x;
        v[i].ss=i+1;
    }
    sort(v.begin(),v.end());
    cout<<v[0].ss<<endl;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
using namespace std;
double dp[305][305][305];
bool vis[305][305][305];
int n,cnt[4];
double dfs (int i,int j,int k) {
	if(i==0&&j==0&&k==0) return 0;
	if(vis[i][j][k]) return dp[i][j][k];
	vis[i][j][k]=true;
	dp[i][j][k]=1;
	if(i!=0) dp[i][j][k]+=dfs(i-1,j,k)*i/n;
	if(j!=0) dp[i][j][k]+=dfs(i+1,j-1,k)*j/n;
	if(k!=0) dp[i][j][k]+=dfs(i,j+1,k-1)*k/n;
	dp[i][j][k]/=1.0*(i+j+k)/n;
	return dp[i][j][k];
}
int main () {
	cin>>n;
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	printf("%.10lf",dfs(cnt[1],cnt[2],cnt[3]));
}

Measured memory_bytes: 246016
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    cin >> a;
    vector <vector <int>> gr(n);
    forn (i, 0, m) {
        int v, u;
        cin >> v >> u, --v, --u;
        gr[v].pb(u), gr[u].pb(v);
    }
    int cnt = 0;
    forn (i, 0, n) {
        bool higher = true;
        for (int j : gr[i])
            if (a[j] >= a[i])
                higher = false;
        if (higher)
            cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 8740
/*input
8
3 1 4 1 5 9 2 6
*/
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d", &n);
	int mx = 0, mn = 1000;
	while (n--){
		int x; scanf("%d", &x);
		mx = max(mx, x); mn = min(mn, x);
	}
	printf("%d\n", mx - mn);
}

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

r = 0
l = 0
ans = 0
while r < N:
    if r < N - 1 and H[r + 1] <= H[r]:
        r += 1
        ans = max(ans, r - l)
    elif r != l:
        l += 1
    else:
        l += 1
        r += 1
print(ans)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
int main()
{   /// Standing in the hall of fame
    ios_base::sync_with_stdio() , cin.tie(NULL) , cout.tie(NULL);
    int n , x , len;
    string s;
    cin >> n >> s;
    len = s.length();
    for(int i = 0 ; i < len ; i++){
        x = s[i]-'A';
        x = ((x+n%26)%26)+'A';
        s[i] = char(x);
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
   int a,b;
   cin>>a>>b;
   if(a<=9&&b<=9)
    cout<<a*b;
   else
    cout<<-1;

}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

template<class T>
T fibonacci(T n) {
	T first = 1, second = 0, ans;
	for (int i = 0; i < n; ++i) {
		if (i == 1)
			second = 1;
		ans = first + second;
		first = second;
		second = ans;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	cout << fibonacci(n + 1) << endl;

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,r;
  cin >> n >> r;
  if(n>=10)
  cout << r;
  else
  cout << r+(100*(10-n));
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
const int N = 200005;
 
int n, arr[N];
int par[N], sz[N];
 
inline int findRoot(int x) {
    if (par[x] == x) {
        return x;
    }
    return par[x] = findRoot(par[x]);
}
 
inline void mergeTree(int x, int y) {
    x = findRoot(x);
    y = findRoot(y);
    par[x] = y;
    sz[y] += sz[x];
}
 
int main() {
    ios :: sync_with_stdio(false);
    cin >> n;
    vector < pair < int, int > > values;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
        values.push_back(make_pair(arr[i], i));
        par[i] = 0; sz[i] = 1;
    }
    sort(values.begin(), values.end());
    reverse(values.begin(), values.end());
    long long ans = 0;
    for (auto val : values) {
        int index = val.second;
        par[index] = index;
        int rightContribution = 1;
        int leftContribution = 1;
        if ((index + 1 <= n) && (par[index + 1] != 0)) {
            rightContribution += sz[findRoot(index + 1)];
            mergeTree(index, index + 1);
        }
        if ((index - 1 >= 1) && (par[index - 1] != 0)) {
            leftContribution += sz[findRoot(index - 1)];
            mergeTree(index, index - 1);
        }
        ans += ((leftContribution * 1LL * rightContribution) * val.first);
    }
    cout << ans << endl;
}

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

using namespace std;


int main() {

	int N;
	cin >> N;

	vector<int> An;
	int a;


	long long sum = 0;

	for (int i = 0; i < N; i++) {
		cin >> a;
		An.push_back(a);
		sum += a;
	}

	long long ans = sum;
  
  	for (int j = 1; j < N; j = j + 2) {
          ans -=  (2 * An[j%N]);
	}

	for (int i = 0; i < N; i++) {
		cout << ans << " ";
		ans = 2 * An[i] - ans;
	}


}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    if((a==b && a!=c) || (a==c && b!=c) || (b==c && a!=b)) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3628
#input
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0] = B[0]
for i in range(0, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]
    
print(sum(A))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int k;
    int a,b;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            break;
        }
        else if(i==b)
            cout<<"NG";        
    }

}

Measured memory_bytes: 3624
//
//  main.cpp
//  Selection of Participants of an Experiment
//
//  Created by x15071xx on 2017/06/13.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    
   
    while (1) {
        
        int n,i,min=10000000,tmp;
        vector<int> s;
        
        
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        for (i = 0; i < n; i++) {
            cin >> tmp;
            s.push_back(tmp);
        }
        
        sort(s.begin(), s.end());
        
        for (i = 0; i < s.size()-1; i++) {
            int ans = abs(s[i] - s[i+1]);
            
            if (ans < min) {
                min = ans;
            }
        }
        
        cout << min << endl;
        
    }
    return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[2][3001][3001];
int n;
/*
fn(int a[],int i,int j,int k)
{
	
	/*if(i>n)
	return 0;
	
	if(j<-1)
	return 0;
	
	if(i==j)
     {
     	dp[k][i][j]=a[i];
      return a[i];
	 }
	if(dp[k][i][j]!=-1)
	return dp[k][i][j];
	
	dp[0][i][j]=max(fn(a,i+1,j)+a[i],fn(a,i,j-1)+a[j]);
	
	return dp[k][i][j];
	
	
}
*/
int32_t main()
{
	//int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	cin>>a[i];
	for(int i=0; i<n; i++)
	for(int j=0; j<n; j++)
	{
		dp[0][i][j]=0;
		dp[1][i][j]=INT_MAX;
	}
     for(int i=0; i<n; i++)
     {
     	dp[0][i][i]=a[i];
     	dp[1][i][i]=-a[i];
	 }
	 
	 for(int l=2; l<=n; l++)
	 {
	 	for(int i=0; i<=n-l; i++ )
	 	{
	 		int j=i+l-1;
	 		
	 		dp[0][i][j]=max(dp[1][i+1][j]+a[i],dp[1][i][j-1]+a[j]);
	 		dp[1][i][j]=min(dp[0][i+1][j]-a[i],dp[0][i][j-1]-a[j]);
	 		
		 }
	 }
	
	cout<<dp[0][0][n-1];
	
	
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define fs first
#define ss second



int main(){

  ll x;
  cin >> x;

  ll ans = (x/500)*(1000);

  ans +=   ((x%500)/5)*5 ;

  cout << ans << endl; 
 

}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int red,blue;
int c[2002][2002];
signed main(){
	cin>>red>>blue;
	red-=blue;
	c[0][0]=1;
	for(int i=1;i<=2000;i++){
		c[i][0]=c[i][i]=1;
		for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	for(int step=1;step<=blue;step++){
		int ans=1;
		ans=c[blue-1][step-1];
		int x=red;x++;
		(ans*=c[x][step])%=mod;
		cout<<ans<<endl; 
	}
	return 0;
}

Measured memory_bytes: 30080
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char str[maxn];

int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	cin>>str;
	int len=strlen(str);
	int ans=len/2;
	for(int i=len-ans,j=ans+1;1;i--,j++)
	{
		// cout<<i<<" "<<j<<endl;
		int flag=1;
		 for(int w=i;w<j;w++)
		 {
		 	if(str[w]!=str[i-1])
		 	{
		 		flag=0;
		 		break;
		 	}
		 }
		 if(!flag)
		 	break;
		ans++;
	}	
	cout<<ans<<endl;
	
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  int ans = INF;
  int a;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    if (a & 1) {
      ans = 0;
      break;
    }
    else {
      int cnt = 0;
      while (not (a & 1)) {
        a >>= 1;
        ++cnt;
      }
      ans = min(ans, cnt);
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
    cin >> A >> B >> C >> D;
  if(A + B > C + D)
    cout <<"Left" << endl;
  else if(A + B == C + D)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll AB = C * 2;
    ll ans = 1e18;
    for(int i = 0;i <= max(X,Y);i++){
        if(ans > AB * i + max(0,X-i) * A + max(0,Y-i) * B){ans = AB * i + A * max(0,X-i) + B * max(0,Y-i);}
    }
    cout << ans;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i = 0, j, l = 0;
    char s[202], p[102];

    fgets(s, 202, stdin);
    fgets(p, 102, stdin);

    while (s[i++] != '\n')
	l++;
    
    for (i = 0; i < l; i++)
	s[l + i] = s[i];
    s[l + i] = '\0';

    for (i = 0; i < l; i++) {
	j = 0;
	while (p[j] != '\n') {
	    if (s[i + j] != p[j])
		break;
	    j++;
	}
	if (p[j] == '\n')
	    break;
    }

    printf("%s\n", (p[j] == '\n' ? "Yes" : "No"));
    
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG


int main() {
  string S;
  cin >> S;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  if (S.at(2)==S.at(3) && S.at(4)==S.at(5)){
  cout << "Yes" << endl;
  return 0;  
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int N;
  cin >> N;
  
  N = pow(N,3);

  cout << N << endl;
}



Measured memory_bytes: 892
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

ll comb(ll n, ll k) {
    mint ret = 1;
    FOR(i, 1, k+1) {
        ret *= (n - i + 1);
        ret /= (k - i + 1);
    }

    return ret.x;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll n, a, b;
    cin >> n >> a >> b;

    mint ans = pow_mod(2, n);

    ans -= (1 + comb(n, a) + comb(n, b));

    cout << ans << endl;
    
}


Measured memory_bytes: 256
fn main() {
    fn input<T: std::str::FromStr + Copy> () -> (T, T) {
        let mut ab = String::new();
        std::io::stdin().read_line(&mut ab).unwrap();
        let ab: Vec<T> = ab.trim().split_whitespace().flat_map(str::parse).collect();
        (ab[0], ab[1])
    }

    let (_, m) = input::<usize>();
    let mut ns: Vec<_> = (0..m).map(|i| {
        let (p, y) = input::<usize>();
        (p, y, i)
    }).collect();
    ns.sort();
    let mut cp = 0;
    let mut index = 1;
    let mut ns: Vec<_> = ns.into_iter().map(|(p, _, i)| {
        if p != cp {
            cp = p;
            index = 1;
        } else {
            index += 1;
        }
        (i, format!("{:06}{:06}", cp, index))
    }).collect();
    ns.sort();
    for (_, s) in ns.into_iter() {
        println!("{}", s);
    }
}


Measured memory_bytes: 12540
import sys

n, m = map(int, sys.stdin.readline().strip().split())

mat = []

for _ in range(n):
    mat.append(list(map(int, sys.stdin.readline().strip().split())))

vec = []

for _ in range(m):
    vec.append(int(sys.stdin.readline()))

for i in range(n):
    print(sum(mat[i][j] * vec[j] for j in range(m)))



Measured memory_bytes: 6016
n, m, l = [int(i) for i in input().split()]
 
A = []
B = []
C = []
 
for ni in range(n):
    A.append([int(i) for i in input().split()])
 
for mi in range(m):
    B.append([int(i) for i in input().split()])
 
for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
 
for ni in range(n):
    print(" ".join([str(s) for s in C[ni]]))

Measured memory_bytes: 8832
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      string a,b;
      cin>>a>>b;
      int c = 0;
      for(int i=0;i<a.length();i++)
      {
        if(a[i]!=b[i])
          c++;
      }
      cout<<c<<endl;
      return 0;
    }

Measured memory_bytes: 3828
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(M)]

INF = 1 << 28
ds = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
    ds[i][i] = 0

for abc in ABC:

    ds[abc[0]][abc[1]] = ds[abc[1]][abc[0]] = min(ds[abc[0]][abc[1]], abc[2])

for k in range(N + 1):
    for i in range(N + 1):
        for j in range(N + 1):
            ds[i][j] = ds[j][i] = min(ds[i][j], ds[i][k] + ds[k][j])
cnt = 0
for abc in ABC:
    used = False
    for i in range(N + 1):
        for j in range(N + 1):
            if ds[i][j] == ds[i][abc[0]] + abc[2] + ds[abc[1]][j]:
                used = True
    if not used:
        cnt += 1

print(cnt)


Measured memory_bytes: 44780
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int cards[205];
    int n, m;
    while(cin >> n >> m){
        rep(i,n * 2){
            cards[i] = i + 1;
        }
        int co;
        rep(i, m){
            int g[205];
            cin >> co;
            if(co == 0){
                int A[105],B[105];
                rep(j,n){
                    A[j] = cards[j];
                    B[j] = cards[n + j];
                }
                rep(j,n * 2){
                    if(j % 2 == 0){
                        cards[j] = A[j / 2];
                    }else{
                        cards[j] = B[j / 2];
                    }
                }
            }else{
                int l = 0;
                range(j, co, n * 2){
                    g[l++] = cards[j];
                }
                rep(j,co){
                    g[l++] = cards[j];
                }
                rep(j,n * 2){
                    cards[j] = g[j];
                }
            }
        }
        rep(i,n * 2){
            cout << cards[i] << endl;
        }
    }
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> a(N+1); repp(i,1,N+1) cin >> a[i];

    vector<int> ans(N+1); repp(i,1,N+1) ans[i] = -1;
    ans[0] = 0;
    bool can = true;
    repm(i,N,0) {

        vector<int> v;
        int I = i;
        while(I <= N) {
            v.push_back(I);
            I += i;
        }
        sort(v.begin(), v.end(), greater<int>());

        int count = 0;
        for(auto x: v) {
            if (ans[x] == -1) {
                if (count % 2 == a[x]) ans[x] = 0;
                else ans[x] = 1;
            } else {
                count += ans[x];
            }
        }
    }
    if (can) {
        int count = 0; for(auto x: ans) count += x;
        cout << count << endl;
        bool f = true;
        repp(i,1,N+1) {
            if (ans[i] != 0) {
                if (!f) cout << " " << i;
                else {
                    cout << i;
                    f = false;
                }
            }
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3304
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
	const int MAX = 1001;
	int N;
	while(cin >> N, N) {
		int tmp, ans = 0;
		FOR(i, 1, MAX) {
			tmp = 0;
			FOR(j, i, MAX) {
				tmp += j;
				if(tmp == N) {
					ans++;
				} else if(tmp > N) {
					break;
				}
			}
		}
		cout << ans-1 << endl;
	}
}

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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;



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

    bool check=true;
    for (int i = 0; i < S.size(); i++)
    {
        if(i%2==0){
            if(S[i]!='h') check=false; 
        }
        if(i%2==1) {
            if(S[i]!='i') check=false;
        }
        if(S[S.size()-1]=='h') check=false;
    }
    check?cout<<"Yes"<<endl:cout<<"No"<<endl;
    


    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

bool check(ll x) {

    string s = to_string(x);
    ll n = s.size();
    ll m = n/2;

    rep(i, m) {
        if(s[i] != s[(n-1) - i]) {
            return false;
        }
    } 

    return true;
}

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

    ll ans = 0;
    exrep(x, a, b) {
        if(check(x)) {
            ans++;
        }
    }

    out(ans);
    re0;
}

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

int main()
{
    char s;
    cin >> s;
    if (isupper(s))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int s = C / B + (C % B == 0 ? 0 : 1);
  int t = A / D + (A % D == 0 ? 0 : 1);
  cout << (s <= t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <sys/stat.h>
using namespace std;
using ll = int64_t;

int main(int , char **)
{
#ifdef LOCAL_DEBUG
	struct stat sb;
	ifstream in("/dev/shm/input.txt");
	if (stat("/dev/shm/input.txt",&sb)==0){ cin.rdbuf(in.rdbuf()); }
#endif

	ll N;
	cin >> N;
	for(ll h=1;h<=3500;h++){
		for(ll n=1;n<=3500;n++){
			ll Nhn= N*h*n;
			ll z = 4*h*n - N*n - N*h;
			if (0 < z){
				if (Nhn % z == 0){
					printf("%ld %ld %ld\n",h,n,Nhn/z);return 0;
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		ArrayList<int[]> data = new ArrayList<int[]>();
		
		long result = 0;
		boolean flag = true;
		
		for(int i = 0; i < N; i++) {
			int[] input = new int[2];
			input[0] = sc.nextInt();
			input[1] = sc.nextInt();
			data.add(input);
		}
		data.sort((a,b) -> Integer.compare(a[0],b[0]));
		
		int i = 0;
		int count_m = 0;
		int count = 0;
		
		while(M != count_m) {
			result += data.get(i)[0];
			count++;
			count_m++;
			
			int next_i = count/data.get(i)[1];
			count = count%data.get(i)[1];
			i += next_i;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 88900
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
int main(){
 int k;char s[105];
 scanf("%d ",&k);
 int i,len=0;
 for(i=0;i<105;i++){
  scanf("%c",&s[i]);
  if(s[i]=='\n')break;
  len++;
 }
  
 if(len<=k){
  for(i=0;i<len;i++)
   printf("%c",s[i]);
  return 0;
 }
  
  else{
   for(i=0;i<k;i++)
   printf("%c",s[i]);
   puts("...");
   return 0;
  }

return 0;}

Measured memory_bytes: 3760
import java.math.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong(),k=sc.nextLong();
		int arr[]=new int[(int) n+1];
//		int ans[]=new int[(int) n+1];
		for(int i=1;i<=n;i++){
			arr[i]=sc.nextInt();
		}
		HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
		int index=1;
		int count=1;
		while(!map.containsKey(arr[index])){
			map.put(arr[index], count);
//			ans[count]=index;
			count++;
			index=arr[index];
		}
		int cell=count-map.get(arr[index]);
		int form=map.get(arr[index]);
		if(k>=count){
			k-=count;
			k%=cell;
			k+=count;
			k-=cell;
		}
		for(int ts:map.keySet()){
//			System.out.println(ts+" "+map.get(ts));
			if(map.get(ts)==k){
				
				System.out.println(ts);
			}
		}
	}
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll MOD = 1000000007;
  ll n;
  cin >> n;
  ll ten = 1, nine = 1, eight = 1;
  rep(i,n){
    ten *= 10;
    ten %= MOD;
  }
  rep(i,n){
    nine *= 9;
    nine %= MOD;
  }
  rep(i,n){
    eight *= 8;
    eight %= MOD;
  }
  ll ans = ten - (nine*2 - eight) + MOD*10;
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll h,w;
    cin >> h >> w;
    ll a[3];
    ll ans=100000000000;
    for (ll i=1; i<=h-2; i++){
        a[0]=w*i;
        a[1]=(h-i)/2*w;
        a[2]=h*w-a[0]-a[1];
        sort(a,a+3);
        ans=min(ans,a[2]-a[0]);
    }
    for (ll i=1; i<=h-1; i++){
        a[0]=w*i;
        a[1]=(h-i)*(w/2);
        a[2]=h*w-a[0]-a[1];
        sort(a,a+3);
        ans=min(ans,a[2]-a[0]);
    }
    for (ll i=1; i<=w-2; i++){
        a[0]=h*i;
        a[1]=(w-i)/2*h;
        a[2]=h*w-a[0]-a[1];
        sort(a,a+3);
        ans=min(ans,a[2]-a[0]);
    }
    for (ll i=1; i<=w-1; i++){
        a[0]=h*i;
        a[1]=(h/2)*(w-i);
        a[2]=h*w-a[0]-a[1];
        sort(a,a+3);
        ans=min(ans,a[2]-a[0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
const int M = 100000;

int main()
{
	int x[M];
	int y[M];
	int i = 0;
	while (1) {
		cin >> x[i] >> y[i];
		if (x[i] == 0 && y[i] == 0) {
			break;
		}
		if (x[i] > y[i]) {
			swap(x[i], y[i]);
		}
		cout << x[i] << " " << y[i] << endl;
		i++;
	}
	return 0;
}

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

using namespace std;


int main() {
    int h, w, K;
    cin >> h >> w >> K;
    vector<vector<char>> c(h, vector<char>(w));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    int ans = 0;
    vector<vector<char>> v = c;
    for(int i = 0; i < (1 << h); i++) {
        for(int j = 0; j < (1 << w); j++) {
            for(int k = 0; k < h; k++) {
                if((i >> k) & 1) {
                    for(int l = 0; l < w; l++) {
                        v[k][l] = '.';
                    }
                }
            }
            for(int k = 0; k < w; k++) {
                if((j >> k) & 1) {
                    for(int l = 0; l < h; l++) {
                        v[l][k] = '.';
                    }
                }
            }
            int counter = 0;
            for(int x = 0; x < h; x++) {
                for(int y = 0; y < w; y++) {
                    if(v[x][y] == '#') {
                        counter++;
                    }
                }
            }
            if(counter == K) {
                ans++;
            }
            v = c;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        int cnt = int.Parse(Reader.ReadLine());

        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        Dictionary<long, int> stock = new Dictionary<long, int>();
        inpt.ToList().ForEach(a=>{
            if(stock.ContainsKey(a)) {
                stock[a]++;
            } else {
                stock[a] = 1;
            }
        });

        cnt = int.Parse(Reader.ReadLine());

        inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        bool isValid = true;

        foreach(long mondai in inpt) {
            if(stock.ContainsKey(mondai)) {
                if(stock[mondai] <= 0) {
                    isValid = false;
                    break;
                } else {
                    stock[mondai]--;
                }
            } else {
                isValid = false;
                break;
            }
        }

        string ans = "NO";
        if(isValid) {
            ans = "YES";
        }
        Console.WriteLine(ans);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



5
3 1 4 1 5
3
5 4 3


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 53220
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

ll F(char c){
    if(c!='a')return 'z'-c+1;
    return 0;
}

int main(){
    string S;
    cin >> S;
    ll K;
    cin >> K;
    ll mark=0;
    while(K>0){
        if(F(S[mark])<=K){
            K-=F(S[mark]);
            S[mark]='a';
        }
        mark++;
        if(mark==S.size()){
            ll k=K;
            for(ll i=0;i<k;i++){
                if(S[mark-1]!='z')S[mark-1]++;
                else S[mark-1]='a';
                K--;
            ;}
        }
    }
    cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
long long calc(long long h)
{
	if(h)
	{
		return calc(h / 2) * 2;
	}
	else
	{
		return 1;
	}
}
int main()
{
	long long h;	
	scanf("%lld", &h);
	printf("%lld\n", calc(h) - 1);
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let (n, c) = readl!(usize, usize);
    let d: Vec<_> = (0..c).map(|_| readlvec!(i64)).collect();
    
    let cv: Vec<Vec<_>> = (0..n).map(|_| readlvec!(i64).into_iter().map(|x| x-1).collect()).collect();
    


    let mut cov = vec![vec![0; c]; 3];
    for (i, row) in cv.iter().enumerate() {
        for (j, &e) in row.iter().enumerate() {
            cov[(i+j)%3][e as usize] += 1;
        }
    }
    let cov = cov;

    let inf = 1_000_000_000_000;
    let mut ans = inf;
    for c0 in 0..c {
        for c1 in 0..c { 
            for c2 in 0..c {
                if c0 == c1 || c1 == c2 || c0 == c2 {
                    continue;
                }
                let ccv = [c0, c1, c2];
                let mut cost = 0;
                for i in 0..3 {
                    for j in 0..c {
                        cost += cov[i][j]*d[j][ccv[i]];
                    }
                }
                ans = min(ans, cost);
            }
        }
    }
    printfln!("{}", ans);
}


Measured memory_bytes: 6396
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        c: [Chars; h],
    }

    let mut ans = 0;
    for i in 0..1 << h {
        for j in 0..1 << w {
            let mut count = 0;
            for m in 0..h {
                for n in 0..w {
                    if i >> m & 1 == 0 && j >> n & 1 == 0 {
                        if c[m][n] == '#' {
                            count += 1;
                        }
                    }
                }
            }
            if count == k {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/02  Problem: 010_agc_b / Link: https://agc010.contest.atcoder.jp/tasks/agc010_b?lang=en  ----- */
/* ------問題------

N 個の箱が円環状に並んでおり、i 番目の箱には Ai 個の石が入っています。
以下の操作を繰り返して、全ての石を取り除くことができるか判定してください。
箱を一か所選ぶ。それを i 番目としたとき、1 から N の各 j に対して、i+j 番目の箱から石をちょうど j 個取り除く。
ただし、N+k 番目と表される箱は k 番目の箱と同一視するものとする。
各操作において、取り除きたい個数の石がない箱があるときは、その操作を行えないことに注意してください。

-----問題ここまで----- */
/* -----解説等-----

わからないので悲しくなって階差をとると、数字に規則性を感じる。
階差を取ることで得られる情報として、数列を生成するごとに+1がn-1回、-Nが1回加算される。
このことからこれが成り立っているかを確認すれば良い。
条件は”階差数列の値が数列を生成するのに必要な回数以下、かつ先の関係が成立している”

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(2 * N);
	LL sum = 0;
	FOR(i, 0, N) {
		cin >> a[i];
		a[i + N] = a[i];
		sum += a[i];
	}

	ans = 1;
	LL k = sum / (N*(N + 1) / 2);

	if (k*(N*(N + 1) / 2) != sum)ans = 0;

	FOR(i, 0, N) {
		int diff = a[i + 1] - a[i];
		if (k - diff < 0 || ((k - diff) % N != 0))ans = 0;
	}
	if (ans) {
		cout << "YES" << endl;
	}
	else
		cout << "NO" << "\n";

	return 0;
}


Measured memory_bytes: 1024
// Aizu 0204: UFO Shooting Down Operation
// 2017.9.11 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EPS 1e-7

typedef struct { double a, d; int r, v; char f; } T;
T ufo[103]; int n, m;

double equ2(double a, double b, double c)  // ax^2 + bx + c = 0
{
    double d = b*b - 4*a*c;     /* ????????? */
    double x1 = 0.0;            /* ?§£ */
    if (d > EPS || d >= 0) x1 = (-b + sqrt(d)) / (2*a);
    return x1;
}

int cmp(T *a, T *b)
{
    double x;
	if (b->f - a->f) return (int)(b->f - a->f);
	x = a->d - b->d;
    if (fabs(x) <= EPS) return 0;
    if (x <= 0) return -1; else return 1;
}

int hit(int k, double aa, double lim)
{
	double a, b, c;
	double d, r, x;

	b = fabs(ufo[k].a - aa), d = ufo[k].d, r = ufo[k].r;
	a = 1.0, b = -2.0*d*cos(b), c = d*d-r*r;
	x = equ2(a, b, c);
	if (fabs(x - lim) > EPS && x >= lim) return 1;
	return 0;
}

int main()
{
    int i, x, y, ans, t;
	double a, r;

	while (scanf("%d%d", &t, &n) && t) { r = t;
        for (ans = 0, m = n, i = 0; i < n; i++) {
            scanf("%d%d%d%d", &x, &y, &ufo[i].r, &ufo[i].v), ufo[i].f = 1;
            if (x == 0 && y == 0) ufo[i].f = 0, ans++, m--;
            ufo[i].a = atan2((double)y, (double)x);
            ufo[i].d = sqrt(x*x + y*y)-ufo[i].v;
        }
        while (m > 0) {
			qsort(ufo, n, sizeof(T), cmp);
			for (i = 0; i < n; i++) if (ufo[i].f) {
				if (fabs(ufo[i].d - r) <= EPS || ufo[i].d <= r) { ufo[i].f = 0, m--, ans++; continue; }
				ufo[i].f = 0, m--;	// fire
				a = ufo[i].a;
				break;
			}
			for (i = 0; i < n; i++) if (ufo[i].f) {
				if (hit(i, a, r)) ufo[i].f = 0, m--;
			}
			for (i = 0; i < n; i++) if (ufo[i].f) {
				ufo[i].d -= ufo[i].v; { if (ufo[i].d <= 0) ufo[i].f = 0, m--, ans++; }
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    int dp[n + 1][m + 1]{};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    string ans = "";
    int r = n;
    int c = m;
    while (r > 0 && c > 0) {
        if (s[r - 1] != t[c - 1]) {
            if (dp[r - 1][c] > dp[r][c - 1]) r--;
            else c--;
        } else {
            ans += s[r - 1];
            r--;
            c--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 35456