akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define sz(x) ((int)(x).size())
#define endl "\n"
#define INF 0x20202020
#define EPS 1e-9
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

ll powmod(ll a, ll b) {
    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;
}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> si;

class B {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        //max b = 1000
        //max p = 10
        //MAX OF ALL BASES
        int n;
        cin >> n;
        int res = 1;
        for (int p = 2; p * p <= n; ++p) {
            int j = p * p;
            while (j * p <= n) j *= p;
            res = max(res, j);
        }
        cout << res << endl;
    }
};


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    B solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> V(N);
    rep(i,N) {
        string s; cin >> s;
        int p; cin >> p;
        V.at(i) = make_tuple(s, p, i);
    }
    sort(begin(V), end(V), [](tuple<string, int, int> L, tuple<string, int, int> R) {
        if (get<0>(L) != get<0>(R)) return L < R;
        return get<1>(L) > get<1>(R);
    });
    rep(i,N) {
        cout << get<2>(V[i]) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;

int main(){
	int x,y,z;
	cin>>x>>y>>z;
	cout<<(x-z)/(z+y)<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
Min=float('inf')
while True:
    if len(A)==0:
        break
    if A[-1]<0:
        break
    else:
        Min=A[-1]
        ans+=A[-1]
        A.pop()
if len(A)%2==1:
    if abs(A[-1])>Min:
        ans-=A[-1]+2*Min
    else:
        ans+=A[-1]
    A.pop()
ans+=-1*sum(A)
print(ans)

Measured memory_bytes: 14332
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  char[]c=sc.next().toCharArray();
  boolean b=true;
  char[]po=new char[]{'L','R'};
  for(int i=0;i<c.length;i++){
  if(c[i]==po[i%2])b=false;
  }
  System.out.println(b?"Yes":"No");

}

}


Measured memory_bytes: 21972
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int sum;

    void run(){
	while(sc.hasNext()){
	    sum = 0;
	    for(int i=0; i<5; i++){
		int x = sc.nextInt();
		if(x<40) sum+=40;
		else sum+=x;
	    }
	    System.out.println(sum/5);
	}
    }
}

Measured memory_bytes: 17240
s=input()
t=input()
 
if len(s) < len(t):
  print("UNRESTORABLE")
  exit()
 
c=len(s)-len(t)
 
flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1
#print(c)
 
 
 
if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const int max_n=3005;
int n,L;
double ang[max_n];
int main(){
    scanf("%d%d",&n,&L);
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        ang[i]=2*PI*x/L;
    }
    double ansx=0.0,ansy=0.0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            double tx=cos((ang[i]+ang[j])/2),ty=sin((ang[i]+ang[j])/2);
            int l=n-(j-i+1),r=j-i-1;
            ansx+=tx*(l-r),ansy+=ty*(l-r);
        }
    }
    ll all=1ll*n*(n-1)*(n-2)/6;
    ansx/=all,ansy/=all;
    printf("%.9f %.9f\n",ansx,ansy);
    return 0;
}

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

using ll = long long int;

int n, k;

vector<ll> x;

ll ans = (ll)(1e18 + 5);

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

  for (int i = 0; i < n; ++i) {
    ll xi;
    scanf("%lld", &xi);
    x.push_back(xi);
  }

  for (int i = 0; i <= n - k; ++i) {
    ll tmp1 = abs(x[i]) + abs(x[i + k - 1] - x[i]);
    ll tmp2 = abs(x[i + k - 1]) + abs(x[i] - x[i + k - 1]);
    ans = min(ans, min(tmp1, tmp2));
  }

  printf("%lld\n", ans);

  return 0;
}


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

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


    vector<char> l = {S[0], S[1], S[2]};

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

    if (l[0] == 'a' && l[1] == 'b' && l[2] == 'c') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/arc076_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  mint np = 1;
  mint mp = 1;
  mint ans = 1;

  repi(i, 1, N + 1) { np *= i; }
  repi(i, 1, M + 1) { mp *= i; }

  if (N == M) {
    ans = np * np * 2;
 } else {
    ans = np * mp;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3528
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
struct P {double a,b;};

void kock(int n,P p1,P p2){
    if (n == 0) return;
    P s,u,t;
    double r = M_PI*60.0/180.0;
    s.a = (p1.a*2.0 + p2.a*1.0)/3.0;
    s.b = (p1.b*2.0 + p2.b*1.0)/3.0;
    t.a = (p1.a*1.0 + p2.a*2.0)/3.0;
    t.b = (p1.b*1.0 + p2.b*2.0)/3.0;
    
    u.a = (t.a-s.a)*cos(r) - (t.b -s.b)*sin(r) + s.a;
    u.b = (t.a-s.a)*sin(r) + (t.b- s.b)*cos(r) + s.b;
    kock(n-1,p1,s);
    cout<<s.a<<" "<<s.b<<endl;
    kock(n-1,s,u);
    cout<<u.a<<" "<<u.b<<endl;
    kock(n-1,u,t);
    cout<<t.a<<" "<<t.b<<endl;
    kock(n-1,t,p2);
}
int main(){
    P p1,p2;
    p1.a = 0.0;
    p1.b = 0.0;
    p2.a = 100.0;
    p2.b = 0.0;
    
    int n;
    cin >>n;
    cout<<p1.a<<" "<<p1.b<<endl;
    kock(n,p1,p2);
    cout<<p2.a<<" "<<p2.b<<endl;
    return 0;
    
}



Measured memory_bytes: 3292
W,H,N = map(int,input().split())
mat = [list(map(int,input().split())) for i in range(N)]
tmp = [0]*W
tmp = [tmp]*H
for i in range(N):
    if mat[i][2] == 1:
        for j in range(H):
            for k in range(mat[i][0]):
                tmp[j][k] = 1
    elif mat[i][2] == 2:
        for j in range(H):
            for k in range(mat[i][0],W):
                tmp[j][k] = 1
    elif mat[i][2] == 3:
        for j in range(0,mat[i][1]):
            tmp[j] = [1]*W
    else:
        for j in range(mat[i][1],H):
            tmp[j] = [1]*W
print(max([W*H-sum(list(map(sum,tmp))),0]))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>

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

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

int main()
{
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    cout << endl;

    for (auto p : mp) mx = max(mx,p.second);
    for (auto p : mp) {
        if (p.second != mx) continue;
        cout << p.first << endl;
    }
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using Int = long long;
using namespace std;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

const int MAX = 510000;

const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    Int n, k;
    cin >> n >> k;
    Int ans = 0;
    for (Int i = 0; i <= min(k, n - 1); i++) {
        Int x = COM(n - 1, i);
        x *= COM(n, i);
        x %= MOD;
        ans += x;
        ans %= MOD;
    }
    PUTS(ans);
}


Measured memory_bytes: 12160
/****************************** بسم الله الرحمن الرحيم ************************/
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<pair<int, int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define compare bool operator <
#define main int main()
#define sf(n) scanf ("%d", &n)
#define pf(n) printf ("%d", n)
#define sfl(n) scanf ("%lld", &n)
#define pfl(n) printf ("%lld", n)
#define pfnewline() printf("\n")
#define pfspace() printf(" ")
#define mem(x,y) memset( (x), (y), sizeof(x) )
#define max3(a,b,c)   max(a , max(b,c) )
#define min3(a,b,c)  min(a, min(b,c) )
#define Ex 2.718281828
#define pi acos(-1.0)
#define toDecimal(n) fixed<< setprecision(n)
#define rep1(i, n) for(int i = 1; i<=n;i++)
#define rep(i, n) for(int i = 0; i<n;i++)
#define sfc(ch) scanf("%c",&ch)
#define sfs(ch) scanf("%[^\n]%*c", ch);

const ll mxn = 1e5+3;
const ll mod = 1e9+7;

/** ---8 moves --- **/
//int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/** ---4 moves--**/
//int dx[] = {-1,0,0,1};
//int dy[] = {0,-1,1,0};

using namespace __gnu_pbds;
using namespace std;

//ll lcm(ll a, ll b)  return a/__gcd(a,b)*b;
//ll bigmod(int a, ll b) { if(b == 0) return 1% mod;    ll x = bigmod(a,b/2  );    x = (x * x) % mod;    if(b % 2 == 1) x = (x*a)% mod;   return x;}
string toString(int A)
{
    stringstream ss;
    ss<<A;
    string tmp;
    ss>>tmp;
    return tmp;
}
/*-----------------------Bitmask------------------*/
unsigned ll Set(unsigned ll e,int pos)
{

    e |= 1ULL << pos;
    return e;
}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//bool check_if_last_set(int N, int pos) {return N & (1 << (pos - 1));}
/*------------------------------------------------*/

int a[150];
ll dp[150][150];
int f;
bool flag[150];
ll recur(int pos, int cnt)
{
    if(pos == 26)
    {
        if( cnt == 0 )return 0;
        else return 1;
    }
    if( dp[pos][cnt] != -1 )
        return dp[pos][cnt];
    ll amount = (recur(pos+1,cnt  ) % mod);

    amount = ((((recur( pos+1,cnt+1 ) %mod) *((a[pos]) % mod)%mod) + (amount))%mod);

    dp[pos][cnt] = amount%mod;
    return dp[pos][cnt];
}

main
{
    int n;
    cin >>n;
    string str;
    cin >> str;
    mem(dp,-1);
    for(int i = 0; i<n; i++)
    {
        if( !flag[str[i]-'a'] )
        {
            f++;
            flag[str[i]-'a'] =  true;
        }
        a[ str[i]-'a' ]++;
    }
    cout << recur(0,0)%mod << endl;
}


Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> M(N);
  int mi = INF;
  for (int i = 0; i < N; i++) {
    cin >> M[i];
    X -= M[i];
    mi = min(mi, M[i]);
  }
  cout << N + X / mi << endl;

  return 0;
}

Measured memory_bytes: 256
while True:
	a, op, b = (x for x in input().split())
	a, b = int(a), int(b)
	if op == '+':
		print(a + b)
	elif op == '-':
		print(a - b)
	elif op == '*':
		print(a * b)
	elif op == '/':
		print(a // b)
	elif op == '?':
		break


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,W;
	cin>>n>>W;
	int w[n];
	long v[n];
	long dp[W+1];
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	for(int i=0;i<=W;i++)
	{
		dp[i]=0;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=W;j>=w[i];j--)
		{
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
 
	}
 
	cout<<dp[W];
} 
 


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i< t ;i++)

#define SZ(x) (int)x.size()
using LL = long long; using ll = LL;
const int INF = 1e9; const LL LINF = 1e18;

#define MAXT 1005
ll N;
vector<int> T;
bool memo[55][MAXT][MAXT];

void dfs(int n, int x, int y,ll sum) {
	if (memo[n][x][y]) return;
	memo[n][x][y] = true;
	if (n == N) return;
	if (x + T[n] < MAXT) dfs(n + 1, x + T[n], y,sum + T[n]);
	if (y + T[n] < MAXT) dfs(n + 1, x, y + T[n],sum + T[n]);
	if (sum - x - y + T[n] < MAXT) dfs(n + 1, x, y, sum + T[n]);
}

void solve() {
	cin >> N;
	T.resize(N);
	for (auto& in : T) { cin >> in; }
	sort(T.begin(), T.end());
	reverse(T.begin(), T.end());
	dfs(0, 0, 0, 0);
	int sum = accumulate(T.begin(), T.end(), 0);

	ll ans = LINF;
	for (int i = 0; i < MAXT; i++) {
		for (int j = 0; j < MAXT; j++) {
			if (memo[N][i][j] == false) continue;
			ll t = -1;
			t = max({ i,j,sum - i - j });
			ans = min(ans, t);
		}
	}
	cout << ans << endl;
}


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




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

int main() {
    int n, w;
    cin >> n >> w;
    vector<pair<int, int>> wv(n+1);
    for (int i = 1; i <= n; i++)
        cin >> wv[i].first >> wv[i].second;
    vector<vector<long long>> dp(n+1, vector<long long>(w+1, -1));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int k = 0; k <= w; k++) {
            dp[i][k] = max(dp[i][k], dp[i-1][k]);
            if (k < wv[i].first || dp[i-1][k-wv[i].first] < 0)
                continue;
            dp[i][k] = max(dp[i][k], dp[i-1][k-wv[i].first] + wv[i].second);
        }
    }
    long long ans = 0;
    for (int i = 0; i <= w; i++)
        ans = max(ans, dp[n][i]);
    cout << ans;
    return 0;
}

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

int main() {
  int n,d,x;
  scanf("%d %d %d",&n,&d,&x);
  int a;
  int ans=x;
  for (int i=0; i<n; i++) {
    scanf("%d",&a);
    ans += (d-1)/a + 1;
  }
  printf("%d\n",ans);
  return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

struct Node {
    int key;
    Node *left;
    Node *right;
    Node *parent;
public:
    Node(Node *l, Node *r, Node *p, int k) : left(l), right(r), parent(p), key(k) {};
};

class BinarySearchTree {
private:
    Node *root;
    void preorder(Node node);
    void inorder(Node node);
public:
    void insert(int n);
    BinarySearchTree() {root = 0;}
    void print() {
        inorder(*root);
        cout << endl;
        preorder(*root);
        cout << endl;
    }
};

void BinarySearchTree::preorder(Node node) {
    cout << " " << node.key;
    if (node.left != 0) {
        preorder(*node.left);
    }
    if (node.right != 0) {
        preorder(*node.right);
    }
}

void BinarySearchTree::inorder(Node node) {
    if (node.left != 0) {
        inorder(*node.left);
    }
    cout << " " << node.key;
    if (node.right != 0) {
        inorder(*node.right);
    }
}

void BinarySearchTree::insert(int n) {
    Node *z = new Node(0,0,0,n);
    Node *y = 0;
    Node *x = root;
    while (x != 0) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }else {
            x = x->right;
        }
    }
    z -> parent = y;
    if (y == 0) {
        root = z;
    }else if (z->key < y->key) {
        y->left = z;
    }else {
        y->right = z;
    }
}

int main() {
    int n;
    cin >> n;
    string s;
    BinarySearchTree tree;
    REP(i,n) {
        cin >> s;
        if (s[0] == 'i') {
            int j;
            cin >> j;
            tree.insert(j);
        }else {
            tree.print();
        }
    }
    return 0;
}

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

int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> p(n + 1, 1LL), b(n + 1, 1LL);
    for(int i = 1; i <= n; i++){
        p[i] = p[i-1] + 1 + p[i-1];
        b[i] = 1 + b[i-1] + 1 + b[i-1] + 1;
    }
    ll sum = 0LL;
    for(int i = n; i >= 1; i--){
        if(x == 0) break;
        x--;
        if(x <= b[i-1]) continue;
        sum += p[i-1] + 1;
        x -= b[i-1] + 1;
    }
    if(x) sum++;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

list = input().split()
list_int = [int(s) for s in list]
list_int.sort(reverse=True)

A = 0
B = 0

for x in range(N):
  if x % 2 == 0:
    A += list_int[x]
  else:
    B += list_int[x]

ans = A - B
print(ans)


Measured memory_bytes: 3060
// #include<set>
// #include<vector>
// #include<algorithm>
#include <string>
#include <iostream>

using namespace std;

int N;
string s, t;

int main(){
    cin >> s >> t;
    if(t.find(s) == 0 && t.size() == s.size() + 1)cout << "Yes";
    else cout << "No";
	return 0;
}

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

using namespace std;

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

    int r = 0;

    for (int i = 0; i < 3; i++) {
        if (s % 10 == 1) r++;
        s /= 10;
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3624
N = int(input())
x2 = input()
x10 = int(x2, 2)
popc =  x2.count("1")
#print("x10", x10)
#print("popc", popc)
#popc: Nを2進数で表したときの1の個数

#以下で1つフリップさせた時の入力に対する余りを事前に計算
if popc <= 1:
    xp = x10%(popc+1)
    xm = 0
else:
    xp = x10%(popc+1)
    xm = x10%(popc-1)
#print("xp", xp)
#print("xm", xm)

#以下でフリップさせた場所のみを計算
for i in range(N):
    if x2[i] == "1":
        if popc == 1:
            print(0)
            continue
        tmp = (xm - pow(2, N-i-1, popc-1))%(popc-1)
    else:
        tmp = (xp + pow(2, N-i-1, popc+1))%(popc+1)
        
    #print("tmp", tmp)
    ans = 1
    while tmp > 0:
        tmp %= bin(tmp).count("1")
        ans += 1
    print(ans)

Measured memory_bytes: 81492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int>X(N);
    for(int i=0;i<N;++i)cin>>X[i];
    int ans=0;
    int maxv=0;
    int A=0;
    sort(X.begin(),X.end());
    reverse(X.begin(),X.end());
    A=X[0];

    for(int i=0;i<=A;++i){
        int ans=0;
        for(int j=0;j<N;++j){
        ans+=pow(X[j]-i,2);
    }

        if(i==1){
            maxv=ans;
            continue;
        }
        if(maxv>ans){
            maxv=ans;
        }
      
    
    }
    cout<<maxv<<endl;

}


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

int main()
{
    long int H, W;
    cin >> H >> W;
    if( H >=2 and W >= 2){

        long int h0 = (W+1) / 2;
        long int h1 = W / 2;
        long int w0 = (H+1) / 2;
        long int w1 = H / 2;
        cout << h0 * w0 + h1 * w1 << endl;
    }else{
        cout << 1 << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
int N,A[Nmax];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
		A[i]--;
	}

	sort(A, A+N);
	vector<int> cnt(100000);
	for(int i=0; i<N; i++){
		cnt[A[i]]++;
	}

	int l=0, u=100000-1;
	while(l < 100000 && cnt[l]<2) l++;
	while(u >= 0 && cnt[u]<2) u--;
	while(l<u){
		cnt[l]--;
		cnt[u]--;
		while(l < 100000 && cnt[l]<2) l++;
		while(u >= 0 && cnt[u]<2) u--;
	}
	
	int ans = 0;
	if(l == u){
		while(cnt[l] >= 3) cnt[l]-= 2;
		if(cnt[l]>1){
			cnt[l] = 1;
			ans = -1;
		}
	}

	for(int i=0; i<100000; i++){
		if(cnt[i]==1) ans++;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1024
N, M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

class UnionFind(object):
    def __init__(self,N):
        self.N = N
        self.par = list(range(self.N))
        self.rank = [0]*self.N
        self.size = [1]*self.N
        
    def find(self,x):
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[x]
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        
        self.size[x] += self.size[y]
        self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
    
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    def count(self,x):
        return self.size[self.find(x)]
    
uni = UnionFind(N)
ans = []

inconv = N*(N-1)//2
ans.append(inconv)

for i in range(M-1,0,-1):
    x,y = ab[i]
    x -= 1
    y -= 1
    xs = uni.count(x)
    ys = uni.count(y)
    if uni.find(x) == uni.find(y):
        ans.append(inconv)
        continue
    uni.union(x,y)
    inconv -= xs*ys
    ans.append(inconv)

for i in ans[::-1]:
    print(int(i))  

Measured memory_bytes: 36664
#include <bits/stdc++.h>
#define ll long long 
#pragma GCC optimize("Ofast", "unroll-loops")
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define pii pair<int,int>
#define SZ(x) x.size()
#define ALL(x) x.begin(), x.end()
#define ull unsigned ll 
#define pb push_back
#define f first 
#define s second
using namespace std;
int main (){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int k,x; cin>>k>>x;
	FOR(i,x-k+1,k+x){
		cout<<i<<' ';
	}
	cout<<endl;
}

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

int main(void){
    char a;
    cin>>a;
    if(a>='a'&&a<='z')cout<<'a';
    else cout<<'A';
}

Measured memory_bytes: 3584
//#include <climits>
//#include <vector>
#include <iostream>
using namespace std;

int GCD(int x, int y) {
    //余りがゼロになったら終了
    if(x % y == 0) {
        return y;
    }

    return GCD(y, x%y);
}

int main() {

    int x, y;
    cin >> x >> y;

    cout << GCD(x, y) << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>

int n;
int a[100];

int main() {
    std::cin>>n;
    for(int i=0;i<n;++i)
        std::cin>>a[i];
    std::sort(a,a+n);
    std::cout<<a[n-1]-a[0]<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;
const int N = 2e5 + 5;

ll power(ll a, ll n) {
    if (n == 1) return a;
    if (n & 1)
        return (power(a, n - 1) * a) % M;
    else {
        ll r = power(a, n / 2);
        return (r * r) % M;
    }
}

ll mid[N];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    ll ans = 0;
    for (ll i = k; i >= 1; i--) {
        ll v = k / i;
        mid[i] = (power(v, n)) % M;
        for (int j = i * 2; j <= k; j += i) {
            mid[i] -= mid[j];
            mid[i] = (mid[i] + M) % M;
        }
        ans += mid[i] * i;
        ans %= M;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4000
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String a = s.substring(0,5);
		String b = s.substring(6,13);
		String c = s.substring(14,19);
		System.out.println(a + " " + b + " " + c);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

int memo[110][110];
char field[110][110];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n, m;

int main(){
	while(cin >> n >> m && (n || m)){
		fill(&memo[0][0], &memo[109][109] + 1, INF);
		fill(&field[0][0], &field[109][109] + 1, '.');
		rep(i, m)rep(j, n) cin >> field[j+1][i+1];
		memo[0][0] = 0;
		priority_queue<PP, vector<PP>, greater<PP> > que;
		que.push(PP(0, P(0, 0)));
		while(!que.empty()){
			
			PP pp = que.top();
			que.pop();
			int c = pp.first;
			int x = pp.second.first;
			int y = pp.second.second;
			if(c > memo[x][y]) continue;
			if(field[x][y] == '&') {
				cout << c << endl;
				break;
			}
			rep(i, 4){
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				if(0 <= x2 && x2 <= n + 1 && 0 <= y2 && y2 <= m + 1){
					int cost = 0;
					if(field[x][y] == '.' && field[x2][y2] == '#') cost = 1;
					if(memo[x2][y2] > memo[x][y]+ cost){
						memo[x2][y2] = memo[x][y] + cost;
				
						que.push(PP(memo[x2][y2], P(x2, y2)));
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque


def main():
    N, Q = map(int, input().split())
    g = [[] for _ in range(N)]

    # for storing the value of the each node
    cnt = [0]*N

    # for DFS
    stack = deque()
    stack.append(0)
    seen = [0] * N

    # store the structure of the graph
    for i in range(N-1):
        a, b = map(int, input().split())
        g[b-1].append(a-1)
        g[a-1].append(b-1)

    # add values to parent nodes
    for i in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x

    # DFS
    while len(stack):
        idx = stack.pop()
        seen[idx] += 1
        for c in g[idx]:
            if seen[c]:
                continue
            cnt[c] += cnt[idx]
            stack.append(c)

    print(*cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 56088
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    ans = ""
    while n > 0:
        n -= 1
        ans = chr(n%26 + ord('a')) + ans
        n //= 26
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 61768
S = int(input())

def f(n):
  if n%2 == 0:
    return n // 2
  else:
    return 3*n + 1
  
A = set()
X = [0] * 1000010

X[1] = S
A.add(S)

for i in range(2,1000001):
  X[i] = f(X[i-1])
  A.add(X[i])
  if i > len(A):
    break
    
print(i)

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

int main(){
  int n, k, ans=0;
  string s;
  cin >> n >> k;
  cin >> s;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1])ans++;
  }
  ans=min(ans+2*k, n-1);
  cout << ans << endl;
  return 0;
}


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

int main(void) {
	int i;
	int N;
	long long int ans;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);

	ans = 0;
	for(i = 1; i <= N - 1; i += 1) {
		ans += (N - 1) / i;
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const ll MOD = 1e9+7;

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

	int n, m; cin >> n >> m;
	vector<string> v(n);
	FOR(i, n) cin >> v[i];

	int dp[101][101];
	dp[0][0] = (v[0][0] == '#');
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(i == 0 && j==0) continue;
			if(i == 0){
				dp[i][j] = dp[i][j-1];
				if(v[i][j] == '#' && v[i][j-1] == '.')
					dp[i][j]++;
			}else if(j == 0){
				dp[i][j] = dp[i-1][j];
				if(v[i][j] == '#' && v[i-1][j] == '.')
					dp[i][j]++;
			}else{
				int add1 = (v[i][j] == '#' && v[i-1][j] == '.');
				int add2 = (v[i][j] == '#' && v[i][j-1] == '.');
				dp[i][j] = min(dp[i-1][j] + add1, dp[i][j-1] + add2);
			}
		}
	}

	cout << dp[n-1][m-1] << '\n';

	return 0;
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for(int i = s; i < (e); ++i)
#define FASTIO                                                                                     \
	ios_base::sync_with_stdio(false);                                                              \
	cin.tie(NULL);
#define FILEIO                                                                                     \
	freopen("./input.txt", "r", stdin);                                                            \
	freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                                                  \
	for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;  \
		debug("%s : %lld ms\n ",                                                                   \
			  d,                                                                                   \
			  chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() -   \
														  blockTime.first)                         \
				  .count()),                                                                       \
			 blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T& x) {
	return x > 0 ? x : -x;
}
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
ll ceil2(ll a, ll b) { return (a + b - 1) / b; }

int main() {
	FASTIO
#ifdef LOCAL
	FILEIO
#endif
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans = max({a * c, a * d, b * d, b * c});
	cout << ans;

	return 0;
}

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

int main() {
  double N;
  int K;
  cin >> N >> K;
  if(N >= K) {
    double ans = (N - K + 1) / N;
    for(int i = 1; i < K; i++) {
      double p = 1;
      int keep = i;
      while(keep < K) {
        p /= 2;
        keep *= 2;
      }
      ans += p / N;
    }
    cout << fixed << setprecision(10) << ans << endl;
  }
  else {
    double ans = 0;
    for(int i = 1; i <= N; i++) {
      double p = 1;
      int keep = i;
      while(keep < K) {
        p /= 2;
        keep *= 2;
      }
      ans += p / N;
    }
    cout << fixed << setprecision(10) << ans << endl;
  }
}

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

int main()
{
    int n;
    vector<int> v;
    int x = 0;
    cin >> n;
    while (n > 0)
    {
        int a;
        cin >> a;
        x = a ^ x;
        v.push_back(a);
        n--;
    }

    for (int i = 0; i < v.size(); i++)
    {
        v[i] = v[i] ^ x;
        cout << v[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 3792
import java.util.*;

import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] ad;
	static int n;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n=sc.nextInt();
		System.out.println((n/2)+(n%2==0?0 :1));
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int H[N];
for(int i=0;i<N;i++){
cin >> H[i];
}
H[0]--;
bool f=true; 
for(int i=1;i<N;i++){
 if(H[i-1]<H[i]){ H[i]--; }
 else if(H[i-1]>H[i]){ f=false;break; }
}
if(f){ cout << "Yes"; }else{ cout << "No"; }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,m;
int sr[10010];
int A[110][110];
bool book[10010];
int B[110][110];
int C[110][110];

int s,t;
struct data{
    int to,nxt,c,id;
}mp[100100];
int head[1010],cnt=1;
void link(int x,int y,int c,int id)
{
    mp[++cnt].to=y;
    mp[cnt].nxt=head[x];
    mp[cnt].c=c;
    mp[cnt].id=id;
    head[x]=cnt;
}
void add(int x,int y,int c,int id)
{
//    cout<<"x: "<<x<<" y: "<<y<<" id: "<<id<<endl;
    link(x,y,c,id);
    link(y,x,0,id);
}
int cur[1010];
int dis[1010];
queue<int>q;
bool BFS()
{
    memset(dis,0,sizeof(dis));dis[s]=1;
    q.push(s);
    int x;
    while(!q.empty())
    {
        x=q.front();q.pop();
        for(int i=head[x];i;i=mp[i].nxt)
            if(!dis[mp[i].to]&&mp[i].c&&!book[mp[i].id])
                dis[mp[i].to]=dis[x]+1,q.push(mp[i].to);
    }
    return dis[t];
}
int dfs(int x,int f)
{
    if(x==t)return f;
    int rf=0,fl;
    for(int& i=cur[x];i;i=mp[i].nxt)
        if(dis[mp[i].to]==dis[x]+1&&mp[i].c&&!book[mp[i].id])
        {
            fl=dfs(mp[i].to,min(f,mp[i].c));
            if(fl)
            {
                rf+=fl;
                f-=fl;
                mp[i].c-=fl;
                mp[i^1].c+=fl;
                if(!f)break;
            }
        }
    return rf;
}
void Dinic()
{
    int mf=0,fl;
    while(BFS())
    {
        memcpy(cur,head,sizeof(head));
        while(fl=dfs(s,inf))mf+=fl;
    }
//    cout<<"flow: "<<mf<<endl;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            scanf("%d",&A[i][j]);
            sr[m*(i-1)+j]=i;
        }
    s=n*2+1;t=s+1;
    for(int i=1;i<=n;++i)
        add(s,i,1,0),add(i+n,t,1,0);
    int tc=cnt;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            add(sr[A[i][j]],i+n,1,A[i][j]);
    int x;
    for(int j=1;j<=m;++j)
    {
        for(int i=2;i<=tc;i+=2) mp[i].c=1,mp[i^1].c=0;
        Dinic();
        for(x=1;x<=n;++x)
            for(int i=head[x];i;i=mp[i].nxt)
                if(!book[mp[i].id]&&mp[i].to>n&&!mp[i].c)
                {
                    book[mp[i].id]=1;
                    B[mp[i].to-n][j]=mp[i].id;
                    C[x][j]=mp[i].id;
//                    cout<<"x: "<<x<<" y: "<<mp[i].to<<endl;
                    break;
                }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)printf("%d ",B[i][j]);
        puts("");
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)printf("%d ",C[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 201
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
ll n, a[MAX_N][MAX_N];

signed main(){
	cin >> n;
	string s;
	REP(i, n){
		cin >> s;
		REP(j, n) a[i][j] = s[j] - '0';
	}
	ll ret = 0;
	REP(i, n){
		ll used[MAX_N]; REP(i, n) used[i] = -1;
		bool valid = true;
		vector<ll> group[MAX_N];
		group[0].pb(i);
		used[i] = 0;
		ll tmp = 0;
		REP(k, n){
			for(ll v: group[k]){
				REP(j, n){
					if(a[v][j] == 1){
						// cout << j << " " << used[j] << endl;
						if(used[j] >= 0 && used[j] < k-1) valid = false;
						else if(used[j] == k) valid = false;
						else if(used[j] == -1){
							used[j] = k + 1;
							group[k+1].pb(j);
							tmp = k + 1;
						}
						else if(used[j] == k-1) continue;
					}
				}
			}
		}
		// REP(j, n) cout << used[j] << endl; 
		REP(j, n) if(used[j] == -1) valid = false;
		if(valid) ret = max(ret, tmp);
	}
	if(ret == 0) cout << -1 << endl;
	else cout << ret + 1 << endl;

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

bool cmp(const pair<ll,ll>& lv,const pair<ll,ll>& rv){
  return lv.second>rv.second;
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  
  map<ll,ll> ecnt,ocnt;
  rep(i,n){
    if(i&1)ocnt[a[i]]++;
    else ecnt[a[i]]++;
  }
  vector<pair<ll,ll>> x,y;
  for(const auto& elm:ecnt)x.emplace_back(elm);
  for(const auto& elm:ocnt)y.emplace_back(elm);
  sort(x.begin(),x.end(),cmp);
  sort(y.begin(),y.end(),cmp);
  ll m=n/2;
  x.emplace_back(0,0);
  y.emplace_back(0,0);
  if(x[0].first==y[0].first){
    ll s=x[0].second+y[1].second;
    ll t=y[0].second+x[1].second;
    cout<<(n-max(s,t))<<endl;
  }
  else{
    cout<<(n-x[0].second-y[0].second)<<endl;
  }


}


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

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

ll divide(ll a, ll b, ll m) {
    a %= m;
    return a * modinv(b, m) % m;
}

ll comb(ll n, ll r, ll m) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        n %= m;
        ans *= i;
        ans %= m;
    }
    for (int j = 1; j <= r; ++j) {
        ans = divide(ans, j, m);
    }
    return ans;
}


int main() {
    ll x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll t = (x + y) / 3;
    x -= t; y -= t;
    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << comb(x + y, min(x, y), 1000000007) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(){
std::string a,b;
std::cin >> a >> b;
int A=0,B=0;
if(a[0]=='A')
A=10;
else if(a[0]=='B')
A=11;
else if(a[0]=='C')
A=12;
else if(a[0]=='D')
A=13;
else if(a[0]=='E')
A=14;
else
A=15;
if(b[0]=='A')
B=10;
else if(b[0]=='B')
B=11;
else if(b[0]=='C')
B=12;
else if(b[0]=='D')
B=13;
else if(b[0]=='E')
B=14;
else
B=15;
if(A==B)
std::cout << '=' << std::endl;
else if(A<B)
std::cout << '<' << std::endl;
else
std::cout << '>' << std::endl;
}

Measured memory_bytes: 256
H, N, *AB = map(int, open(0).read().split())

dp = [0] * (H + max(AB[::2]))

for i in range(1, len(dp)):
    dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(AB)] * 2))

print(min(dp[H:]))

Measured memory_bytes: 3516
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    S = input()
    logging.info("Hello!")

    i = 1
    for c in S:
        if i % 2 == 1:
            if c == "L":
                print("No")
                exit()

        if i % 2 == 0:
            if c == "R":
                print("No")
                exit()
        i += 1
            
    print("Yes")
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4584
#include<iostream>
#define MAX 101
#define INF (2<<29)
using namespace std;
int main(){
  int n;
  cin>>n;
  int graph[MAX][MAX];
  
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      cin>>graph[i][j];
      if(graph[i][j]==-1)graph[i][j]=INF;
    }
  }
  
  int visited[MAX];
  int min[MAX];
  for(int i=1;i<n+1;i++){
    visited[i]=0;
    min[i]=INF;
  }
  
  min[1]=0;
  int ans=0;
  while(true){
    int a=-1;
    for(int i=1;i<n+1;i++){
      if(visited[i]==0&&(a==-1||min[i]<min[a]))a=i;
    }

    if(a==-1)break;
    visited[a]=1;
    ans +=min[a];

    for(int i=1;i<n+1;i++){
      min[i]=min[i]<graph[a][i] ? min[i]:graph[a][i];
    }
  }
  cout<<ans<<endl;
  return 0;
}  

Measured memory_bytes: 0
n=int(input())
name=[list(input()) for _ in range(n)]
march=[0]*5
for s in name:
  if s[0]=='M':
    march[0]=march[0]+1
  if s[0]=='A':
    march[1]=march[1]+1
  if s[0]=='R':
    march[2]=march[2]+1
  if s[0]=='C':
    march[3]=march[3]+1
  if s[0]=='H':
    march[4]=march[4]+1
march.sort()
a=0
if march[2]==0:
  print(0)
else:
  a=a+march[0]*march[1]*march[2]
  a=a+march[0]*march[1]*march[3]
  a=a+march[0]*march[1]*march[4]
  a=a+march[0]*march[2]*march[3]
  a=a+march[0]*march[2]*march[4]
  a=a+march[0]*march[3]*march[4]
  a=a+march[1]*march[2]*march[3]
  a=a+march[1]*march[2]*march[4]
  a=a+march[1]*march[3]*march[4]
  a=a+march[2]*march[3]*march[4]
  print(a)

Measured memory_bytes: 20288
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200005
#define INF 2147483640
#define LL long long
using namespace std;
int n,sum,l[maxn],r[maxn],mx[maxn],sx[maxn],siz[maxn];
LL ans;
char s[maxn];
struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;
void addedge(int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
void dfs1(int u,int fa)
{
	siz[u]=s[u]-'0';
	for(node *p=head[u];p;p=p->nxt)
	{
		int v=p->v;
		if(v==fa) continue;
		dfs1(v,u);
		siz[u]+=siz[v];
		if(mx[v]+1>mx[u]) sx[u]=mx[u],mx[u]=mx[v]+1;
		else if(mx[v]+1>sx[u]) sx[u]=mx[v]+1;
	}
}
void dfs2(int u,int fa,int len)
{
	r[u]=len>mx[u]?mx[u]:max(len,sx[u]);
	l[u]=s[u]-'0'?0:(sum-siz[u]?len:INF);
	if(fa)
	{
		if(len-1==mx[u]) ans++;
		else if(len-1<mx[u]) ans+=siz[u]<sum;
		else ans+=siz[u]>0;
	}
	for(node *p=head[u];p;p=p->nxt)
	{
		int v=p->v;
		if(v==fa) continue;
		if(siz[v]) l[u]=min(l[u],mx[v]+1);
		if(mx[u]==mx[v]+1) dfs2(v,u,max(len,sx[u])+1);
		else dfs2(v,u,max(len,mx[u])+1);
	}
}
int main()
{
	scanf("%d",&n);
	ncnt=&edge[0];
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) sum+=s[i]-'0';
	dfs1(1,0); dfs2(1,0,0);
	for(int i=1;i<=n;i++)
		if(l[i]<=r[i]) ans+=1ll*(r[i]-l[i]+1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 19200