akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<iostream> 
#include<algorithm>
using namespace std; 
  
vector<int> arr;
vector<pair<int,long long int> > num;
long long int mod;
int n;
long long int k;
long long int getSum(int BITree[], int index) 
{ 
	long long int sum = 0; 
	while (index > 0) 
	{ 
		sum += BITree[index]; 
		index -= index & (-index); 
	} 
	return sum; 
} 
void updateBIT(int BITree[], int n, int index, int val) 
{ 
	while (index <= n) 
	{ 
	BITree[index] += val; 
	index += index & (-index); 
	} 
} 

void convert() 
{ 
	int temp[n]; 
	for (int i=0; i<n; i++) 
		temp[i] = arr[i]; 
	sort(temp, temp+n); 
	for (int i=0; i<n; i++) 
	{ 
		arr[i] = lower_bound(temp, temp+n, arr[i]) - temp + 1; 
	} 
} 

long long int func() 
{ 
	long long int ans = 0;  
	convert(); 
	int BIT[n+1]; 
	for (int i=1; i<=n; i++) 
		BIT[i] = 0; 
	for (int i=n-1; i>=0; i--) 
	{ 
		ans += getSum(BIT, arr[i]-1); 
		updateBIT(BIT, n, arr[i], 1); 
	} 

	return ans; 
} 

int main() 
{ 
    scanf("%d %lld",&n,&k);
    arr.clear();
    num.clear();
    arr.resize(n);
    num.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        num[i].first=arr[i];
        num[i].second=0;
    }
    mod=1e9+7;
    long long int ans = func();
    ans=ans%mod;
    //printf("in1 ans %lld\n",ans); 
    ans=(ans*k)%mod;
    //printf("in2 ans %lld\n",ans); 
    sort(num.begin(),num.end());
    for(int i=1;i<num.size();i++)
    {
        if(num[i].first>num[i-1].first)
        {
            num[i].second=i;
        }
        else
        {
            num[i].second=num[i-1].second;
        }  
        if(k>1)
        {
            long long int temp=(k*(k-1))/2;
            temp=temp%mod;
            //printf("temp %lld\n",temp);
            temp=(temp*(num[i].second))%mod;
            //printf("%d %d %lld %lld\n",i,num[i].first,num[i].second,temp);
            ans=(ans+temp)%mod;    
        }
    }
    printf("%lld\n",ans);
	return 0; 
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def sieve(n):
    if n == 1:return []
    primes = [1 if i%2 == 1 else 0 for i in range(n + 1)]
    primes[1] = 0
    primes[2] = 1
    for i in range(3,n + 1,2):
        if i * i > n:
            break
        if primes[i]:
            for j in range(i * i,n + 1,i):
                primes[j] = 0
    return [p for p in range(2,n + 1) if primes[p] == 1]

primes = sieve(10005)
P = len(primes)

def solve(N):
    ans = 0
    r = 0
    tot = 0
    for l in range(P):
        if primes[l] > N:
            break
        while r < P and tot + primes[r] <= N:
            tot += primes[r]
            r += 1
        if tot == N:
            ans += 1
        tot -= primes[l]
    print(ans)

while True:
    N = int(input())
    if N == 0:
        exit()
    solve(N)



Measured memory_bytes: 5696
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;
int a[200000];
int f[200000];

//答えをx以下にできるか
bool check(int x) {
	int i;
	static int g[200000];
	
	rep(i, n) { g[i] = x / f[i]; }
	
	int cst = 0;	//操作回数
	rep(i, n) { if (a[i] > g[i]) cst += a[i] - g[i]; }
	return cst <= k;
}

signed main() {
	int i;
	
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];
	sort(f, f + n, greater<int>());
	sort(a, a + n);
	
	int st = -1, ed = 1e+12, mid;	//(st, ed], xxxooo
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) ed = mid;
		else st = mid;
	}
	cout << ed << endl;
	return 0;
}

Measured memory_bytes: 4992
/*
  Vivek Rathi
  CSE 3rd Year
  MNNIT
  THUMB RULE - THINK FOR DP FIRST AND THEN GREEDY!!!
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define sz(x)	(ll)x.size()
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#define endl '\n'
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
//shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above-----------------------------------------------

int main()
{
	boost
	ll tot,k;
	cin>>tot>>k;
	ll ck=k;
	ll a[tot];
	multiset<ll,greater<ll> > p;
	multiset<ll,greater<ll> > n;
	ll z=0;
	for(ll i=0;i<tot;i++)
	{
		cin>>a[i];
		if(a[i]>0)
			p.insert(a[i]);
		else if(a[i]<0)
			n.insert(abs(a[i]));
		else 
			z++;
	}
	ll prod1=1;
	vector<ll> pp,nn;
	ll co=0;
	while((sz(p)+sz(n)>0))
	{
		if(sz(n)==0||abs(*p.begin())>=abs(*n.begin()))
		{
			prod1=((*p.begin())*prod1)%M;
			pp.pb((*p.begin()));
			p.erase(p.begin());
		}
		else
		{
			prod1=((*n.begin())*prod1)%M;
			nn.pb((*n.begin()));
			n.erase(n.begin());
			co++;
		}
		k--;
		if(k==0)
			break;
	}
	if(co%2==0&&k==0)
	{
		cout<<prod1<<endl;
		return 0;
	}	
	else if(k!=0)
	{
		cout<<0<<endl;
		return 0;
	}
	if(sz(p)>0&&((!(sz(n)>0&&sz(pp)>0))||(nn[sz(nn)-1]*((*n.begin()))<pp[sz(pp)-1]*(*p.begin()))))
	{
		prod1=(prod1*modpower(nn[sz(nn)-1],M-2,M))%M;
		prod1=(prod1*(*p.begin()))%M;
		cout<<prod1<<endl;
	}
	else if(sz(n)>0&&sz(pp)>0)
	{
		prod1=(prod1*modpower(pp[sz(pp)-1],M-2,M))%M;
		prod1=(prod1*(*n.begin()))%M;
		cout<<prod1<<endl;
	}
	else if(z!=0)
	{
		cout<<0<<endl;
	}
	else
	{
		multiset<ll> p;
		multiset<ll> n;
		p.clear();
		n.clear();
		k=ck;
		prod1=1;
		z=0;
		for(ll i=0;i<tot;i++)
		{
			if(a[i]>0)
			p.insert(a[i]);
			else if(a[i]<0)
				n.insert(abs(a[i]));
			else 
				z++;
		}
		while((sz(p)+sz(n)>0))
		{
			if(sz(n)==0||abs(*p.begin())>=abs(*n.begin()))
			{
				prod1=((*p.begin())*prod1)%M;
				pp.pb((*p.begin()));
				p.erase(p.begin());
			}
			else
			{
				prod1=((*n.begin())*prod1)%M;
				nn.pb((*n.begin()));
				n.erase(n.begin());
				co++;
			}
			k--;
			if(k==0)
				break;
		}
		//debug1(prod1);
		prod1 = (-prod1+M)%M;
		cout<<prod1<<endl;
	}
	return 0;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n,m;
    cin>>n>>m;
    int sums[n+1]={};
    rep(i,m){
        int l,r;
        cin>>l>>r;
        --l;--r;
        sums[l]++;
        sums[r+1]--;
    }
    rep(i,n){
        sums[i+1]+=sums[i];
    }
    int ans=0;
    rep(i,n+1){
        if(sums[i]==m)++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>

using namespace std;

const int N = 100000 + 5;

bool vis[N];
int c[N], ex[N], ey[N];
vector<pair<int, int>> v[N];

void dfs(int x)
{
    vis[x] = true;

    for (pair<int, int> pr : v[x])
    {
        if (vis[pr.first])
        {
            continue;
        }

        dfs(pr.first);

        if (c[pr.first] == 1)
        {
            c[pr.first] ^= 1;
            c[x] ^= 1;
            swap(ex[pr.second], ey[pr.second]);
        }
    }
}

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

    if (m % 2 != 0)
    {
        puts("-1");
        return 0;
    }

    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &ex[i], &ey[i]);
        v[ex[i]].push_back(make_pair(ey[i], i));
        v[ey[i]].push_back(make_pair(ex[i], i));
        c[ex[i]] ^= 1;
    }

    dfs(1);

    for (int i = 0; i < m; i++)
    {
        printf("%d %d\n", ex[i], ey[i]);
    }

    return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  nds; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int pow(int x, int y,int m)
{ 
	if(y==0)return 1;
	int u=pow(x,y/2,m);
	u=(u*u)%m;
	if(y%2)u=(x*u)%m;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
		int n;
	 string s;
	 cin>>n>>s;
	 int dp[1000000];
	 dp[0]=0;
	 fr(i,1,1000000)dp[i]=1+dp[i%__builtin_popcount(i)];
	 int ans1=0,ans2=0,ans3=0;
	 int c=0;
	 fr(i,0,n)c+=(s[i]=='1');
if(c!=0)
	{ 
			fr(i,0,n)if(s[i]=='1'){ans1=(ans1+pow(2,n-1-i,c))%c;ans2=(ans2+pow(2,n-1-i,c+1))%(c+1);if(c!=1)ans3=(ans3+pow(2,n-1-i,c-1))%(c-1);} 
}
	 fr(i,0,n)
	 {
	 	if(s[i]=='0')cout<<1+dp[(ans2+pow(2,n-1-i,c+1))%(c+1)]<<endl;
	 	else cout<<(c==1?dp[0]:1+dp[(c-1+ans3-(pow(2,n-1-i,c-1)))%(c-1)])<<endl;
	 }
	 
	 
	 
	 
	 	  
	  
	  
	
}



Measured memory_bytes: 11564
#include<stdio.h>

int main(){
	double weight;

	while(scanf("%lf",&weight)!=EOF){
		if(weight<=48.00)
			printf("light fly\n");
		else if(48.00<weight && weight<=51.00)
			printf("fly\n");
		else if(51.00<weight && weight<=54.00)
			printf("bantam\n");
		else if(54.00<weight && weight<=57.00)
			printf("feather\n");
		else if(57.00<weight && weight<=60.00)
			printf("light\n");
		else if(60.00<weight && weight<=64.00)
			printf("light welter\n");
		else if(64.00<weight && weight<=69.00)
			printf("welter\n");
		else if(69.00<weight && weight<=75.00)
			printf("light middle\n");
		else if(75.00<weight && weight<=81.00)
			printf("middle\n");
		else if(81.00<weight && weight<=91.00)
			printf("light heavy\n");
		else if(91.00<=weight)
			printf("heavy\n");
	}
	return 0;
}

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

typedef long long ll;

int main()    
{
    int n;
    cin>>n;
    int ans = 0;
    int a[n],b[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];

    for(int i=0;i<n;i++){
        if(a[i]>b[i]) ans += (a[i]-b[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 3612
def solve():
    A, B, K = list(map(int, input().split()))
    common_div = []
    for i in range(1, min(A, B)+1):
        if(A % i == 0 and B % i == 0):
            common_div.append(i)
    common_div.sort(reverse=True)
    print(common_div[K-1])


if __name__ == "__main__":
    solve()

Measured memory_bytes: 61916
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

using P = pair<ll, ll>;
#define fi first
#define se second

int main() {
    int q;
    cin >> q;
    ll pow3_30 = 1;
    for (int i=0; i<30; i++) pow3_30 *= 3;
    while (q--) {
        P p1, p2, b1, b2, r1, r2;
        cin >> p1.fi >> p1.se >> p2.fi >> p2.se;
        p1.fi--; p1.se--; p2.fi--; p2.se--;
        ll pow = pow3_30;
        ll dist = abs(p1.fi - p2.fi) + abs(p1.se - p2.se);
        while (pow /= 3) {
            b1 = {p1.fi / pow, p1.se / pow};
            b2 = {p2.fi / pow, p2.se / pow};
            r1 = {p1.fi % pow, p1.se % pow};
            r2 = {p2.fi % pow, p2.se % pow};
            if (b1.fi != b2.fi && b1.se != b2.se) {
                break;
            } else if (b1.fi == b2.fi && b1.se != b2.se && b1.fi % 3 == 1 && (b1.se+1) / 3 != (b2.se+1) / 3) {
                dist = abs(p1.se - p2.se) + min(r1.fi + r2.fi + 2, (pow-r1.fi) + (pow-r2.fi));
                break;
            } else if (b1.fi != b2.fi && b1.se == b2.se && b1.se % 3 == 1 && (b1.fi+1) / 3 != (b2.fi+1) / 3) {
                dist = abs(p1.fi - p2.fi) + min(r1.se + r2.se + 2, (pow-r1.se) + (pow-r2.se));
                break;
            }
        }
        cout << dist << '\n';
    }
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> v(n);
	REP(i, n)cin >> v[i];
	vvi cnt(n, vi(26, 0));
	REP(i, n) {
		REP(j, v[i].size()) {
			cnt[i][v[i][j] - 'a']++;
		}
	}
	vi res(26, INF);
	REP(i, 26) {
		REP(j, n) {
			res[i] = min(res[i], cnt[j][i]);
		}
	}
	string ans = "";
	REP(i, 26) {
		REP(j, res[i]) {
			ans += char('a' + i);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll n;
	cin>>n;
	if(n%2==1)cout<<n/2<<endl;
	else cout<<n/2-1<<endl;
	return 0;
}/*『你强归你强，我永不示弱』*/




Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
int cnt[10][10];

pii get(int n){
	vector<int> vec;
	while (n){
		vec.pb(n%10);
		n/=10;
	}
	return {vec[0], vec.back()};
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++){
		pii p=get(i);
		cnt[p.first][p.second]++;
	}
	for (int i=1; i<=n; i++){
		pii p=get(i);
		ans+=cnt[p.second][p.first];
	}
	kill(ans)
	
	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  s <- getContents
  forM_ (M.toList $ count s) $ \(c, n) -> do
    printf "%c : %d\n" c n

count :: String -> M.Map Char Int
count = foldr f mp0 . filter isLower . map toLower
 where
  f c mp = M.insertWith (+) c 1 mp
  mp0 = M.fromList [ (c, 0) | c <- ['a'..'z'] ]



Measured memory_bytes: 4188
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[a]++, A[b]++;
    }
    rep(i, N){
        if(A[i] % 2 == 1){
            output("NO");
            return 0;
        }
    }
    output("YES");
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define MODN 1000000007
ll modMult(ll a, ll b) {
    ll r = 0;
    while(b) {
        if(b&1) {r+=a;r%=MODN;}
        b>>=1;
        a+=a;
        a%=MODN;
    }
    return r;
}
int main() {
    ll n;
    cin>>n;
    ll s=0,v,c1,c2;
    ll arr[n];
    REP(i,n) cin>>arr[i];
    REP(i,60) {
        v=pow(2,i);c1=0;c2=0;
        REP(j,n) {
            if(arr[j]/v%2   ) {
                c1++;
            } else c2++;
        }
        s += modMult(modMult(v,c1),c2)%MODN;
        s%=MODN;
    }
    cout<<s<<endl;

}

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

int w, h;

void dfs(vector<vector<short>>& masu, int x, int y) {
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            if (0 <= x+i && x+i < w && 0 <= y+j && y+j < h) {
                if (masu[y+j][x+i]) {
//                    cout << "#: x=" << x+i << ", y="  << y+j << endl;
                    masu[y+j][x+i] = 0;
                    dfs(masu, x+i, y+j);
                }
            }
        }
    }
}

int main(void) {
    while (cin >> w >> h, w) {
        vector<vector<short>> masu(h, vector<short>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> masu[i][j];
            }
        }

        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (masu[i][j]) {
                    dfs(masu, j, i);
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1440
#include <cstdio>
using namespace std;
int main() {
    int a, b, c, d;
    scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
    int mult[] = {1, -1};
    char s[2] = {'+', '-'};
    int idx[3] = {};
    for (int i = 0; i < 8; i++) {
        idx[0] = (i & 0x1) > 0;
        idx[1] = (i & 0x2) > 0;
        idx[2] = (i & 0x4) > 0;
        if (a + b * mult[idx[0]] + c * mult[idx[1]] + d * mult[idx[2]] == 7) {
            printf("%d%c%d%c%d%c%d=7\n",a,s[idx[0]],b,s[idx[1]],c,s[idx[2]],d);
            return 0;
        }
    }
}




Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 802

vector<int> G[MAX_N];
queue<int> que;

ll dp[301][301][301]={};
int n,m;
int main() {
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	dp[1][0][0]=1;
	rep(i,n){
		rep(j,i+1) dp[i+1][j+1][j+1]=0;
	}
	rep(i,m){
		int l1,r1,x1;
		cin>>l1>>r1>>x1;
		rep(a1,r1){
			rep(a2,a1+1){
				if(x1==1){
					if(a1>=l1||a2>=l1)dp[r1][a1][a2]=0;
				}
				if(x1==2){
					if((a1>=l1&&a2>=l1)||(a1<l1&&a2<l1))dp[r1][a1][a2]=0;
				}
				if(x1==3){
					if(a2<l1||a1<l1)dp[r1][a1][a2]=0;
				}
			}
		}
	}
//	rep(i,n+1){
//		rep(j,i){
//			rep(k,j+1){
//				printf("%d %d %d %d\n",i,j,k,dp[i][j][k]);
//			}
//		}
//	}

	REP(i,2,n+1){
		rep(j,i){
			rep(k,j+1){
				if(dp[i][j][k]==0)continue;
				dp[i][j][k]=0;
				if(j==i-1){
					rep(i2,j){
						if(i2<k)dp[i][j][k]+=dp[j][k][i2];
						if(i2>=k)dp[i][j][k]+=dp[j][i2][k];
						dp[i][j][k]%=i197;
					}
				}else{
					dp[i][j][k]=dp[i-1][j][k];
				}
			}
		}
	}

	ll t=dp[n][0][0]*3;
	rep(j,n){
		rep(k,j){
			t+=dp[n][j][k]*6;
			t%=i197;
//			printf("%d %d %d\n",j,k,dp[n][j][k]);
		}
	}
//	t*=6;
//	t%=i197;
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 213376
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    ll n; cin >> n;
    string ans = "";
    --n;
    while (1) {
        if (n < 26) {
            ans += char('a' + n);
            break;
        }
        ans += char('a' + n % 26);
        n -= 26;
        n /= 26;
    }
    print(reversed(ans));
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<ll> h(N);
  REP(i, N){
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  
  ll ans = 1e16;
  REP(i, N-K+1){
    ans = min(ans, h[i+K-1]-h[i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long [] array = new long[N+1];
		long sum=0;
		for(int i=1;i<=N;i++) {
			array[i] = sc.nextLong();
			sum += array[i];
		}

		long [][] dp = new long[3002][3002];

		long X = solve(dp, array, 1, N, 1);
		long Y = sum-X;
		return X-Y;
	}

	private long solve(long [][] dp, long []array, int i, int j, int turn) {

		if(i>j) return 0;
		if (dp[i][j]!=0) return dp[i][j];
		if (turn==1) {
			long selectLeft = array[i] + solve(dp, array, i+1, j, 0);
			long selectRight = array[j] + solve(dp, array, i, j-1, 0);
			dp[i][j] = Math.max(selectLeft, selectRight);
		} else {
			long selectLeft = solve(dp, array, i+1, j, 1);
			long selectRight = solve(dp, array, i, j-1, 1);
			dp[i][j] = Math.min(selectLeft, selectRight);
		}
		return dp[i][j];

	}

}

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

int main(){
	int N,A,B,C,X;
	int Y[101];
	int i;
	while(1){
		int count = 0;
		cin >> N >> A >> B >> C >> X;
		if(N+A+B+C+X==0) break;
		for(i = 0 ;  i < N ;i++){
			cin >> Y[i];
			}
		for(i = 0 ; i < 10001 ; i++){
			if(X==Y[count]) count++;
			if(count == N) break;
			X = (A*X+B)%C;
			}
		if(i != 10001) cout << i << endl;
		else cout << "-1" << endl;
		}
	return 0;
	}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		Task[] tasks = new Task[n];
		
		for(int i = 0; i < n; i++) {
			String[] tmpArray = br.readLine().split(" ");
			
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			
			tasks[i] = new Task(i, a, b);
		}
		
		Arrays.sort(tasks);
		
		long currentTime = 0;
		for(int i = 0; i < n; i++) {
			if(currentTime > tasks[i].beginLimit) {
				System.out.println("No");
				return;
			}
			
			currentTime += tasks[i].length;
			
//			System.out.println("task "+tasks[i].id + " finished : "+currentTime);
		}
		
		System.out.println("Yes");
	}

}

class Task implements Comparable<Task> {
	int id;
	int length;
	int deadLine;
	int beginLimit;
	
	Task(int id, int length, int deadLine){
		this.id = id;
		this.length = length;
		this.deadLine = deadLine;
		this.beginLimit = deadLine - length;
	}

	@Override
	public int compareTo(Task t) {
		// TODO Auto-generated method stub
//		return this.beginLimit - t.beginLimit;
		return this.deadLine - t.deadLine;
	}
	
	
}

Measured memory_bytes: 64532
import sys

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

init_dp = lambda v,n:[v]*(n)

import math
# 四捨五入はround
ceil = lambda a:math.ceil(a) # 切り上げ
floor = lambda a:math.floor(a) # 切り捨て

def dfs(s,N):
    ans = 0
    if s != '' and int(s) > N:return ans
    if all(c in s for c in '753'):ans+=1
    for c in '753':
        ans += dfs(s+c,N)
    return ans
    
def solution():
    N = input_int()
    sys.setrecursionlimit(N+10)
    ans = dfs('',N)
    print(ans)

if __name__ == '__main__':
    solution()

Measured memory_bytes: 5128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 || W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (i == 0 || i == H - 1) {
                        System.out.printf("#");
                    } else {
                        if (j == 0 || j == W - 1) {
                            System.out.printf("#");
                        } else {
                            System.out.printf(".");
                        }
                    }
                }
                System.out.printf("\n");
            }System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 60620
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int n = s.length(), i;
	for(i=0;i<n;i++){
		if(s[i] == '?')cout << 'D';
		else cout << s[i];
	}return 0;
}

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

using namespace std;
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; }

const long long INF = 1LL << 60;
long long dp[100100];

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

    string ans = "Heisei";
    if(S[5] == '0') {
        if((int)S[6] < (int)'5') ans = "Heisei";
        else ans = "TBD";
    }else ans = "TBD";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:break
    f=[[0 for i in range(b)]for j in range(a)]
    for i in range(a):
        for j in range(b):
            if i==0 or i==a-1 or j==0 or j==b-1:
                f[i][j]=1
    for i in range(a):
        for j in range(b):
            if f[i][j]==1:
                print('#',end='')
            else :
                print('.',end='')
        print()
    print()



Measured memory_bytes: 7260
#include<stdio.h>

int main(void){
    int a=0;
    int b=0;
    int n=0;
    scanf("%d %d %d",&n,&a,&b);
    if(a*n<=b){
        printf("%d\n",a*n);
    }
    else printf("%d\n",b);

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
//int NUMOFDIV(int n) 素因数分解して+1してかける奴
int NUMOFDIV2(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0,dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N,Al=0,Bo=0;
	cin >> N;
	vector <int> a(N);
	rep(i, N)
		cin >> a[i];
	sort(ALL(a),greater<int>());
	rep(i, N) {
		if (i % 2 == 0)
			Al += a[i];
		else
			Bo += a[i];
	}
	cout << Al -Bo;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
  long long int a,b,i;
  cin>>a>>b;
  long long int big=max(a,b);
  long long int small=min(a,b);
  for(i=big;;i=i+big)
  {
      if(i%small==0)
      {
          cout<<i;
          break;
      }
  }

   return 0;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
  
  private static long X = 1000000007;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    long[][] memo = new long[N+1][N+1];
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N; j++) {
        memo[i][j] = -1;
      }
    }
    for (int i = 1; i <= K; i++) {
      long count = (comb(N-K+1, i, memo) * comb(K-1, i-1, memo)) % X;
      System.out.println(count);
    }
  }
  
  private static long comb(int n, int r, long[][] memo) {

    if (r == n || r == 0) {
      return 1;
    }
    if (n == 0) {
      return 0;
    }

    if (memo[n][r] != -1) {
      return memo[n][r];
    }
        
    memo[n][r] = (comb(n-1, r-1, memo) + comb(n-1, r, memo)) % X;
    
    return memo[n][r];
  }
}


Measured memory_bytes: 82900
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    if (a <= x && a + b >= x)
    {
        ce("YES");
    }
    else
    {
        ce("NO");
    }
}

Measured memory_bytes: 256
N=gets.to_i
As=gets.split.map(&:to_i)

prev=As[0]
mode=0
count = 1
As.each_with_index{|a, i|
    if i == 0
        next
    end
    # puts "start: i=#{i}, a=#{a}, mode=#{mode}, prev=#{prev}, count=#{count}"
    if mode == 0
        if a > prev
            mode = 1
        elsif a < prev
            mode = -1
        end
    elsif (mode > 0 && a < prev) || (mode < 0 && a > prev)
        count += 1
        mode = 0
    end
    # puts "end  : i=#{i}, a=#{a}, mode=#{mode}, prev=#{prev}, count=#{count}"
    prev = a
}
puts count


Measured memory_bytes: 8452
#include<iostream>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int a = 1;
    int b = 1;
    for(int i = 9; i >= 1; i--){
        if (n % i == 0){
            a = i;
            b = n / i;
            break;
        }
    }
    if (a <= 9 && b <= 9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
import fractions

n, ma, mb = map(int,input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int,input().split())

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10**15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]

for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            # i番目を買うか、買わないか
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)


Measured memory_bytes: 81364
#include<bits/stdc++.h>
using namespace std;
int dp[100000+1][3];
int n;
int vac(int v[][3],int ind,int f){
      if(ind==-1) return 0 ;
      
      if(f==-1){
            return max(v[ind][0]+vac(v,ind-1,0),max(v[ind][1]+vac(v,ind-1,1),v[ind][2]+vac(v,ind-1,2)));
      }
      if(dp[ind][f]!=-1) return dp[ind][f];
      if(f==0){
            return dp[ind][f]=max(v[ind][1]+vac(v,ind-1,1),v[ind][2]+vac(v,ind-1,2));
      }
      if(f==1)
      return dp[ind][f]=max(v[ind][0]+vac(v,ind-1,0),v[ind][2]+vac(v,ind-1,2));
      if (f==2)
      return dp[ind][f]=max(v[ind][1]+vac(v,ind-1,1),v[ind][0]+vac(v,ind-1,0));
      
      
}
int main(){
  int i,j;
  memset(dp,-1,sizeof(dp));
  cin>>n;
  int v[n][3];
  for(i=0;i<n;i++){
    for(j=0;j<3;j++)        
    cin>>v[i][j];
  }
  int ans=vac(v,n-1,-1);
  cout<<ans;
  
 
}
  
  

Measured memory_bytes: 13760
#include <iostream>
#include<math.h>
using namespace std;

int main() {
  int n,i,k,j[10000000];
  cin>>n;
  for(i=1;i<n;i++){
    j[i]=0;
  }
  for(i=1;i<n;i++){
    cin>>k;
    j[k]++;
  }
  
  for(i=1;i<=n;i++){
    cout<<j[i]<<endl;
  }
  
}



Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}

int n,m;

#define Num(x,y) f[x+10][y+10]

int f[100][100];


inline void init()
{
    n=read();
    REP(i,1,n)
    {
	ll x=0;
	char ch=getchar();
	int ws=0,flg=0;
	while(ch!='\n' && ch!=-1)
	{
	    if(ch=='.')flg=1;
	    else if(isdigit(ch))
	    {
		ws-=flg;
		x=x*10+ch-'0';
	    }
	    ch=getchar();
	}
	int ws2=ws,ws5=ws;
	while(x%2==0)x/=2,ws2++;
	while(x%5==0)x/=5,ws5++;
	Num(ws2,ws5)++;//f[ws2][ws5]++;
    }
    ll ans=0;
    REP(x1,-10,30)REP(y1,-10,30)REP(x2,-10,30)REP(y2,-10,30)
	if(Num(x1,y1) && Num(x2,y2))
	if(x1+x2>=0 && y1+y2>=0)
	{
	    if(x1==x2 && y1==y2)ans+=1ll*Num(x1,y1)*(Num(x1,y1)-1);
	    else ans+=1ll*Num(x1,y1)*Num(x2,y2);
	}
    printf("%lld\n",ans/2);
}

int main()
{
    init();
    return 0;
}


Measured memory_bytes: 3764
/*  ex3_2
    Graku   */
#include <stdio.h>
#include <math.h>

int main(void) {
    int n, k; //declaration
    scanf("%d %d", &n, &k);

    /*
    write n in k base, and divide n by k.
    this operation mean remove ones place.
    */
    int count = 0; //initialized
    do {
        count++;
    } while (n /= k);

    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC126A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var s = Console.ReadLine();
            for(int i = 0; i< nk[0]; i++)
            {
                if (i == nk[1] - 1)
                {
                    Console.Write(char.ToLower(s[i]));
                    continue;
                }
                Console.Write(s[i]);
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

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

int main() {
  int K,X; 
  cin >> K>>X;
  int min=X-K+1;
  int max=X+K-1;
  for(int i=min;i<=max;++i){
    if(i!=max){
      cout<<i<<" ";
    }else{
      cout<<i<<endl;
    }
  }
  //cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}

void Main()
{
  ld a, b, x; cin >> a >> b >> x;
  if(b * a * a == x) fin(0.);
  x /= a;
  if(b * a / 2. >= x)
  {
    ld base = x * 2. / b;
    fin(atan(b / base) * 180 / PI);
  }
  else
  {
    ld S = a * b - x;
    ld hide = S * 2. / a;
    fin(atan(hide / a) * 180 / PI);
  }
  
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

struct Player
{
	struct Player *prev;
	struct Player *next;
	int alive;
};

int main(void)
{
	int m, n;
	
	while (scanf("%d %d", &m, &n), m != 0){
		int i;
		struct Player player[20000];
		struct Player *current;
		int flag = 0;
		int t = m;
		
		for (i = 0; i <= m; i++){
			player[i].prev = player + (i - 1 + m)  % m;
			player[i].next = player + (i + 1) % m;
			player[i].alive = 1;
		}
		current = player;
		for (i = 1; i <= n; i++){
			char s[2048];
			int dead;
			
			scanf("%s", s);
			if (t == 1){
				continue;
			}
			if (i % 3 == 0){
				if (i % 5 == 0){
					dead = strcmp(s, "FizzBuzz");
				}
				else {
					dead = strcmp(s, "Fizz");
				}
			}
			else if (i % 5 == 0){
				dead = strcmp(s, "Buzz");
			}
			else {
				char num[16];
				
				sprintf(num, "%d", i);
				dead = strcmp(s, num);
			}
			if (dead != 0){
				current->prev->next = current->next;
				current->next->prev = current->prev;
				current->alive = 0;
				t--;
			}
			current = current->next;
		}
		
		for (i = 0; i < m; i++){
			if (player[i].alive == 1){
				if (flag == 0){
					printf("%d", i + 1);
					flag = 1;
				}
				else {
					printf(" %d", i + 1);
				}
			}
		}
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 660
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc= new Scanner(System.in);
		
		int S = sc.nextInt();
		int[] A = new int[S];
	
		int sum = 0;
		for(int i =0; i<S; i++) {
			A[i]  = sc.nextInt();
				
			
			
			
		}
		Arrays.sort(A);
		int temp = A[S-1]/2;
		A[S-1] = 0;
		for(int i =0; i<S; i++) {
			sum = sum + A[i];
		}
		System.out.println(sum + temp);
		
		
		
	}

}


Measured memory_bytes: 35816