akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 505;
const int MM = 1000000007;

int D[MX][MX];

int main()
{
	int H, W, h, w;
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if( H%h == 0 && W%w == 0 ) return !printf("No\n");
	if( W%w ){
		for(int i = 1; i <= W; i += w){
			for(int j = 1; j <= H; j++) D[j][i] = 1e8-2;
			if( i+w-1 <= W ) for(int j = 1; j <= H; j++) D[j][i+w-1] = -1e8;
		}
	}
	else{
		for(int i = 1; i <= H; i += h){
			for(int j = 1; j <= W; j++) D[i][j] = 1e8-2;
			if( i+h-1 <= H ) for(int j = 1; j <= W; j++) D[i+h-1][j] = -1e8;
		}
	}
	printf("Yes\n");
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++) printf("%d ", D[i][j]);
		printf("\n");
	}
}


Measured memory_bytes: 3712
class SegTreeMin:
    def __init__(self, n):
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [(1 << 31) - 1] * (n2 << 1)
        self.output = []

    def update(self, i, x):
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
            i >>= 1

    def get_min(self, s, t):
        self.output.append(self._get_min(s, t + 1, 1, 0, self.n2))

    def _get_min(self, a, b, k, l, r):
        if r <= a or b <= l:
            return (1 << 31) - 1
        if a <= l and r <= b:
            return self.tree[k]
        m = (l + r) // 2
        return min(
            self._get_min(a, b, k << 1, l, m),
            self._get_min(a, b, (k << 1) + 1, m, r))

    def print(self):
        print('\n'.join(map(str, self.output)))


n, q = map(int, input().split())
st = SegTreeMin(n)
fs = [st.update, st.get_min]
for c, x, y in (map(int, input().split()) for _ in range(q)):
    fs[c](x, y)
st.print()

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

int main(){
	int n,d;
	while(1){
		cin>>n;
		if(n==0) break;
		n/=4;
		int sum=0;
		for(int i=0;i<n;i++){
			cin>>d;
			sum+=d;
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int MOD = 1000000007;

string S;
int dp[100100][15];

int mod_pow(int x, int n, int mod) {
    int res = 1;
    while (n>0) {
        if (n&1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S;
    reverse(S.begin(), S.end());
    dp[0][0] = 1;
    rep(i, S.size()) {
        int p = mod_pow(10, i, 13);
        if (S[i]=='?') {
            rep(j, 10) rep(k, 13) {
                dp[i+1][(j*p+k)%13] += dp[i][k];
                dp[i+1][(j*p+k)%13] %= MOD;
            }
        }
        else {
            int d = S[i]-'0';
            rep(j, 13) {
                dp[i+1][(d*p+j)%13] += dp[i][j];
                dp[i+1][(d*p+j)%13] %= MOD;
            }
        }
    }
    cout << dp[S.size()][5] << endl;
}

Measured memory_bytes: 12240
N = int(input())
h = list(map(int, input().split()))

ans = 0

while True:
  given_water = False
  is_continuous = False
  for i in range(N):
    if h[i] > 0:
      if is_continuous is False:
        ans += 1
        is_continuous = True
      h[i] -= 1
      given_water = True
    else: # h[i] == 0
      is_continuous = False
  if given_water is False:
    break
      
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, a[200005], sum[200005];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum[i] += a[i];
		sum[i + 1] += sum[i];
	}
	int ans = inf;
	REP(i, n) {
		int co = abs(sum[i - 1] - (sum[n] - sum[i - 1]));
		chmin(ans, co);
	}
	cout << ans << endl;
}


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

using namespace std;
using ll = long long;
struct SegmentTree
{
    vector<int> _data;
    int N;
    bool minimum;
    SegmentTree(bool minimum):minimum(minimum){}
    void init_0(int _N){
        N=1;
        while (N < _N)N*=2;
        _data = vector<int>(N*2-1, 0);
    }

    void init_MAX(int _N){
        N=1;
        while (N < _N)N*=2;
        if(minimum)
            _data = vector<int>(N*2-1, INT_MAX);
        else
            _data = vector<int>(N*2-1, INT_MIN);
    }
    void update(int i, int value){
        i += N-1;
        _data[i] = value;
        while (i)
        {
            i = (i-1)/2;
            if (minimum) _data[i] = min(_data[i*2+1], _data[i*2+2]);
            else _data[i] = max(_data[i*2+1], _data[i*2+2]);
        }
    }
    void add(int i, int value){
        i += N-1;
        _data[i] += value;
        while (i)
        {
            i = (i-1)/2;
            _data[i] = _data[i*2+1] + _data[i*2+2];
        }
    }
    void initVector(vector<int> v){
        for (int i = 0; i < v.size(); i++)
            update(i, v[i]);
    }
    int getMin(int left, int right, int l = 0, int r = -1, int k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return INT_MAX;
        if(left<=l&&right>=r)return _data[k];
        int v1=getMin(left,right,l,(l+r)/2,k*2+1);
        int v2=getMin(left,right,(l+r)/2,r,k*2+2);
        return min(v1,v2);
    }
    int getMax(int left, int right, int l = 0, int r = -1, int k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return INT_MIN;
        if(left<=l&&right>=r)return _data[k];
        int v1=getMin(left,right,l,(l+r)/2,k*2+1);
        int v2=getMin(left,right,(l+r)/2,r,k*2+2);
        return max(v1,v2);
    }
    int getSum(int left, int right, int l = 0, int r = -1, int k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return 0;
        if(left<=l&&right>=r)return _data[k];
        int v1=getSum(left,right,l,(l+r)/2,k*2+1);
        int v2=getSum(left,right,(l+r)/2,r,k*2+2);
        return v1 + v2;
    }
};




int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    SegmentTree st = SegmentTree(true);
    st.init_0(n);
    for (int i = 0; i < q; i++)
    {
        bool com;int x, y; cin >> com >> x >> y;
        
        if (com){
            x--; y--;
            cout << st.getSum(x, y+1) << endl;
        }
        else {
            x--;
            st.add(x, y);
        }
    }
    
}


Measured memory_bytes: 3768
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<limits.h>

int main()
{
    int i,j,k,n,b,t,count=0,sum=0 ;
    char ch[43422] , s[1000000];
    scanf("%s",s) ;
    b=strlen(s) ;
    for(i=0 ; i<b ; i++)
    {

        sum=sum+(int)s[i]-48;
    }
   if(sum%9==0)
    printf("Yes") ;
   else
    printf("No") ;
    return 0 ;
}

Measured memory_bytes: 1940
#include <iostream>

using namespace std;

const int MAXN = 20;
int n;

int a[MAXN], x[MAXN][MAXN], y[MAXN][MAXN];

bool satisfy(int v) {
  for (int i=0;i<n;i++) {
    if ((v >> i) & 1) {
      for (int j=0;j<a[i];j++) {
        if (((v >> x[i][j]) & 1) != y[i][j]) {
          return false;
        }
      }
    }
  }
  return true;
}

int count(int v) {
  int cnt = 0;
  for (int i=0;i<n;i++) {
    if ((v >> i) & 1) {
      cnt++;
    }
  }
  return cnt;
}

void solve() {
  int ans = 0;
  for (int i=0;i<1<<n;i++) {
    if (satisfy(i)) {
      ans = max(ans, count(i));
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
    for (int j=0;j<a[i];j++) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  solve();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, x;

ll f(ll p, ll q) {
	if(q==0) return 0;
	if(p==0) return 1;
	ll m = 1LL << p;
	if(q<2*m-1) return f(p-1, q-1);
	return m + f(p-1, q-2*m+1);
}

int main() {
	cin>>n>>x;
	cout<<f(n, x);
	return 0;
}

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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> s(N);
    int total = 0;
    rep(i, N){
        cin >> s[i];
        total += s[i];
    }

    if(total % 10 == 0){
        sort(s.begin(), s.end());
        rep(i, N){
            if(s[i] % 10 != 0){
                cout << total - s[i] << endl;
                return 0;
            }
        }
    }else{
        cout << total << endl;
        return 0;
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,d,ans=0;
    cin>>n>>d;
    ans+=n/(2*d+1);
    if(n%(2*d+1)!=0)
    {
        ans++;
    }
    cout<<ans;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(n==m){
        ll ans=1;
        for(int i=1;i<=m;i++){
            ans*=i;
            ans=ans%1000000007;
        }
        for(int i=1;i<=n;i++){
            ans*=i;
            ans=ans%1000000007;
        }
        ans*=2;
        ans=ans%1000000007;
        cout<<ans<<endl;
    }
    else if(n==m+1 || m==n+1){
        ll ans=1;
        for(int i=1;i<=m;i++){
            ans*=i;
            ans=ans%1000000007;
        }
        for(int i=1;i<=n;i++){
            ans*=i;
            ans=ans%1000000007;
        }
        cout<<ans<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define MOD 1000000007 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 4e5 + 5;


int32_t main() 
{ 
    FAST;
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
    cout<<"Bad";
    else
    cout<<"Good";
}

Measured memory_bytes: 256
/**                                                     **\
 *    created by:   Divianshu Bansal                     *
 *    e-mail id:    god_coder@icloud.com                 *
*                                                        */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>


using namespace std;
using namespace __gnu_pbds;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>new_data_set;
#define MOD 1000000007
#define int long long
#define BIG 998244353
#define pf push_front
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589


int power(int x, int y) {
    int r = 1, z = x;
    while (y) {
        if (y & 1)r *= z;
        z *= z; y = y >> 1;
    }
    return r;
}
int powerm(int x, int y, int p) {
    int r = 1;
    while (y) {
        if (y & 1)r = (r * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return r % p;
}
int modinv(int x, int m) {
    return powerm(x, m - 2, m);
}
int logarithm(int a, int b) {
    int x = 0;
    while (a > 1) {
        x++;
        a /= b;
    }
    return x;
}
int max3(int a, int b, int c) {
    return max(a, max(b, c));
}
int min3(int a, int b, int c) {
    return min(a, min(b, c));
}
int32_t main() {
    fast;
    int x, y;
    cin >> x >> y;
    if (y % 2 == 1) {
        cout << "No";
        return 0;
    }
    int ma = 4 * x;
    int mi = 2 * x;
    if (y < mi || y > ma) {
        cout << "No";
        return 0;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3616
n, y = map(int,raw_input().split())
y/=1000


def g(y,n):
	for a in range(y/10 + 1):
		b,c = f(y - a * 10, n - a)
		if b != -1:
			return [a,b,c]
	return [-1,-1,-1]
def f(y,n):
	if y < 0 or n < 0:
		return [-1,-1]
	if y == 0:
		if n == 0:

			return [0,0]
		return [-1,-1]

	for b in range(y/5 + 1):
		if y - b * 5 == n - b and n - b >= 0:
			return [b,n-b]
	return [-1,-1]

print ' '.join(map(str, g(y,n)))



Measured memory_bytes: 85040
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, q;
    cin >> n >> k >> q;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = INF;
    rep(i, n) {
        int mn = a[i];
        int m = 0;
        vi b, c;
        rep(j, n) {
            if (a[j] < mn) {
                sort(b.begin(), b.end());
                rep(x, m - k + 1) {
                    c.pb(b[x]);
                }
                m = 0;
                b = vi(0);
            } else {
                m++;
                b.pb(a[j]);
            }
        }
        sort(b.begin(), b.end());
        rep(x, m - k + 1) {
            c.pb(b[x]);
        }
        if (q-1 >= sz(c)) continue;
        sort(c.begin(), c.end());
        int mx = c[q-1];
        chmin(ans, mx - mn);
    }
    cout << ans << endl;
}

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

//const int INF=1001001001;
 int a[12][12];
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  int kotae=INT_MAX;
  for(int s=0;s<(1<<n);s++){
    int sum=0;
    vector<int> d(m,0);
    for(int i=0;i<n;i++){
      if(s>>i&1){
        sum+=c[i];
        for(int j=0;j<m;j++){
          d[j]+=a[i][j];
        }
      }
    }
    bool hantei=true;
    for(int j=0;j<m;j++){
      if(d[j]<x){
        hantei=false;
        break;
      }
    }
    if(hantei)kotae=min(kotae,sum);
  }
  if(kotae==INT_MAX){
    cout<<-1<<endl;
  }else{
    cout<<kotae<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 2e9+7
using namespace std;
using pii=pair<int,int>;
using ll=long long int;

ll sum;

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    for(int i=1;i<=n;i++) {
        if(i%3!=0 and i%5!=0) {
            sum+=i;
        }
    }
    cout<<sum<<endl;
}



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

int main()
{
int A;
int B;

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

	cin >> A;
	cin >> B;

	if( A > 8 || B > 8 )
		cout << ":(" << endl;
	else
		cout << "Yay!" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,M,a,b;
bool G[10][10];

int dfs(int now, bool passed[]){
    passed[now]=true;

    bool done=true;
    rep(i,N){
        if(!passed[i])done=false;
    }
    if(done)return 1;

    int ans = 0;

    rep(next,N){
        if(passed[next])continue;
        if(G[now][next]){
            passed[next]=true;
            ans+=dfs(next,passed);
            passed[next]=false;
        }
    }

    return ans;
}

int main(){
    cin>>N>>M;
    rep(i,10){
        rep(j,10)G[i][j]=false;
    }
    rep(i,M){
        cin>>a>>b;
        a--;
        b--;
        G[a][b]=true;
        G[b][a]=true;
    }
    // rep(i,10){
    //     rep(j,10){
    //         cout<<G[i][j];
    //     }
    //     out("");
    // }
    bool aaaa[N];
    rep(i,N)aaaa[i]=false;
    aaaa[0]=true;
    out(dfs(0,aaaa));

    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
vector<int>v[20005];
int ans,k;
void dfs(int node, int par, double val)
{
	if(val>(double)k/2.0)
		ans++;
	for(int i=0;i<v[node].size();i++)
	{
		if(v[node][i]!=par)
		{
			dfs(v[node][i],node,val+1);
		}
	}

}
vector<pi>edges;
int main()
{
	int i,j,x;
	int n;
	sd(n);
	sd(k);
	for(i=1;i<n;i++)
	{
		sd(j);
		sd(x);
		v[j].pb(x);
		v[x].pb(j);
		edges.pb(mp(j,x));
	}
	int val=n+1;
	for(i=1;i<=n;i++)
	{
		ans=0;
		dfs(i,0,0);
		val=min(ans,val);
	}
	for(i=0;i<edges.size();i++)
	{
		ans=0;
		dfs(edges[i].first,edges[i].second,0.5);
		dfs(edges[i].second,edges[i].first,0.5);
		val=min(val,ans);
	}
	printf("%d\n", val);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
        int h,w;
        while(true){
                cin >> h >> w;
                if(h+w==0)
                        break;
                for(int i=0 ; i<h ; i++ ){
                        for(int j=0 ; j<w ; j++ ){
                                cout <<"#";
                        }
                        cout << endl;
                }
                cout << endl;
        }
        return 0;
}

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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main() {
	int q=read();while(q--){
		int a=read(),b=read(),c=read(),d=read();
		int len=max(a,b)/(min(a,b)+1);if(max(a,b)%(min(a,b)+1)!=0)len++;
		//cout<<"maxlen="<<len<<endl;
		int l=0,r=a;
		while(l<r){
			int mid=(l+r+1)>>1;
			//cout<<"checking mid="<<mid<<endl;
			int tb=b-max(0,(mid-1)/len);assert(tb>=0);
			int ta=a-mid;
			int tl=max(ta,tb)/(min(ta,tb)+1);if(max(ta,tb)%(min(ta,tb)+1)!=0)tl++;
			if(tl<=len)l=mid;
			else r=mid-1;
		}
		int x=l+max(0,(l-1)/len);
//		int tb=b-max(0,(l-1)/len);assert(tb>=0);
//		int ta=a-l;
//		int tl=max(ta,tb)/(min(ta,tb)+1);if(max(ta,tb)%(min(ta,tb)+1)!=0)tl++;
//		assert(tl==len);
		for(int i=c;i<=d;++i){
			if(i<=x){
				if(i%(len+1))putchar('A');
				else putchar('B');
			}else{
				if((a+b-i+1)%(len+1))putchar('B');
				else putchar('A');
			}
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
import math
k=int(input())
a=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      if i<=j<=l:
        if i==j==l:
          a=a+i
        elif i==j and j!=l:
          a=a+3*math.gcd(i,l)
        elif i!=j and j==l:
          a=a+3*math.gcd(i,l)
        elif i!=j and j!=l:
          a=a+6*math.gcd(i,math.gcd(j,l))
      else:
        a=a+0
print(a)


Measured memory_bytes: 9208
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e18;
const int maxn = 410;

int dp[maxn][maxn];
int p[maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        p[i] += p[i - 1];
    }
    for (int len = 1; len < n; len++) {
        for (int l = 1; l + len <= n; l++) {
            int r = l + len;
            dp[l][r] = inf;
            for (int j = l; j < r; j++) {
                dp[l][r] = min(dp[l][r], dp[l][j] + dp[j + 1][r]);
            }
            dp[l][r] += p[r] - p[l - 1];
        }
    }
    cout << dp[1][n] << "\n";

    return 0;
}

Measured memory_bytes: 1664
while 1:
	n = input()
	if n == 0: break
	ans = []
	for i in range(n):
		inp = raw_input().split()
		L = inp[0]
		P,A,B,C,D,E,F,S,M = map(int,inp[1:])
		ans.append([L,(M*F*S-P)*1.0/(A+B+C+(D+E)*M)])
	ans = sorted(sorted(ans), key = lambda x:x[1], reverse = True)
	for k,v in ans: print k
	print "#"

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++)
  {
    int buf;
    cin >> buf;
    a[i] = buf - 1;
  }
  for (int i = 0; i < n; i++)
  {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++)
  {
    cin >> c[i];
  }

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


Measured memory_bytes: 3600
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k;
    cin >> k;
    bool v[91][k];
    int inf = 10000000;
    for(int i = 0; i<=90; i++){
        for(int j = 0; j<k; j++){
            v[i][j] = false;
        }
    }
    vector<int> sum;
    vector<int> mod;
    for(int i = 1; i<10; i++){
        if(!v[i][i%k]){
            v[i][i%k] = true;
            sum.push_back(i);
            mod.push_back(i%k);
        }
    }
    for(int i = 0; i<sum.size(); i++){
        for(int j = 0; j<10; j++){
            int ns = sum[i]+j;
            int nm = (mod[i]*10+j)%k;
            if(ns<=90 && !v[ns][nm]){
                v[ns][nm] = true;
                sum.push_back(ns);
                mod.push_back(nm);
            }
        }
    }
    int ans = 100;
    for(int i = 0; i<=90; i++){
        if(v[i][0]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 111380
N, M = map(int, input().split())
ball = [1] * N
red = {1}
ans = 0
for _ in range(M):
    x, y = map(int, input().split())
    ball[x - 1] -= 1
    ball[y - 1] += 1
    if x in red:
        red.add(y)
        if ball[x - 1] == 0:
            red.remove(x)
print(len(red))


Measured memory_bytes: 12652
#include<iostream>
using namespace std;
int main(){
	int n,n1,n2,n3,n4;
	cin>>n;
	int c=0;
	for(int i=0;i<4;i++){
		if(n%10==2)
			c++;
		n/=10;
	}
	cout<<c;
	return 0;
}

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

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 vector<int> dx = { 1, 0 };
const vector<int> dy = { 0, 1 };
const long long INF = 1LL << 60;
int H, W;
vector<string> fi;

long long solve() {
	vector<vector<long long>> dp(H, vector<long long>(W, INF));
	if (fi[0][0] == '#') dp[0][0] = 1;
	else dp[0][0] = 0;

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (int dir = 0; dir < 2; ++dir) {
				int ni = i + dx[dir], nj = j + dy[dir];
				if (ni >= H || nj >= W) continue;
				int add = 0;
				if (fi[ni][nj] == '#' && fi[i][j] == '.') add = 1;
				chmin(dp[ni][nj], dp[i][j] + add);
			}
		}
	}
	return dp[H - 1][W - 1];
}

int main() {
	cin >> H >> W;
	fi.resize(H);
	for (int i = 0; i < H; ++i) cin >> fi[i];
	cout << solve() << endl;
}

Measured memory_bytes: 384
#include <iostream>
 
int main(void)
{
  int N;
  std::cin >> N;
  char S[N];
  for(int i=0;i<N;i++)
  {
    std::cin >> S[i];
  }
  int a=0;
  for(int i=0;i<N;i++)
  {
    if(S[i] == 'Y'){
   		a=1;
    }
    
  }
  
  if(a==1)
  {
    std::cout << "Four" << std::endl;
  }
  else{
 	std::cout << "Three" << std::endl;
  }
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

void print(vector<vector<int>>& p, int h, int w) {
  rep(i, h+1) {
    rep(j, w+1) {
      cout << p[i][j] << " ";
    }
    END;
  }
}

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    string p;
    cin >> p;
    s[i] = p;
  }

  vector<vector<int>> left(h+1, vector<int>(w+1, 0)), right(h+1, vector<int>(w+1, 0)), low(h+1, vector<int>(w+1, 0)), high(h+1, vector<int>(w+1, 0));

  rep(i, h) {

    for (int j = 1; j <= w; ++j) {
      if (s[i][j-1] == '#') {
        
        continue;
      }
      left[i][j] += left[i][j-1] + 1;
    }
    
    for (int j = w-1; j >= 0; --j) {
      if (s[i][j] == '#') {
        
        continue;
      }
      right[i][j] += right[i][j+1] + 1;
    }
  }

  rep(i, w) {
    for (int j = 1; j <= h; ++j) {
      if (s[j-1][i] == '#') {
        continue;
      }
      low[j][i] += low[j-1][i] + 1;
    }
    
    for (int j = h-1; j >= 0; --j) {
      if (s[j][i] == '#') {
        continue;
      }
      high[j][i] += high[j+1][i] + 1;
    }
  }/*
  print(left, h, w); END;
  print(right, h, w); END;
  print(low, h, w); END;
  print(high, h, w); END;*/
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '#') continue;
      int tt = i+1, pp = j+1;
      ans = max<ll>(ans, left[i][j] + right[i][j] + low[i][j] + high[i][j] - 1);
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 67200
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vi r(R);
    vii G(N, vi(N, inf));
    rep(i, 0, R){
        cin >> r[i];
        r[i]--;
    }
    rep(i, 0, M){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a][b] = c;
        G[b][a] = c;
    }
    rep(k, 0, N){
        rep(i, 0, N){
            rep(j, 0, N){
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    vll dp(1<<(R+1), vl(R, INF));
    rep(j, 0, R) dp[0][j] = 0;
    rep(i, 0, R){
        dp[1 << i][i] = 0;
    }
    rep(i, 0, 1 << R){
        rep(j, 0, R){
            if(1 && (i >> j)){
                int prev_i = i ^ (1 << j);
                rep(k, 0, R){
                    if(1 && (prev_i >> k)){
                        int r1 = r[k];
                        int r2 = r[j];
                        /* DEBUG(r1); */
                        /* DEBUG(r2); */
                        /* DEBUG(dp[i][j]); */
                        dp[i][j] = min(dp[i][j], dp[prev_i][k] + G[r1][r2]);
                    }
                }
            }
        }
    }
    ll ans = INF;
    rep(j, 0, R){
        ans = min(ans, dp[(1<<R) - 1][j]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1020
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <math.h>
#include <bitset>
#include <queue>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> nums(n);
    for(int i = 0; i < n; i++){
        cin >> nums[i];
    }

    int count = 1;
    int minNum = nums[0];
    for(int i = 1; i < n; i++){
        if(minNum > nums[i]){
            count++;
            minNum = nums[i];
            if(minNum == 1){
                break;
            }
        }
    }

    cout << count;

}

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

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
B = [0 for i in range(N)]
A = [False for i in range(N)]
for m in range(M):
  p,S=input().split()
  p = int(p)
  if S=="WA":
    if not A[p-1]:
      B[p-1] += 1
  else:
    A[p-1] = True
c = 0
for a,b in zip(A,B):
  if a:
    c+=b

print(sum(A),c)

Measured memory_bytes: 47280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define fast                            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int                             long long
#define ff                              first
#define ss                              second
#define max3(a,b,c)                     max(a,max(b,c))
#define min3(a,b,c)                     min(a,min(b,c))
#define setbits(x)                      __builtin_popcountll(x)
#define zerobits(x)                      __builtin_ctzll(x)
#define pb                              push_back
#define mkp                             make_pair
#define all(v)                          (v).begin(),(v).end()
#define pii                             pair<int, int>
#define vi                              vector<int>
#define vpi                             vector<pair<int,int>>
#define rev(x)                          reverse(all(x))
#define gcd(m,n)                        __gcd(m, n)
#define negmod(x,m)                     ((x)%(m)+(m))%(m)
#define fr(i, a, b)                     for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n)                       for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n)                      for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b)                    for (int i = (a), _b = (b); i >= _b; i--)
#define M                               1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ull countBits(ull n){ull count=0;while(n){count++;n>>=1;}return count;}
int updiv(int a,int b)
{
  if(a%b==0)
    return (a/b);
  else
    return (a/b)+1;
}
int mymod(int x,int m)
{
  if(x>0)
    return x%m;
  else
    return negmod(x,m);
}
int binpow(int a, int b)
{
    int res = 1;
    while(b>0)
    {
        if(b&1)
        res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.ff=lhs.ss;
    a.ss=lhs.ff;
    b.ff=rhs.ss;
    b.ss=rhs.ff;
    return a<b;
}
int32_t main()
{
fast
int t=1,n,k;
//cin>>t;
while(t--)
{
cin>>n>>k;
int h[n+1]={0};
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
int dp[n+1]={0};
rep(i,n+1)
dp[i]=LLONG_MAX;
dp[1]=0;
dp[0]=0;
dp[2]=abs(h[2]-h[1]);
for(int i=3;i<=n;i++)
{
    for(int j=1;j<=k;j++)
    {
        if(i-j<1)
            break;
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));

    }
}
cout<<dp[n]<<"\n";
}
return 0;
}


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

int main(void){
  long long n, m;
  cin >> n >> m;
  if(n == 2 || m == 2){
    cout << 0 << endl;
    return 0;
  }
  if(n == 1 || m == 1){
    cout << abs(max(n, m) - 2) << endl;
      return 0;
  }
  if(n >= 3 && m >= 3){
    cout << (n - 2) * (m - 2) << endl;
    return 0;
  }
  return 0;
}


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

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            int r=sc.nextInt();
            if(n==0 && r==0) break;
            int[] card=new int[n];
            for(int i=0;i<n;i++) card[i]=i;
            for(int i=0;i<r;i++){
                int p=sc.nextInt();
                int c=sc.nextInt();
                int[] newcard=new int[n];
                for(int j=0;j<n-p-c+1;j++) newcard[j]=card[j];
                for(int j=n-p-c+1;j<n-c;j++) newcard[j]=card[c+j];
                for(int j=n-c;j<n;j++) newcard[j]=card[j-p+1];
                card=newcard;
            }
            System.out.println(card[n-1]+1);
        }
    }
}


Measured memory_bytes: 36940
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;

int S[1000];
int top = 0;

void push(int x){
	S[top+1] = x;
	top++;
}

int pop() {
	top--;
	return S[top+1];
}

bool isFull() {
	if(top==999)
		return true;
	else
		return false;
}

bool isEmpty() {
	if(top==0)
		return true;
	else
		return false;
}

int main() {
	char symbol[100];
	for( ;scanf("%s",symbol) != EOF; ) {
		if(*symbol == '+') {
			int a = pop();
			int b = pop();
			push(a+b);
		} else if(*symbol == '-') {
			int a = pop();
			int b = pop();
			push(b-a);
		} else if(*symbol == '*') {
			int a = pop();
			int b = pop();
			push(a*b);
		} else {
			push(atoi(symbol));
		}
	}
	printf("%d\n",pop());
}




Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            String S = in.next();
            int o = 0;
            int x = 0;
            int k = S.length();
            for (int i = 0; i < k; i++) {
                char charAt = S.charAt(i);
                if (charAt == 'o') {
                    o++;
                }
                if (charAt == 'x') {
                    x++;
                }
            }
            System.out.println(x >= 8 ? "NO" : "YES");
        }
    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005,mod=19260817;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(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;}

int main()
{
	ll h;cin>>h;
	if(h==0)cout<<"0";
	else
	{
		for(int i=0;i<=41;i++)
		{
			if(pow(2,i,90000000000005)>h)
			{
				cout<<pow(2,i,90000000000005)-1;break;
			}
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int num;
int main(){
	cin>>s>>t;
	int n=s.length();
	for(int i=0;i<=n;i++){
		if(s[i]!=t[i]){
			num++;
		}
	}
	cout<<num<<endl;
}

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

int main(void)
{
    int i = 1, x;

    while (1)
    {
        cin >> x;
        if (x == 0) break;

        cout << "Case " << i << ": " << x << endl;
        ++i;
    }
}



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

int main(){
    int n;
    string s;
    cin>>n>>s;
    
    ll cnt_r=0;
    ll cnt_g=0;
    ll cnt_b=0;
    
    for(int i=0;i<n;i++){
        if(s[i]=='R') cnt_r++;
        if(s[i]=='G') cnt_g++;
        if(s[i]=='B') cnt_b++;
    }
    
    ll ans=cnt_r*cnt_g*cnt_b;
    
    for(int d=1;d<=n;d++){
        for(int m=0;m<n;m++){
            if(m-d<0||m+d>=n) continue;
            
            if(s[m-d]!=s[m+d]&&s[m]!=s[m+d]&&s[m-d]!=s[m]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int64_t a, b, n; cin >> a >> b >> n;
    int64_t c;
    if (n < b-1) {
        c = (a * n) / b;
    } else {
        c = (a * (b-1)) / b;
    }
    cout << c << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int d = max(a,max(b,c));
    rep(i,k)d*=2;
    cout << a+b+c+d-max(a,max(b,c));
    return 0;
}

Measured memory_bytes: 3628
n = gets.to_i
x = gets.split.map(&:to_i)
xs = x.sort

bSmall = xs[n/2-1]
bBig = xs[n/2]
x.each do |i|
  if i <= bSmall
    printf("%d\n",bBig)
  else
    printf("%d\n",bSmall)
  end
end

Measured memory_bytes: 23396
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9;
signed main() {
	int H,W;
    cin >> H >> W;
    vector<string>S(H);
    int cnt = 0;
    for(int i = 0; i < H; i++) {
        cin >> S[i];
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '#') {
                cnt++;
            }
        }
    }
    if(cnt == H+W-1) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const long long MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int main () {

    ll n,a,b;cin>>n>>a>>b;

    ll p = (ll)(n/(ll)(a+b));

    if (n<a+b) {
        if (n>a) {
            cout<<a<<endl;
            return 0;
        } else {
            cout<<n<<endl;
            return 0;
        }
    }

    ll ans;
    if (n-(ll)(p*(a+b))>a) {
        ans=(p+1)*a;
    } else {
        ans = (ll)p*a+ n-(ll)(p*(a+b));
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
H,W,K = map(int,input().split())
S = [input() for i in range(H)]

ans = H+W+9999
for b in range(1<<(H-1)):
    mp = [0]
    k = 0
    for i in range(H-1):
        if b&(1<<i):
            k += 1
        mp.append(k)
    tmp = bin(b).count('1')
    ws = [0] * H
    muri = False
    for col in zip(*S):
        for i,c in enumerate(col):
            if c == '1':
                ws[mp[i]] += 1
        if any(w > K for w in ws):
            ws = [0] * len(mp)
            for i,c in enumerate(col):
                if c == '1':
                    ws[mp[i]] += 1
            if any(w > K for w in ws):
                muri = True
                break
            tmp += 1
        if muri:
            break
    if not muri:
        ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9248
N = int(input())
A = list(input())

W=[]
R=[]

for a_idx,a in enumerate(A):
    if a == 'W':
        W.append(a_idx)
    else:
        R.append(a_idx)
        
W.sort()
R.sort(reverse=True)


ans=0
for n in range(min(len(W),len(R))):
    if W[n] > R[n]:
        break
    ans+=1
    
print(ans)

Measured memory_bytes: 95884
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}



const int N=15,M=1005;
int ans=1e9,b[N],a[N][M],n,m,s,cnt[N];


bool check(){
	for(int l=1,r;l<=n;l=r+1){
		r=l;
		while(r+1<=n&&!b[r+1]) r++;
		for(int j=1;j<=m;j++){
			int cnt=0;
			for(int i=l;i<=r;i++) cnt+=a[i][j];
			if(cnt>s) return 0;
		}
	}
	return 1;
}

bool add(int x){
	for(int l=1,r,id=1;l<=n;l=r+1,id++){
		r=l;
		while(r+1<=n&&!b[r+1]) r++;
		for(int i=l;i<=r;i++) cnt[id]+=a[i][x];
		if(cnt[id]>s) return 0;
	}
	return 1;
}

signed main(){
	read(n);read(m);read(s);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) scanf("%1d",&a[i][j]);
	int tot=1<<n-1;
	for(int i=0;i<tot;i++){
		int si=i<<2,id=1,cur=0;
		for(int j=2;j<=n;j++) b[j]=si>>j&1,id+=b[j];
		if(!check()) continue;
		for(int l=1,r;l<=m;l=r+1){
			r=l-1;
			cur++;
			while(r+1<=m&&add(r+1)) r++;
			for(int i=1;i<=id;i++) cnt[i]=0;
		}
		ans=min(ans,cur+id-2);
	}
	write(ans);
}

Measured memory_bytes: 256
// Recursive C program for 
// coin change problem. 
// C++ program for coin change problem. 
#include<bits/stdc++.h> 

using namespace std; 

int count( int S[], int m, int n ) 
{ 
	int i, j, x, y; 

	// We need n+1 rows as the table 
	// is constructed in bottom up 
	// manner using the base case 0 
	// value case (n = 0) 
	int table[n + 1][m]; 
	
	// Fill the enteries for 0 
	// value case (n = 0) 
	for (i = 0; i < m; i++) 
		table[0][i] = 1; 

	// Fill rest of the table entries 
	// in bottom up manner 
	for (i = 1; i < n + 1; i++) 
	{ 
		for (j = 0; j < m; j++) 
		{ 
			// Count of solutions including S[j] 
			x = (i-S[j] >= 0) ? table[i - S[j]][j] : 0; 

			// Count of solutions excluding S[j] 
			y = (j >= 1) ? table[i][j - 1] : 0; 

			// total count 
			table[i][j] = x + y; 
		} 
	} 
	return table[n][m - 1]; 
} 

// Driver Code 

// This code is contributed 
// by Akanksha Rai(Abby_akku) 

// Driver program to test above function 
int main() 
{ 
	int i, j; 
	int arr[3];
  	cin>>arr[0]>>arr[1]>>arr[2]>>j;
	int m = sizeof(arr)/sizeof(arr[0]); 
	printf("%d", count(arr, m, j)); 
	getchar(); 
	return 0; 
} 


Measured memory_bytes: 256
def cmb(n,r):
    if n==0 or r==0:
        return 1
    else:
        ans=1
        for i in range(1,min(r,n-r)+1):
            ans=ans*(n-i+1)//i
        return ans

n,p=map(int,input().split())
a=list(map(int,input().split()))
buf=0
for i in range(n):
    if a[i]%2==1:
        buf+=1
ans=0
if p==0:
    for i in range(buf//2+1):
        ans+=cmb(buf,2*i)
    ans*=2**(n-buf)
    print(ans)
else:
    for i in range((buf+1)//2):
        ans+=cmb(buf,2*i+1)
    ans*=2**(n-buf)
    print(ans)

Measured memory_bytes: 3064
import math
 
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct
 
n = int(input())
mod = 10 ** 9 + 7
 
l = [0] * (n + 1)
 
for i in range(1, n + 1):
  soi = factorize(i)
  for j in range(len(soi)):
    l[soi[j][0]] += soi[j][1]
 
ans = 1
for i in range(1, n + 1):
  ans = ans * (l[i] + 1) % mod
 
print(ans)

Measured memory_bytes: 41692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    string s;cin>>s;
    int n=s.size();
    int res=n;
    stack<int> st;
    REP(i,n){
        if(s[i]=='S')st.push(1);
        if(!st.empty() && s[i]=='T'){
            st.pop();
            res-=2;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[1000009],ff[1000009],i,j,cnt[4],fct[1000009],pas;
string s;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	cin>>s;
	for(i=1; i<=a; i++) ff[i]=s[i-1]-'0';
	for(i=1; i<a; i++) f[i]=abs(ff[i]-ff[i+1]);
	a--;
	if(a==1){
		cout<<f[1];
		return 0;
	}
	for(i=1; i<=a; i++){
		cnt[f[i]]++;
	}
	if(cnt[1]==0){
		for(i=1; i<=a; i++){
		if(f[i]==2) f[i]=1;
	}
	fct[0]=0;fct[1]=0;
	for(i=2; i<=a; i++){
		fct[i]=i/2+fct[i/2];
	}
	for(i=1; i<=a; i++){
		if(fct[a-1]>fct[i-1]+fct[a-i]){
			
		}else{
			pas+=f[i];
		}
	}
	if(pas%2==0) cout<<0; else cout<<2;
		return 0;
	}
	for(i=1; i<=a; i++){
		if(f[i]==2) f[i]=0;
	}
	fct[0]=0;fct[1]=0;
	for(i=2; i<=a; i++){
		fct[i]=i/2+fct[i/2];
	}
	for(i=1; i<=a; i++){
		if(fct[a-1]>fct[i-1]+fct[a-i]){
			
		}else{
			pas+=f[i];
		}
	}
	cout<<pas%2;
	return 0;
}

Measured memory_bytes: 24860