akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  int x;
  cin>>x;
  int ans = 1;
  for(int i = 2; i <= sqrt(x); i++){
    int j = i;
    int c = 0;
    while(1){
      if(j*i>x){
        if(c>0)
        ans = max(ans,j);
        break;
      }
      else {
        j*=i;
        c++;
        }
    }
  }
  cout<<ans<<endl;
  return 0;
}




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

int main(){
    int h, w, l;
    vector<vector <int>> a;
    vector<int> y, x, yp, xp;
    cin >> h >> w;
    a.resize(h);
    for(int i=0; i<h; ++i){
        a[i].resize(w);
        for (int j=0; j<w; ++j){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(a[i][j] % 2 == 1){
                if(j+1 < w && a[i][j+1] % 2 == 1){
                    a[i][j]--;
                    a[i][j+1]++;
                    y.push_back(i+1);
                    x.push_back(j+1);
                    yp.push_back(i+1);
                    xp.push_back(j+2);
                    //cout << i+1 << " " << j+1 << " " << i+1 << " " << j+2 << endl;
                }
                else if(i+1 < h && a[i+1][j] != 0 && a[i+1][j] % 2 == 1){
                    a[i][j]--;
                    a[i+1][j]++;
                    y.push_back(i+1);
                    x.push_back(j+1);
                    yp.push_back(i+2);
                    xp.push_back(j+1);
                    //cout << i+1 << " " << j+1 << " " << i+2 << " " << j+1 << endl;
                }
                else if(j+1 < w){
                    a[i][j]--;
                    a[i][j+1]++;
                    y.push_back(i+1);
                    x.push_back(j+1);
                    yp.push_back(i+1);
                    xp.push_back(j+2);
                }
                else if(i+1 < h){
                    a[i][j]--;
                    a[i+1][j]++;
                    y.push_back(i+1);
                    x.push_back(j+1);
                    yp.push_back(i+2);
                    xp.push_back(j+1);
                }
            }
        }
    }
    l = y.size();
    cout << l << endl;
    for(int i=0; i<l; ++i){
        cout << y[i] << " " << x[i] << " " << yp[i] << " " << xp[i] << endl;
    }
}



Measured memory_bytes: 5220
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int solve(int n) {
  int t[10]   = {100, 112, 223, 334, 445, 556, 667, 778, 889, 1000};
  int ans[9] = {111, 222, 333, 444, 555, 666, 777, 888, 999};
  for (int i = 0; i < 9; ++i) {
    if (n >= t[i] && n < t[i + 1]) {
      return ans[i];
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  cout << solve(n) << endl;
}


Measured memory_bytes: 256
from itertools import product
N = int(input())
ans = 0
if N <= 2:
  print(0)
  exit()
  
for i in range(3, len(str(N))+1):
  for num in list(product('735',repeat=i)):
    if int(''.join(num)) <= N and '7' in num and '5' in num and '3' in num:
      ans += 1
print(ans)

Measured memory_bytes: 46444
def main29():
    S = input()
    count = 0
    start = False
    tmp = 0
    W_count = 0

    for i in range(len(S)):
        if S[i] == "W":
            if not start and i > 0:
                if S[i-1] == "B":
                    count += i - W_count
                    tmp = i
                    start = True
            else:
                count += i - W_count
                tmp = i
            W_count += 1

    print(count)

main29()

Measured memory_bytes: 3500
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	string S;
	cin >> S;

	ll ans = 0;

	vint N(4);
	for (int i = 0; i < 4; i++) {
		N[i] = int(S[i]) - 48;
	}

	for (int bit = 0; bit < 1 << 3; bit++) {

		int sum = N[0];

		for (int i = 0; i < 3; i++) {

			if (bit >> i & 1) {
				sum += N[i + 1];
			}
			else {
				sum -= N[i + 1];
			}


		}

		if (sum == 7) {
			cout << N[0];
			for (int i = 0; i < 3; i++) {
				if (bit >> i & 1) {
					cout << "+";
				}
				else {
					cout << "-";
				}
				cout << N[i + 1];
			}

			cout << "=7";
			return 0;
		}


	}





}



Measured memory_bytes: 256
function main()
  
  (N,M) = map(x -> parse(Int,x), split(readline()))
  L = zeros(Int,M)
  R = zeros(Int,M)
  
  for i in 1:M
    (L[i],R[i]) = map(x -> parse(Int,x), split(readline()))
  end
  
  if minimum(R)-maximum(L)+1 > 0
    println(minimum(R)-maximum(L)+1)
  else
    println(0)
  end
  
end

main()

Measured memory_bytes: 170380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


/*
操作1は連続する2整数を、操作2はひとつ飛ばしの2整数を逆順にする
本来の位置とずれている距離が奇数なら1を足す

51234
21435

*/

void solve(){
    int n;
    cin >> n;
    int a[n+10];
    int b[n+10];
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b,b+n);
    unordered_map<int,int> um;
    //各値が何番目に小さい値かを保持する
    rep(i,n){
        um.emplace(b[i],i);
    }
    int dist = 0;
    rep(i,n){
        //cout << "a[i]:" << a[i] << " um[a[i]]:" << um[a[i]] << " i:" << i << endl;
        dist += (abs(um[a[i]] - i)%2);
    }
    //cout << dist << endl;

    /*
    sort(a,a+n, greater<int>());
    unordered_map<int,int> um2;
    //各値が何番目に小さい値かを保持する
    rep(i,n){
        um2.emplace(b[i],i);
    }
    int dist2 = 0;
    rep(i,n){
        dist2 += (abs(um2[a[i]] - i)%2);
    }
    

    cout << min(dist,dist2)/2 << endl;
    */
    cout << dist/2 << endl;


}

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



Measured memory_bytes: 5156
import sys
s=input()
n=len(s)
for i in range(n//2):
  if s[i]!=s[n-1-i]:
    print('No')
    sys.exit()
for i in range(n//4):
  if s[i]!=s[n//2-1-i]:
    print('No')
    sys.exit()
  if s[n//2+1+i]!=s[n-1-i]:
    print('No')
    sys.exit()
print('Yes')

Measured memory_bytes: 38384
N=int(input())
A=list(map(int,input().split()))
t=0
hunokazu=0
while t<N:
    if A[t]<0:
        hunokazu=hunokazu+1
    t=t+1
q=[]
qq=0
while qq<N:
    if A[qq]>=0:
        q.append(A[qq])
    else:
        q.append(A[qq]*(-1))
    qq=qq+1
if hunokazu%2==0:
    k=0
    ans=0
    while k<N:
        ans=ans+q[k]
        k=k+1
else:
    k=0
    ans=0
    while k<N:
        ans=ans+q[k]
        k=k+1
    ans=ans-min(q)*2
print(ans)

Measured memory_bytes: 14496
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

// l以下にするには何回切る必要があるか
int caclnum(int *a, int n, int l)
{
    int ans = 0;
    rep(i, n)
    {
        int t = (a[i] - 1) / l + 1;
        if( t > 1 ) ans += ( t - 1 );
    }
    return ans;
}

int main()
{
    int n, k;
    cin >> n >> k;
    int *a = new int[n];
    rep(i, n) cin >> a[i];
    int b = 0;
    int s = 1;
    rep(i, n)
    {
        b = max(b, a[i]);
    }

    while(s < b)
    {
        int m = s + (b - s) / 2;
        int t = caclnum(a, n, m);
        if( t > k )
        {
            s = m + 1;
        }
        else
        {
            b = m;
        }
    }
    cout << s;

    return 0;    
}

Measured memory_bytes: 4356
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int m, n;
bool tront[90][90];

int dfs(int y, int x) {
	int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
	int rep = 0;

	tront[y][x] = false;
	REP(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (! (nx >= 0 && nx < m && ny >= 0 && ny < n)) continue;
		if (! tront[ny][nx]) continue;
		tront[ny][nx] = false;
		rep = max(rep, dfs(ny, nx));
		tront[ny][nx] = true;
	}
	tront[y][x] = true;
	return rep + 1;
}


int main() {
	while (true) {
		int ans = 0;
		cin >> m >> n;
		if (n == 0 && m == 0) break;
		REP(i, n) REP(j, m) cin >> tront[i][j];

		REP(i, n) REP(j, m) if (tront[i][j])
			ans = max(ans, dfs(i, j));

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int count = 0;
char N[100000];
#define SENTINEL 1000000001
int Partition(int *A, char *C, int f, int l){
  int i, j, x;
  char c;
  i = f-1;
  for(j = f; j < l; j++){
    if(A[j] <= A[l]){
      i = i+1;
      x = A[j];
      A[j] = A[i];
      A[i] = x;

      c = C[j];
      C[j] = C[i];
      C[i] = c;
    }
  }
    x = A[i+1];
    A[i+1] = A[l];
    A[l] = x;

    c = C[i+1];
    C[i+1] = C[l];
    C[l] = c;

  return i+1;
}

void Quicksort(int *A, char *C, int f, int l){
  int q;
  if(f < l){
    q = Partition(A,C,f,l);
    Quicksort(A,C,f,q-1);
    Quicksort(A,C,q+1,l);
  }
}
void Merge(int *B, char *D,int left,int mid,int right){
  int n1, n2, i, j, k, *L, *R;
  char *RC, *LC;
  n1 = mid - left;
  n2 = right - mid;
  L = malloc(sizeof(int)*(n1+1));
  R = malloc(sizeof(int)*(n2+1));
  LC = malloc(sizeof(char)*(n1+1));
  RC = malloc(sizeof(char)*(n2+1));
  for(i = 0; i < n1; i++){
    L[i] = B[left + i];
    LC[i] = D[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = B[mid + i];
    RC[i] = D[mid + i];
  }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  LC[n1] = '\0';
  RC[n2] = '\0';
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      B[k] = L[i];
      D[k] = LC[i];
      i = i + 1;
      count++;
    }
    else{
      B[k] = R[j];
      D[k] = RC[j];
      j = j + 1;
      count++;
    }
  }
}

void Merge_Sort(int *B,char *D,int left,int right){
  int mid, i;
  if(left+1 < right){
    mid = (left + right)/2;
    Merge_Sort(B,D,left, mid);
    Merge_Sort(B,D,mid, right);
    Merge(B,D,left, mid, right);
  }
}
int main(){
  int i, n, *A, *B;
  char *C, *D;
  scanf("%d",&n);
  A = malloc(sizeof(int)*n);
  B = malloc(sizeof(int)*n);
  C = malloc(sizeof(char)*n);
  D = malloc(sizeof(char)*n);
  for(i = 0; i < n; i++){
    scanf(" %c%d",&C[i], &A[i]);
    B[i] = A[i];
    D[i] = C[i];
  }

  Quicksort(A,C,0,n-1);
  Merge_Sort(B,D,0,n);

  if(strcmp(C,D)== 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  
  return 0;
}

Measured memory_bytes: 20228
div = int(1e9 + 7)
n, m = map(int, input().split())
tx, ty = 0, 0
coe_x, coe_y = 1 - n, 1 - m
for x in map(int, input().split()):
    tx = (tx + x * coe_x) % div
    coe_x += 2
for y in map(int, input().split()):
    ty = (ty + y * coe_y) % div
    coe_y += 2
print(tx * ty % div)


Measured memory_bytes: 12412
/*input
999983
*/

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 4;

char s[N];
int cnt[2];

int64_t sqr(int x) {
  return (int64_t)x * x;
}

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

  int k; cin >> k;
  int m = 0, b = 10 % k, c = 7 % k;
  for (int i = 0; i < k; ++i) {
    m = (b * m + c) % k;
    if (m > 0) continue;
    cout << i + 1;
    return 0;
  }
  cout << -1;

  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
char  ta[50][50],tb[50][50];
	int n,h,w;
	bool used[50][50],can[50][50];
	bool ok(){

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
			tb[i][j]=ta[i][j];
			}
		}
		
		int cnt=0;
		char tmp;
		bool endf=0;
		for(int cc=0;cc<300;cc++){
			endf=0;
			for(int i=0;i<50;i++)for(int j=0;j<50;j++)used[i][j]=0,can[i][j]=0;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(tb[i][j]!='.')can[i][j]=1;
				//
			for(int i=h-1;i>=0;i--){
				for(int j=w-1;j>=0;j--){
					int ni=i;
					if(tb[i][j]!='.'){
						while(1){
							if(ni+1>=h||tb[ni+1][j]!='.'||can[i][j]==0)break;
							tb[ni+1][j]=tb[ni][j];
							tb[ni][j]='.';
							ni++;
						}
					}
				}
			}
			//if(cc==0)for(int i=0;i<h;i++){for(int j=0;j<w;j++){cout<<tb[i][j];}cout<<endl;}
		
		
		

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cnt=0;
				tmp=tb[i][j];
					while(j<w&&tb[i][j+cnt]==tmp&&tmp!='.')cnt++;
				if(cnt>=n){
					for(int nj=j;nj<j+cnt;nj++)used[i][nj]=1,endf=1;
				}
			}
		}
		
			for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cnt=0;
				tmp=tb[i][j];
					while(i<h&&tb[i+cnt][j]==tmp&&tmp!='.')cnt++;
				if(cnt>=n){
					for(int ni=i;ni<i+cnt;ni++)used[ni][j]=1,endf=1;
				}
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(used[i][j])tb[i][j]='.';
			}
		}
			if(endf==0)break;
		}
		bool nf=1;
		//for(int i=0;i<h;i++){for(int j=0;j<w;j++){cout<<tb[i][j];}cout<<endl;}
		//cout<<endl;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(tb[i][j]!='.')nf=0;
		return nf;
	}
int main(){

	cin>>h>>w>>n;
	
	bool f=0;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>ta[i][j];

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int ii=0;ii<h;ii++)for(int jj=0;jj<w;jj++)can[ii][jj]=0;
			//cout<<i<<" "<<j<<endl;
			/*if(i+1<h){
				swap(ta[i][j],ta[i+1][j]);
				can[i][j]=can[i+1][j]=1;
				if(ok())f=1;
				swap(ta[i][j],ta[i+1][j]);
			}*/
			for(int ii=0;ii<h;ii++)for(int jj=0;jj<w;jj++)can[ii][jj]=0;
			if(j+1<w){
				swap(ta[i][j],ta[i][j+1]);
				if(ok())f=1;
				swap(ta[i][j],ta[i][j+1]);
			}
		}
	}
	if(f)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

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


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9



class BIT{
    public:
        vector<ll> bit_;
        ll N_;
        BIT(ll size){
            N_ = size;
            bit_.assign(N_+1,0);
        }

        ll sum(ll i){
            ll s = 0;
            while(i > 0){
                s+= bit_[i];
                i -= i&-i;
            }
            return s;
        }

        void add(ll i, ll x){
            while(i <=N_){
                bit_[i] += x;
                i += i&-i;
            }
        }
};


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N; cin >> N;

    vector<int> A(N);

    int left = 1e9+7;
    int right = -1;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        left = min(left, A[i]);
        right = max(right, A[i]);
    }
    right++;


    int offset = N+1;
    ll border = ((N * (N + 1))/2 + 1) /2;

    while(right-left > 1){
        BIT bit(2 * N + 1);
        int mid = (left + right)/2;
        int sum = 0;
        bit.add(sum+offset, 1);
        ll result = 0;
        for(int i = 0; i < N; i++){
            if(A[i] >= mid) sum++;
            else sum--;
            result += bit.sum(sum+offset);
            bit.add(sum+offset, 1);
        }
        if(result >= border) left = mid;
        else right = mid;
    }

    cout << left << endl;

    return 0;
}


Measured memory_bytes: 2276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int P[200005];

int main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> P[i];
		P[i]--;
	}

	vector< pair<int, int> > T(N, pair<int, int>(0, 0));
	
	for (int i = N - 1; i >= 0; --i)
	{
		int n = P[i];
		if (n == N - 1 || T[n + 1].first < i)
		{
			T[n] = pair<int, int>(i, 1);
			continue;
		}
		T[n] = pair<int, int>(i, T[n + 1].second + 1);
	}

	int m = 0;
	REP(i, N)
	{
		m = std::max(m, T[i].second);
	}
	cout << N - m << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int b[n+1];
	for(int i=1;i<=n;i++)
	{
		b[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		int a;
		cin>>a;
		b[a]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<b[i]<<endl;
	}
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 2e5 + 5;
int a[N][65];
int n, k;
void solve() {  
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i][0];
    }
    for (int pw = 1; pw <= 60; ++pw) {
        for (int i = 1; i <= n; ++i) {
            a[i][pw] = a[a[i][pw - 1]][pw - 1];
        }
    }
    int cur = 1;
    for (int bit = 60; bit >= 0; --bit) {
        if ((1ll << bit) & k)
            cur = a[cur][bit];
    }
    cout << cur;
}       
    

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

int main(){

int D;
long long G;
cin >> D >> G;

vector<long long>p(D), c(D);
for(int i = 0; i < D; i++){ 
     cin >> p[i] >> c[i];
}

long long cnt = 10000;

for(int i = 0; i < (1 << D); i++){ 
         long long sum = 0;
         long long cnt2 = 0;
         for(int j = 0; j < D; j++){ 
            if(i & (1 << j)) {
                sum += 100 * (j + 1) * p[j] + c[j];
                cnt2 += p[j];
            }  
                 } 

         if(sum >= G) cnt = min(cnt, cnt2);
         else{
             for(int k = D - 1; k >= 0; k--){ 
                  if(i & (1 << k)) continue;
                  for(int l = 0; l < p[k]; l++){ 
                       if(sum >= G) break;
                       sum += 100 * (k + 1);
                       cnt2++;
                  }             
             }
         if(sum >= G) cnt = min(cnt, cnt2);
         }
}

cout << cnt << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int C;
int D;
int E;
int F;
int w[31];
int s[3001];
int main(){
  int i, res1, res2;
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  rd(E);
  rd(F);
  w[0] = s[0] = 1;
  for(i=(A);i<(31);i++){
    w[i] |= w[i-A];
  }
  for(i=(B);i<(31);i++){
    w[i] |= w[i-B];
  }
  for(i=(C);i<(3001);i++){
    s[i] |= s[i-C];
  }
  for(i=(D);i<(3001);i++){
    s[i] |= s[i-D];
  }
  res1 = 100*A;
  res2 = 0;
  for(i=0;i<(31);i++){
    if(w[i]){
      int j;
      for(j=0;j<(3001);j++){
        if(s[j]){
          if(100*i + j > F){
            break;
          }
          if(i*E < j){
            break;
          }
          if(j * (res1+res2) > res2 * (100*i+j)){
            res1 = 100*i;
            res2 = j;
          }
        }
      }
    }
  }
  wt_L(res1+res2);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int A, B, C, D, E, F;
// int w[31], s[3001];
// {
//   int i;
//   int res1, res2;
//   
//   rd(A,B,C,D,E,F);
//   w[0] = s[0] = 1;
//   rep(i,A,31) w[i] |= w[i-A];
//   rep(i,B,31) w[i] |= w[i-B];
//   rep(i,C,3001) s[i] |= s[i-C];
//   rep(i,D,3001) s[i] |= s[i-D];
// 
//   res1 = 100A;
//   res2 = 0;
//   rep(i,31) if(w[i]) rep(j,3001) if(s[j]){
//     if(100i + j > F) break;
//     if(i*E < j) break;
//     if(j * (res1+res2) > res2 * (100i+j)){
//       res1 = 100i;
//       res2 = j;
//     }
//   }
// 
//   wt(res1+res2, res2);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;priority_queue<int,vector<int>,greater<int> >q[2];int main(){long long n,m,a,b,c,d=0,s=0;cin>>n>>m>>a;for(int i=1;i<m;i++){cin>>b;q[0].push(min(a,b)-1);q[1].push(max(a,b)-1);a=b;}for(int i=0;i<n-1;i++){while(!q[0].empty()){if(q[0].top()!=i)break;d++;q[0].pop();}while(!q[1].empty()){if(q[1].top()!=i)break;d--;q[1].pop();}cin>>a>>b>>c;s+=min(a*d,c+(b*d));}cout<<s<<endl;return 0;}

Measured memory_bytes: 4012
x, k, d = map(int,input().split())

first_move = abs(x)//d

if first_move >= k:
    print(abs(x)-d*k)
else:
    k -= first_move
    x_abs = abs(x) - first_move*d

    if k%2 == 0:
        print(x_abs)
    else:
        print(abs(x_abs-d))


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll f(ll v, double t) {
    double raw = v / t;
    ll ans = raw;
    if (ans < raw) ans++;
    return (ans - 1);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    double left = 0, right = 1e9 + 1;
    rep(i, 80) {
        double mid = (left + right) / 2;
        ll tmp = 0;
        rep(j, n) tmp += f(a[j], mid);
        if (tmp <= k) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    ll ans = left;
    if (ans < left) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
int x,y;
string s;
int main()
{
    cin>>s;
    for (int i=0;i<s.size();i++)
    {
        x+=(s[i]-48);
    }
    for (int i=s.size()-1,j=1;i>=0;i--,j*=10)
    {
        y+=(s[i]-48)*j;
    }
    if (y%x==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    rep(i, n - k) {
        if (a[i] >= a[i + k]) cout << "No\n";
        else cout << "Yes\n";
    }

    return 0;
}


Measured memory_bytes: 3984
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll x=0,f=1; char ch=0;
	while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int main()
{
	ll n=read(),a=read(),b=read();
	ll ans=min(n*a,b);
	printf("%lld\n",ans);
	return 0;	
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int K, A, B;
	
	scanf("%d", &K);
	scanf("%d %d", &A, &B);
	
	for(int i = A; A <= B; A++) {
		if (A%K==0) {
			printf("OK");
			
	return 0;
		} 

		}
	printf("NG");
	
	
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x,ans=0;
	string s;
	cin>>x>>s;
	x=0;
	for(auto&i:s){
		i=='I'?++x:--x;
		ans=max(ans,x);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef	pair<int,int>	pii;

int xgcd(int a,int b,int &x,int &y){
	if(b==0){ x=1; y=0; return a; }
	int g=xgcd(b,a%b,y,x); y-=a/b*x;
	return g;
}

pii solve(int a,int b,int d){
	int x,y,g=xgcd(a,b,x,y);
	x*=d/g,y*=d/g;

	int xans=x,yans=y;
	rep(i,2){
		int delta=(i?1:-1);
		for(int j=0,k=0;j<100001;j++,k+=delta){
			int xx=x+k*(b/g),yy=y-k*(a/g);
			if(mp(abs(xans)+abs(yans),a*abs(xans)+b*abs(yans))
			 < mp(abs(xx  )+abs(yy  ),a*abs(xx  )+b*abs(yy  )))	break;
			else	xans=xx,yans=yy;
		}
	}

	return mp(abs(xans),abs(yans));
}

int main(){
	for(int a,b,d;scanf("%d%d%d",&a,&b,&d),a;){
		pii res=solve(a,b,d);
		printf("%d %d\n",res.first,res.second);
	}
	return 0;
}

Measured memory_bytes: 0
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


int main() {
	ll N;

	cin >> N;
	vector<ll> d(N);

	rep(i, N)
		cin >> d[i];


	sort(d.begin(), d.end());

	ll ans = 0;
	

		ans = d[N / 2] - d[N / 2 - 1];

	

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
using System;

namespace abc095A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int Ans = 0;
            for(int i = 0; i < 3; i++)
            {
                string temp = S.Substring(i, 1);
                if (temp == "o")
                    Ans += 1;
            }
            Console.WriteLine(700 + Ans * 100);
        }
    }
}


Measured memory_bytes: 11092
n,m = map(int,input().split())

data = [0] * n
count = [0] * n
for i in range(m):
    p,s = input().split()
    p = int(p)
    p = p - 1
    if s == "AC":
        data[p] = 1
    elif s == "WA" and data[p] == 0:
        count[p] += 1

x = 0

for i in range(n):
    x += data[i] * count[i]

print(sum(data),x)



Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   int s, w;
   cin >> s >> w;
   if(s<=w){
    cout << "unsafe" << endl;

   }else{
    cout << "safe" << endl;
   }
}



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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	int a;
	vi cnt(100030);
	for (int i = 0; i < n; i++) {
		cin >> a;
		cnt[a]++;
	}

	int res = cnt[0] + cnt[1];
	for (int i = 1; i < 100000; i++) {
		res = max(res, cnt[i] + cnt[i - 1] + cnt[i + 1]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
d = {}
for i in range(-1000,1000):
	temp = i**5
	if temp not in d:
		d[temp] = i

posd = {}
for i in range(0,1000):
	temp = i**5
	if temp not in posd:
		posd[temp] = i

x = int(input())
for i in posd:
	if i-x in d:
		print(posd[i],d[i-x])
		break

Measured memory_bytes: 9440
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define pii     pair<ll,ll>
#define vi      vector<ll>
#define mp      make_pair
#define pb      push_back
#define F       first
#define S       second
#define pf(n)   printf("%lld\n",n)
#define sf(n)   scanf("%lld",&n)
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)  x.begin(),x.end()
#define ms(n,i) memset(n,i,sizeof n)
#define sz(x)   (ll)x.size()
#define pi      3.141592653589793238
#define hell    1000000007
#define hell2   1000000009
#define endl    '\n'
#define inf     1e18
#define N       100005

int main()
{
    ll n,w,i,j,k;
    cin>>n>>w;
    vector<pii> v(n);
    for(i=0;i<n;i++){
        cin>>v[i].F>>v[i].S;
    }
    ll dp[n][w+1];
    ms(dp,0);
    for(i=v[0].F;i<=w;i++)
        dp[0][i]=v[0].S;
    for(i=1;i<n;i++){
        for(j=0;j<=w;j++){
            if(j>=v[i].F)
                dp[i][j]=max(dp[i-1][j-v[i].F]+v[i].S,dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];            
        }
        //cout<<endl;
    }
    ll ans=0;
    for(i=0;i<=w;i++)
        ans=max(ans,dp[n-1][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 78336
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int n = cin.nextInt();
			n = n%39;
			if(n==0){
				System.out.println("3C"+39);
			}
			else{
				if(n>=10)
					System.out.println("3C"+n);
				else{
					System.out.println("3C0"+n);
				}
			}
		}

	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <map>

int main()
{
    int dict_size = 26;
    std::map<char, int> alphaToNum = {
        {'A', 0}, {'B', 1}, {'C', 2}, {'D', 3}, {'E', 4}, {'F', 5}, {'G', 6}, {'H', 7}, {'I', 8}, {'J', 9}, {'K', 10}, {'L', 11}, {'M', 12}, {'N', 13}, {'O', 14}, {'P', 15}, {'Q', 16}, {'R', 17}, {'S', 18}, {'T', 19}, {'U', 20}, {'V', 21}, {'W', 22}, {'X', 23}, {'Y', 24}, {'Z', 25}
    };
    std::map<int, char> numToAlpha = {
        {0, 'A'}, {1, 'B'}, {2, 'C'}, {3, 'D'}, {4, 'E'}, {5, 'F'}, {6, 'G'}, {7, 'H'}, {8, 'I'}, {9, 'J'}, {10, 'K'}, {11, 'L'}, {12, 'M'}, {13, 'N'}, {14, 'O'}, {15, 'P'}, {16, 'Q'}, {17, 'R'}, {18, 'S'}, {19, 'T'}, {20, 'U'}, {21, 'V'}, {22, 'W'}, {23, 'X'}, {24, 'Y'}, {25, 'Z'}
    };
    int num;
    std::string inputs;
    std::cin >> num;
    std::cin >> inputs;
    
    std::string outputs;
    int i, k;
    for (i = 0; i < inputs.length(); ++i)
    {
        k = alphaToNum[inputs[i]] + num;
        k %= 26;
        outputs.push_back(numToAlpha[k]);
    }
    std::cout << outputs;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;

int main(){
  ll n,k;cin>>n>>k;
  vll l(k),r(k);
  rep(i,0,k){
    cin>>l[i]>>r[i];
  }
  vll dp(n,0),sdp(n+1,0);
  dp[0]=1;sdp[1]=1;
  rep(i,1,n){
    rep(j,0,k){
      ll left=max(0LL,i-r[j]),right=max(0LL,i-l[j]+1);
      dp[i]+=sdp[right]-sdp[left];dp[i]%=MOD;
    }
    sdp[i+1]=sdp[i]+dp[i];
    
  }

  out(dp[n-1]%MOD);
}







Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int a,b;

    cin>>a>>b;

    cout<<max(a+b,max(a-b,a*b))<<endl;
}


Measured memory_bytes: 256
using System.Numerics;
using System;

public class hello
{

    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var h = int.Parse(line[1]);
            if (w == 0 && h == 0) break;
            var map = new string[h, w];
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                {
                    int t;
                    map[i, j] = int.TryParse(s[j].ToString(), out t) ? s[j].ToString() : "#";
                }
            }
            var dp = new string[h, w];
            goDp(map, h, w, dp);
        }
    }
    static void goDp(string[,] map, int h, int w, string[,] dp)
    {
        var ans = "-1";
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j] != "#")
                {
                    string t;
                    if ((i - 1 < 0) || (map[i - 1, j] == "#")) t = map[i, j];
                    else t = dp[i - 1, j] + map[i, j];
                    string t2;
                    if ((j - 1 < 0) || (map[i, j - 1] == "#")) t2 = map[i, j];
                    else t2 = dp[i, j - 1] + map[i, j];
                    dp[i, j] = checkAB(t, t2) ? t : t2;
                    if (((i + 1 >= h) || (map[i + 1, j] == "#")) &&( (j + 1 >= w) || map[i, j + 1] == "#"))
                        ans = checkAB(ans, dp[i, j]) ? ans : dp[i, j];
                }
            }
        }
        print(ans);
    }
    static void print(string s)
    {
        var ans = "";
        var p = 0;
        var first = true;
        while (p < s.Length)
        {
            if (first && s[p] != '0') { ans += s[p]; first = false; }
            else if (!first) ans += s[p];
            p++;
        }
        Console.WriteLine(ans);

    }
    static bool checkAB(string s, string t)
    {
        BigInteger s2 = BigInteger.Parse(s);
        BigInteger t2 = BigInteger.Parse(t);
        return s2 > t2;
    }
}



Measured memory_bytes: 31848
N,K = map(int,input().split())
A = list(map(int,input().split()))

for k in range(1,min(K+1,45)):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1,i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
            
    for i in range(1,N):
        B[i] += B[i-1]
    A = B
print(*A)

Measured memory_bytes: 164264
#include <bits/stdc++.h>
using namespace std;
int N,M;


vector<int> solve(){
	cin>>N>>M;
	char s[N+2];
	vector<int> prev(N+1,-1);
	cin>>s;
	vector<int> nn;
	nn.push_back(-1);
	if(s[0]=='1') return nn;
//	if(N==1) return n1;
//	n1.push_bac({0});
	if(s[N]=='1') return nn;
	prev[0] = 0;
	int a = 0;
	for(int j = 1; j<=N;j++){
		if(s[j]=='1') continue;
		int st = j-a;
		if(st>M){
			int found = 0;
			for(int q = j-M;q<j;q++){
				if(s[q]=='0'){
					a = q;
					found = 1;
					break;
				}
			}
			if(!found){
				return nn;
			}
		}
	    prev[j] = a;
	}
	vector<int> numbers;
	int sta = N;
	while(sta!=0){
		numbers.push_back(sta-prev[sta]);
		sta = prev[sta];
	}

	return numbers;

}
int main(){
   vector<int> x = solve();
   for(int j = x.size()-1;j>=0;j--){
   	 cout<<x[j]<<" ";
   }
	
}

Measured memory_bytes: 4184
#include<bits/stdc++.h>
 
using namespace std;
long long mod = 1e9+7;
long long dp[1000+3][24];
int main(){
#ifdef LOCAL
	freopen("input.txt","r",stdin);
#endif
   int n, m;
  cin >> n >> m;
  if(m<n)
  {
      for(int i=0;i<n;i++)
        cout << m;
  }
  else
  {
      for(int i=0;i<m;i++)
        cout << n;
  }
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

const int INF = INT_MAX / 3;

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


double EPS = 1e-10;

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct P {
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator +(P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator -(P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator *(double d) {
		return P(d*x, d*y);
	}
	double dot(P p) {
		return add(x*p.x, y*p.y);
	}
	double det(P p) {
		return add(x*p.y, -y*p.x);
	}
	void print() {
		printf("%.10lf %.10lf \n", x, y);
		return;
	}
};

int IsConvex(vector<P> &polygon){
	int n = polygon.size();
	int d = 1;
	P p1, p2;
	for(int i=0;i<n-2;i++){
		p1 = polygon[i+1]-polygon[i];
		p2 = polygon[i+2]-polygon[i+1];
		if(p1.det(p2)<0){
			d = 0;
			break;
		}
	}
	p1 = polygon[n-1]-polygon[n-2];
	p2 = polygon[0]-polygon[n-1];
	if(p1.det(p2)<0){
		d = 0;
	}
	p1 = polygon[0]-polygon[n-1];
	p2 = polygon[1]-polygon[0];
	if(p1.det(p2)<0){
		d = 0;
	}

	return d;
}

int main(){
	int n;
	cin >> n;
	vector<P> polygon;
	REP(i,n){
		P p;
		cin >> p.x >> p.y;
		polygon.push_back(p);
	}
	cout << IsConvex(polygon) <<endl;
	return 0;
}

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

using namespace std;

struct bulb_t {
    vector<int> switches;
};

vector<bulb_t> bulbs;
vector<int> ps;
int count_all_on = 0;

int compute_bulb_onoff(int bulb_i, vector<int>& switch_states, const bulb_t& bulb) {
    int on_count = 0;
    for(auto sw : bulb.switches) {
        if(0 < switch_states[sw]) {
            on_count++;
        }
    }
    if(on_count%2 == ps[bulb_i]) {
        return 1;
    }
    return 0;
}

bool is_all_bulbs_on(vector<int>& switch_states) {
    // debug
    /*for(int i = 0; i < switch_states.size(); i++) {
        cout << switch_states[i] << " ";
    }
    cout << endl;
    */
    for(int i = 0; i < bulbs.size(); i++) {
        if(compute_bulb_onoff(i, switch_states, bulbs[i]) == 0) {
            return false;
        }
    }
    return true;
}

void process_sw(vector<int>& switch_states, int switch_i) {
    if(switch_i == switch_states.size() -1) { // if leaf
        // sw[i] == off
        switch_states[switch_i] = 0;
        if(is_all_bulbs_on(switch_states)) {
            count_all_on++;
        }
        
        // sw[i] == on
        switch_states[switch_i] = 1;
        if(is_all_bulbs_on(switch_states)) {
            count_all_on++;
        }
    } else { // if node
        // sw[i] == off
        switch_states[switch_i] = 0;
        process_sw(switch_states, switch_i+1);
        
        // sw[i] == on
        switch_states[switch_i] = 1;
        process_sw(switch_states, switch_i+1);
    }
}

int main(int argc, const char * argv[]) {
    int N = 0; // num of bulbs
    int M = 0; // num of switches
    cin >> N >> M;

    for(int i = 0; i < M; i++) {
        int num_switches = 0;
        cin >> num_switches;
        bulb_t bulb;
        for(int j = 0; j < num_switches; j++) {
            int s = 0;// connected switch number
            cin >> s;
            bulb.switches.push_back(s-1);// num -> index
        }
        bulbs.push_back(bulb);
    }
    
    for(int i = 0; i < M; i++) {
        int p = 0;
        cin >> p;
        ps.push_back(p);
    }
    
    vector<int> switch_states(N, 0);// 0:off, 1:on
    process_sw(switch_states, 0);
    cout << count_all_on << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);


		String a = scan.next().toUpperCase();
		String b = scan.next().toUpperCase();
		String c = scan.next().toUpperCase();

		System.out.print(a.charAt(0));
		System.out.print(b.charAt(0));
		System.out.println(c.charAt(0));
	}
}


Measured memory_bytes: 23508
L = input()
MOD = 10**9 + 7
now = 1
ans = 1
for b in L[:: -1]:
    if b == '1':
        ans = (ans * 2 + now) % MOD
    else:
        ans = ans % MOD
    now = now * 3 % MOD
print(ans % MOD)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool IsOneBit(long long bits, int i) {
	return (bits & (1ll << i)) > 0;
}
int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) cin >> A[i][j];
	}
	int MIN = 1200001;
	for (int i = 0; i < (1 << N); i++) {
		int sum = 0;
		vector<int> R(M, 0);
		for (int j = 0; j < N; j++) {
			if (IsOneBit(i, j)) {
				for (int k = 0; k < M; k++) R[k] += A[j][k];
				sum += C[j];
			}
		}
		bool OK = true;
		for (int k = 0; k < M; k++) if (R[k] < X) OK = false;
		if (!OK) continue;
		MIN = min(MIN, sum);
	}
	cout << (MIN < 1200001 ? MIN : -1) << endl;
}

Measured memory_bytes: 3632
H, W = gets.split.map(&:to_i)

a = []
odd_count = 0

H.times do |y|
  tmp =  gets.split.map(&:to_i)
  odd_count += tmp.count{|i| i%2 == 1}
  a << tmp
end

from = []
route = []
move_count = 0

0.upto(H-1) do |y|
  range =
    if y%2 == 0
      0..(W-1)
    else
      ((0..(W-1)).to_a).reverse
    end

  range.each do |x|
    if a[y][x] %2 == 1 && from.empty?
      from = [y,x] if odd_count != 1
    elsif !from.empty?
      route << [from[0]+1, from[1]+1, y+1, x+1]
      move_count += 1
      from =[y,x]

      if a[y][x] %2 == 1
        odd_count -= 2
        from = []
      end
    end
  end
end

puts move_count

0.upto(route.size-1) do |i|
  puts route[i].join(" ")
end


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

template <typename _Ty>
struct Edge {
    int src, to;
    _Ty cost;

    constexpr Edge(int _to, _Ty _cost) noexcept
        : src(-1), to(_to), cost(_cost) {}
    constexpr Edge(int _src, int _to, _Ty _cost) noexcept
        : src(_src), to(_to), cost(_cost) {}
};
template <typename _Ty>
using WeightedGraph = std::vector<std::vector<Edge<_Ty>>>;

template <typename _Ty>
bool bellman_ford(const WeightedGraph<_Ty>& g, std::vector<_Ty>& dist, int s) {
    _Ty inf = std::numeric_limits<_Ty>::max();
    int n = static_cast<int>(g.size());
    dist.assign(n, inf);
    dist[s] = 0;
    bool update;
    for (int i = 0; i < n; i++) {
        update = false;
        for (int j = 0; j < n; j++) {
            for (const auto& edge : g[j]) {
                if (dist[j] != inf && dist[edge.to] > dist[j] + edge.cost) {
                    dist[edge.to] = dist[j] + edge.cost;
                    update = true;
                }
            }
        }
        if (!update) break;
    }
    if (update) {
        dist.clear();
        return false;
    }
    else {
        return true;
    }
}

template <unsigned long _n, typename _Ty>
void bfs(bitset<_n>& bset, WeightedGraph<_Ty>& g, int s) {
    Vi colors(g.size());
    queue<int> q;
    q.push(s);
    colors[s] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        bset[u] = true;
        for (const auto& edge : g[u]) {
            if (colors[edge.to] == 0) {
                q.push(edge.to);
                colors[edge.to] = 1;
            }
        }
    }
}

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

    int N, M;
    ll P;
    cin >> N >> M >> P;

    WeightedGraph<ll> g(N);
    WeightedGraph<ll> rg(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].emplace_back(b, P - c);
        rg[b].emplace_back(a, P - c);
    }

    bitset<2505> bset1, bsetN;
    bfs(bset1, g, 0);
    bfs(bsetN, rg, N - 1);
    bset1 &= bsetN;

    WeightedGraph<ll> g_omitted(N);
    for (int i = 0; i < N; i++) {
        for (const auto& edge : g[i]) {
            if (bset1[edge.to]) {
                g_omitted[i].push_back(edge);
            }
        }
    }

    Vl cost;
    bool ok = bellman_ford(g_omitted, cost, 0);

    if (ok) {
        cout << max(-cost[N - 1], 0LL) << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 896
#include <cstring>
#include <cstdio>
using namespace std;

int cnt = 0;
int n;
int len;

bool check(int num) {
    int san = 0, wu = 0, qi = 0;
    while(num) {
        if(num % 10 == 3) san++;
        else if(num % 10 == 5) wu++;
        else if(num % 10 == 7) qi++;
        num /= 10;
    }
    if(san && wu && qi) return 1;
    else return 0;
}

void solve(int num, int step) {
    if(step == len) {
        if(num <= n && check(num)) cnt++;
        return;
    }
    else if(step < len) {
        if(num <= n && check(num)) cnt++;
    }
    solve(num * 10 + 3, step+1);
    solve(num * 10 + 5, step+1);
    solve(num * 10 + 7, step+1);
}

int main() {
    while(~scanf("%d", &n)) {
        char s[15];
        sprintf(s, "%d", n);
        len = strlen(s);
        cnt = 0;
        solve(0, 0);
        printf("%d\n", cnt);
    }
}

Measured memory_bytes: 128