akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	ll s=n/(a+b)*a;
	n%=a+b;
	if(n<=a) cout<<n+s<<endl;
	else cout<<a+s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int Max = 200;

int a[Max];
void InsertSort(int a[], int N)
{
    for(int i=0; i<N; i++)
    {
        int v = a[i];
        int j= i-1;
        while(j>=0 && a[j]>v)
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for(int k=0; k<N-1; k++)
            cout << a[k] << " ";
        cout << a[N-1] << endl;
    }
}
int main()
{
    int N;
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> a[i];
    }
    InsertSort(a, N);
    return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    ll x[n];rep(i,0,n-1)cin>>x[i];
    ll l,q;cin>>l>>q;
    ll dp[n][35];rep(i,0,34)dp[n-1][i]=n-1;
    for(ll i=n-2;i>=0;i--){
        dp[i][0]=upper_bound(x,x+n,x[i]+l)-x-1;
        if(dp[i][0]==n)dp[i][0]=n-1;
        rep(j,1,34){
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
   /* rep(i,0,n-1){cout<<i<<":";
        rep(j,0,5){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    while(q--){
        ll a,b;cin>>a>>b;if(a>b)swap(a,b);a--;b--;
        ll ans=0;
        if(b==n-1){
            while(a<b){
                ll t=lower_bound(dp[a],dp[a]+35,b)-dp[a]-1;
                if(t==-1)t++;
                ans+=(ll)pow(2,t);
                a=dp[a][t];
            }
        }else{
            while(a<b){
                ll t=upper_bound(dp[a],dp[a]+35,b)-dp[a]-1;
                if(t==-1)t++;
                ans+=(ll)pow(2,t);
                a=dp[a][t];
            }
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;


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

	int n;
	string s, u;
	char c;
	ll x, y;
	cin >> n;
	ll ans = 0, btc = 0;
	forn(i, 0, n){
		cin >> s >> u;
		if(u == "BTC"){
			int m = s.size();
			y = stoll(s.substr(m-8, 8));
			x = stoll(s.substr(0, m-8-1));
			x = x*100000000+y;
			btc += x*380000;
		}else{
			x = stoll(s);
			ans += x;
		}
	}
	double r = btc;
	r /= 100000000;
	cout << r+ans << endl;
//380000 - 0.1 btc
//10000 - x

}




Measured memory_bytes: 3772
import java.util.Scanner;
class Main{
 public static void main(String args[]){
Scanner sc=new Scanner(System.in);
String a[]=new String[3];
for(int i=0;i<=2;i++) {
	a[i]=sc.next();
}
	

String X=a[1];
System.out.println("A"+X.charAt(0)+"C");

 }
  }


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

using namespace std;

typedef long long ll;

const int MXN = 1e6 + 10;
int d[MXN], ld;
int c[MXN], lc;
int sum[MXN];
char str[MXN];

int main ()
{
	int n;
	scanf("%d", &n);
	scanf("%s", str);
	sum[0] = 0;
	ld = lc = 0;
	for (int i = 0; i < n; i++)
	{
		if (str[i] == 'D')
			d[++ld] = i + 1;
		else if (str[i] == 'C')
			c[++lc] = i + 1;
		sum[i + 1] = sum[i] + (str[i] == 'M');
	}
	// cout << "ld = " << ld << endl;
	// cout << "lc = " << lc << endl;
	int k, q;
	scanf("%d", &q);
	while (q--)
	{
		ll ans = 0;
		scanf("%d", &k);
		ll s = 0;
		for (int i = 1, l = 1, r = 1; i <= ld; i++)
		{
			while (l <= lc && c[l] <= d[i])
			{
				s -= 1ll * sum[c[l]];
				l++;
			}
			while (r <= lc && c[r] < d[i] + k)
			{
				s += 1ll * sum[c[r]];
				r++;
			}
			assert(r >= l);
			ll tmp = s - 1ll * (r - l) * sum[d[i]];
			// cout << "i = " << i << endl;
			// cout << "tmp = " << tmp << endl;
			// cout << "l = " << l << endl;
			// cout << "r = " << r << endl;
			// cout << "s = " << s << endl;
			ans = ans + tmp;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double tansin = h*30+m/2;
    double tyoushin = 6*m;
    double deg = abs(tansin-tyoushin);
    double PI = acos(-1);
    double rad = deg*PI/180;
    double ans = a*a+b*b-2*a*b*cos(rad);
    ans = sqrt(ans);
    printf("%.10f\n",ans);
}

Measured memory_bytes: 4260
# -*- coding: utf-8 -*-


def run_prime_factorization(max_number: int):
    from math import sqrt

    ans = dict()
    remain = max_number

    for j in range(2, int(sqrt(max_number)) + 1):
        if remain % j == 0:
            count = 0

            while remain % j == 0:
                count += 1
                remain //= j

            ans[j] = count

    if remain != 1:
        ans[remain] = 1

    return ans


def main():
    n, p = map(int, input().split())
    ans = 1

    # See:
    # https://www.youtube.com/watch?v=z0bIhkaSXY4
    results = run_prime_factorization(p)

    for base, exponent in results.items():
        ans *= base ** (exponent // n)

    print(ans)


if __name__ == '__main__':
    main()


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        string S[100];
        for(int i = 1; i <= n; i++) cin >> S[i];
        vector<int> query[100];
        for(int i = n; i >= 1; i--) {
            int depth = S[i].size() - 1;
            if(S[i].back() <= '9' && S[i].back() >= '0') {
                query[depth].push_back((int)(S[i].back() - '0'));
                continue;
            }
            if(S[i].back() == '*') {
                int now = 1;
                for(int j = 0; j < query[depth+1].size(); j++) {
                    now *= query[depth+1][j];
                }
                query[depth].push_back(now);
                query[depth+1].clear();
            }
            if(S[i].back() == '+') {
                int now = 0;
                for(int j = 0; j < query[depth+1].size(); j++) {
                    now += query[depth+1][j];
                }
                query[depth].push_back(now);
                query[depth+1].clear();
            }
        }
        cout << query[0][0] << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(n);
  if(n<1200) OUT("ABC");
  else if(n<2800) OUT("ARC");
  else OUT("AGC");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

struct Point{
    int x,y;
};

int main(){
    int h,w; cin >> h >> w;
    char M[h+2][w+2];
    queue<Point> Q;
    int ans = 0, m = h*w;

    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++){
            if(i == 0 || i == h+1 || j == 0 || j == w+1){
                M[i][j] = '&';
                continue;
            }

            cin >> M[i][j];
            if(M[i][j] == '#'){
                Point b; b.x = i; b.y = j;
                Q.push(b); m--;
            }
        }
    }
    if(m == 0){
        cout << 0 << endl; return 0;
    }
    
    int c = h*w - m, cn = 0;
    while(m > 0){
        if(c == 0){
            ans++; c = cn; cn = 0;
        }
        Point now = Q.front();
        Q.pop();

        Point n = now;

        n.x = now.x+1; n.y = now.y;
        if(M[n.x][n.y] == '.'){
            M[n.x][n.y] = '#'; Q.push(n); m--;
            cn++;
        }

        n.x = now.x-1; n.y = now.y;
        if(M[n.x][n.y] == '.'){
            M[n.x][n.y] = '#'; Q.push(n); m--;
            cn++;
        }

        n.x = now.x; n.y = now.y+1;
        if(M[n.x][n.y] == '.'){
            M[n.x][n.y] = '#'; Q.push(n); m--;
            cn++;
        }

        n.x = now.x; n.y = now.y-1;
        if(M[n.x][n.y] == '.'){
            M[n.x][n.y] = '#'; Q.push(n); m--;
            cn++;
        }
        c--;
    }
    if(c > 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9360
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

struct Node{
	Node *left,*right;
	
	Node():left(0),right(0){}
	Node(Node* l,Node* r):left(l),right(r){}
	~Node(){delete left;delete right;}
};

int parse(const string& s,int index,Node* n)
{
	index++;
	if(s[index]=='('){
		n->left=new Node;
		index=parse(s,index,n->left);
	}
	index++;
	if(s[index]=='('){
		n->right=new Node;
		index=parse(s,index,n->right);
	}
	index++;
	return index;
}

void print(Node* n)
{
	if(!n)
		return;
	//if(!n->left && !n->right){
	//	printf("o");
	//	return;
	//}
	printf("(");
	print(n->left);
	printf(",");
	print(n->right);
	printf(")");
}

Node* tree_and(Node* n1,Node* n2)
{
	if(!n1 || !n2)
		return NULL;
	Node* n=new Node;
	if(n1->left && n2->left)
		n->left=tree_and(n1->left,n2->left);
	if(n1->right && n2->right)
		n->right=tree_and(n1->right,n2->right);
	return n;
}

Node* tree_or(Node* n1,Node* n2)
{
	if(!n1 && !n2)
		return NULL;
	Node* n=new Node;
	if(n1 && n2){
		if(n1->left || n2->left)
			n->left=tree_or(n1->left,n2->left);
		if(n1->right || n2->right)
			n->right=tree_or(n1->right,n2->right);
	}
	else if(n1){
		if(n1->left)
			n->left=tree_or(n1->left,NULL);
		if(n1->right)
			n->right=tree_or(n1->right,NULL);
	}
	else{
		if(n2->left)
			n->left=tree_or(NULL,n2->left);
		if(n2->right)
			n->right=tree_or(NULL,n2->right);
	}
	return n;
}

int main()
{
	for(string op,s1,s2;cin>>op>>s1>>s2;){
		//dump(s1);
		//dump(s2);
		Node n1,n2;
		parse(s1,0,&n1);
		parse(s2,0,&n2);
		//print(&n1);puts("");
		//print(&n2);puts("");
		
		Node* res;
		if(op=="i")
			res=tree_and(&n1,&n2);
		else
			res=tree_or(&n1,&n2);
		print(res);puts("");
		
		delete res;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
	ll n,k;
	cin>>n>>k;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	sort(all(v));
	ll mn = 1000000000000000000LL;
	rep(i,0,v.sz-k+1){
		mn = min(mn,v[i+k-1]-v[i]);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,n-2) {
        string tmp = s.substr(i,3);
        if (tmp == "ABC")
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main () {

    int n;
    std::cin >> n;
    std::vector< std::pair<int, int> > d(n);
    for(int i = 0; i < n; i++) std::cin >> d.at(i).first >> d.at(i).second;

    bool ans = false;
    for(int i = 1; i < n - 1; i++) {
        if(d.at(i - 1).first == d.at(i - 1).second
        && d.at(i).first == d.at(i).second
        && d.at(i + 1).first == d.at(i + 1).second) ans = true;
    }

    if(ans) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int a; cin >> a;
	string s; cin >> s;
	if(a >= 3200) cout << s << endl;
	else cout <<"red" <<endl;
	return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    //
    ll L = 0;
    ll R = 1e9;
    while(R-L>1)
    {
        ll x = (L + R) / 2;
        bool okay = [&]
        {
            ll total = 0;
            rep(i, A.size()) total += (A[i] - 1) / x;
            return total <= K;
        }();
        //
        okay ? R = x : L = x;
    }
    cout << R;
    //
    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

struct BIT{
	int N;
	vector<int> bit;
	void init(int n){
		N=n;
		bit.resize(n+1);
	}
	int sum(int i){		//i?????????a[0]+..a[i-1]
		int s=0;
		while(i>0){
			s+=bit[i];
			i-=(i&-i);
		}
		return s;
	}
	void add(int i,int x){	//a[i]+=x (0-indexed)
		i++;
		while(i<=N){
			bit[i]+=x;
			i+=(i&-i);
		}
	}
}bit;

int cnt[26],cnthalf[26];
int N;
typedef long long ll;
vector<int> c2p[26];
bool moved[400000];
ll getinversion(vector<int> a){
	int N=a.size();
	vector<int> p(N);
	rep(i,N) p[a[i]]=i;
	ll ret=0;
	bit.init(N);
	rep(i,N) bit.add(i,1);
	rep(i,N){
		ret+=bit.sum(p[i]);
		bit.add(p[i],-1);
	}
	return ret;
}
ll calc(string a,string b){
	assert(a.size()==b.size());
	int N=a.size();
	vector<int> A(N),B(N),iB(N);
	int I=0;
	rep(c,26){
		int J=I;
		rep(i,N){
			if(a[i]=='a'+c) A[i]=I++;
			if(b[i]=='a'+c) B[i]=J++;
		}
	}
	rep(i,N) iB[B[i]]=i;
	rep(i,N) B[iB[A[i]]]=i;
	return getinversion(B);
}
ll solve(){
	string s;
	cin>>s;
	N=s.size();
	rep(i,N){
		if(i==N/2){
			rep(j,26) cnthalf[j]=cnt[j];
		}
		cnt[s[i]-'a']++;
		c2p[s[i]-'a'].pb(i);
	}
	rep(i,26) if(cnt[i]%2) return -1;
	vector<int> le,ri;
	rep(i,26){
		if(cnthalf[i]<cnt[i]/2){	//ri to le
			for(int j=cnthalf[i];j<cnt[i]/2;j++) ri.pb(c2p[i][j]);
		}else{
			for(int j=cnt[i]/2;j<cnthalf[i];j++) le.pb(c2p[i][j]);
		}
	}
	sort(all(ri));
	sort(all(le));
	assert(le.size()==ri.size());
	int K=le.size();
	ll ans=(ll)K*K;
	rep(i,K) ans+=N/2-1-le[K-1-i]-i;
	rep(i,K) ans+=ri[i]-N/2-i;
	rep(i,K) moved[le[i]]=moved[ri[i]]=1;
	string a,b;
	rep(i,N/2) if(!moved[i]) a+=s[i];
	rep(i,K) a+=s[ri[i]];
	rep(i,K) b+=s[le[i]];
	rep(i,N/2) if(!moved[i+N/2]) b+=s[i+N/2];
	reverse(all(b));
	ans+=calc(a,b);
	return ans;
}
int main(){
	cout<<solve()<<endl;
}

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

int main(){
  int N;
  cin>>N;
  
  int x=0;
  
  for(int j=1;j<=N;j++){

  int sum=0;
  
  for(int i=1;i<=j;i++){
    if(j%i==0&&j%2!=0){
      sum++;
    }
    
    if(i==j&&sum==8){
      x++;
    }
    
        
  }
 
  
  }
  
    cout<<x<<endl;
}

      

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

int main(){
  int n,m,i,j,k;
  cin>>n>>m;
  int K[n];
  int A[n][m];
  for(i=0;i<n;i++){
    cin>>K[i];
    for(j=0;j<K[i];j++){
      cin>>A[i][j];
    }
  }
  int cnt1=0,cnt2;
  for(k=0;k<m;k++){
    cnt2=0;
    for(i=0;i<n;i++){
      for(j=0;j<K[i];j++){
        if(A[i][j]==k+1){
          cnt2++;
          break;
        }
      }
    }
    if(cnt2==n){
      cnt1++;
    }
  }
  cout<<cnt1;
}

Measured memory_bytes: 256
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 1000000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define min_heap priority_queue<int, vector<int>, greater<int>>
#define max_heap priority_queue<int>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
bool sortbytwo(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first>b.first) return true;
	else if(a.first==b.first) return a.ss<b.ss;
	else return false;
}
bool sortbystring(const string &a, const string &b)
{
	string c=a+b;
	string d=b+a;
	if(c>=d) return true;
	else return false;
}
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
}
//vector<int> graph[200090];
//int vi[200090];
//void dfs(int i)
//{
//	vi[i]=1;
//	for(int j=0;j<graph[i].size();j++)
//	{
//		if(vi[graph[i][j]]==0)
//		{
//			dfs(graph[i][j]);
//		}
//	}
//}
int main()
{
	FAST
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++) a[i]=0;
	int cnt=0;
	for(int i=0;i<m;i++)
	{
		int a1;
		cin>>a1;	
		string s;
		cin>>s;
		if(s=="AC")
		{
			if(a[a1-1]!=-1)
			{
			
				sum+=a[a1-1];
				cnt++;
			}
			a[a1-1]=-1;
		}
		else
		{
			if(a[a1-1]!=-1)
			{
				a[a1-1]++;
			}
		}
	} 
	cout<<cnt<<" "<<sum;
	return 0;
}
















Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
constexpr auto INF = 2147483647;
typedef long long ll;

void DebugGrid(int row, int column, auto table){
  cout << endl;
  rep(i,row){
    rep(j,column) cout << table[i][j] << " ";
    cout << endl;
  }
}

int blocks[300];
int DP[301][301];


int main(){

  int n;
  while(true){
    cin >> n;
    if(n==0)break;
    rep(i,n) cin >> blocks[i];
    rep(i,n)rep(j,n) {
      DP[i][j] = 0;
      }

    for(int k = 0; k<n; k++){
      for(int i = 0; i<n-k; i++){
        if(k==0)continue;
        if(k==1 && abs(blocks[i]-blocks[i+1])<2) DP[i][i+1] = 2;
        else if(k>1){
          if(DP[i+1][i+k-1]==k-1 && abs(blocks[i]-blocks[i+k])<2) DP[i][i+k] = DP[i+1][i+k-1] +2;
          for(int j=i; j<i+k; j++){
            DP[i][i+k] = max(DP[i][i+k],DP[i][j]+DP[j+1][i+k]);
          }
        }
      }
    }
    // DebugGrid(n,n,DP);
    cout << DP[0][n-1] << endl;
  }
  return 0;
}


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

int main()
{
 int N;
  cin >> N;
  int m,count;
  m =200000;
  count =0;
  int p;
  for(int i=0;i<N;i++)
  {
    cin >> p;
    if (p<=m)
    {
      m=p;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
def log(n):
    cnt=0
    for i in range(10):
        n=n//10
        cnt+=1
        if(n==0):
            break
    return cnt

N=int(input())
ans=0
for i in range(1,N+1):
    if(log(i)%2==1):
        ans+=1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d;std::cin >> a >> b >> c >> d;
  string ans = "";
  re(i, c-a) ans+='R';
  re(i, d-b) ans+='U';
  ans+="U";
  re(i, c-a+1) ans+='L';
  re(i, d-b+1) ans+='D';
  ans+='R';
  re(i, d-b) ans+='U';
  re(i, c-a+1) ans+='R';
  re(i, d-b+1) ans+='D';
  re(i, c-a+1) ans+='L';
  ans+='U';
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    int t;
    map<int, int> m;
    cin >> n;
    while (n--)
    {
        cin >> t;
        if (t % 4 == 0)
            m[4]++;
        else if (t & 1)
            m[1]++;
        else
            m[2]++;
    }
    if (m[1] <= m[4] || (m[1] <= m[4] + 1 && !m[2]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main(){
  int N; cin >> N;
  int W[N]; int sum=0;
  for(int i=0; i<N; i++){
    cin >> W[i];
    sum = sum + W[i];
  }
  
  int s1=0; int min=sum;
  for(int i=0; i<N-1; i++){
    s1 = s1 + W[i];
    if(abs(sum-2*s1)<min){min = abs(sum-2*s1);}
  }
  
  cout << min;
  
  return 0;
}

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

int		main(void)
{
	int N, M;

	cin >> N >> M;
	vector<bitset<30>> foods(N);
	for (int i = 0; i < N; i++)
	{
		int K;

		cin >> K;
		for (int j = 0; j < K; j++)
		{
			int like;

			cin >> like;
			foods[i].set(like - 1);
		}
	}
	for (int i = 1; i < N; i++)
	{
		foods[0] &= foods[i];
	}
	cout << foods[0].count() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define maxN 1000001
#define mod 1000000007
#define maxLL 1000000000000000000
#define PI 3.14159265358979323846264338327950L
typedef long long ll;

bool compared(int a,int b){
	return a < b;
}

int cmp(const void *a,const void *b){
	return(*(int*)b - *(int*)a);
}

int GCD(int a,int b){
	return b?GCD(b,a%b):a;
}

int LCM(int a,int b){
	return a/__gcd(a,b)*b;
}

void f(ll n){
	if(n == 0)return;
	n--;
	f(n/26);
	putchar('a'+(n%26));
}

int main(){
	char a[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	ll n;
	cin>>n;
	f(n);
	return 0;
}

Measured memory_bytes: 3628
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<climits>

using namespace std;

const int MAX = 7368791;

int main(){
  int m,n;
  while( cin >> m >> n , m|n ) {
    bool isntprime[MAX+1];
    memset(isntprime,false,sizeof isntprime);
    //fill(isntprime,isntprime+MAX,false);
    //era(m,n);
    for(int i=m;;++i) {
      if( !isntprime[i] ) {
	if( n ) --n;
	else {
	  cout<< i << endl;
	  break;
	}
	for(int j=i;j<=MAX;j+=i) isntprime[j] = true;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 10308
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  int n;
  // int m;
  cin >> n;
  // cin >> m;
  map<int, int> m;
  int i;
  while(n--) {
    cin >> i;
    if(m[i] == 1) {
      cout << "NO";
      return 0;
    }
    m[i] = 1;
  }
  cout << "YES"; 


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



Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll k, a, b, c = 0;
    cin >> k >> a >> b;
    if(k == 1)
        cout << "OK";
    else{
        for(int i = a; i <= b; ++i){
            if(i%k == 0){
                ++c;
                cout << "OK";
                break;
            }
        }
        if(c == 0)
            cout << "NG";
    }
    return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-8;


int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};

int main(){
	int sum;
	while(~scanf("%d",&sum)){
		if(sum==0) break;
		for(int i=0;i<9;i++){
			int val;
			scanf("%d",&val);
			sum-=val;
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  string S;ll K,N,i,j;
  cin>>S>>K;N=S.size();
  vector<string>SUB;
  FOR(j,1,K+1)REP(i,N-j+1)SUB.push_back(S.substr(i,j));
  sort(ALL(SUB));j=0;
  REP(i,K-1){
    j++;
    while(SUB.at(j-1)==SUB.at(j))j++;
  }
  cout<<SUB.at(j)<<endl;
  return 0;
}

Measured memory_bytes: 1660
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let _n: usize = read();
    let m: usize = read();
    let x: i32 = read();
    let a: Vec<i32> = (0..m).map(|_| read()).collect();
    let l = a.iter().take_while(|&&a_i| a_i < x).count();
    println!("{}", min(l, m - l));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
	int dist[100][100];
	int a,b,c,d,e;
	int n,k;
	while(cin>>n>>k,n||k){
		rep(i,100)rep(j,100)dist[i][j]=INF;
		rep(i,100)dist[i][i]=0;
		while(k--){
			cin>>a;
			if(a==0){
				cin>>a>>b;
				a--;b--;
				cout<<(dist[a][b]==INF?-1:dist[a][b])<<endl;
			}
			else{
				cin>>c>>d>>e;
				c--;d--;
				dist[c][d]=dist[d][c]=min(dist[c][d],e);
				rep(i,n){
					rep(j,n){
						dist[i][j] = min(dist[i][j],dist[i][c]+dist[c][d]+dist[d][j]);
						dist[i][j] = min(dist[i][j],dist[i][d]+dist[d][c]+dist[c][j]);
					}
				}
			}
		}
	}
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   ll a[10] ={0};
   string m = "MARCH";
   rep (i, n) {
      string s;
      cin >> s;
      auto p = m.find(s[0]);
      if (p == string::npos) continue;
      a[p]++;
   }

   ll ans = 0;
   rep (i, 5) {
      repp (j, i+1, 5) {
         repp (k, j+1, 5) {
            ans += a[i] * a[j] * a[k];
         }
      }
   }
   cout << ans << endl;

   return 0;
}

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

using namespace std;

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



int main(){

  int sumn=0;
  string n;
  cin >> n;
  rep(i,n.size()){
    if(n[i]=='9')sumn++;
  }
  int d = n.size(),ret;
  if(d==1){
    ret = (int)(n[0]-'0');
  } else {
    int ind=0;
    while(n[ind]=='9'){ind++;}
    if(ind==n.size())ret = 9*n.size();
    else if(sumn==n.size()-1 && n[0]!='9'){
      ret = (int)(n[0]-'0')+9*(n.size()-1);
    } else if(ind==0){
      ret = 9*(n.size()-1)+(int)(n[0]-'0')-1;
    } else {
      ret = 8+9*(n.size()-1);
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    int N; cin>>N;
    vec a(N); REP(i,N) cin>>a[i];
    vec b(N); REP(i,N) b[i] = a[i]%4;
    vec count(3);
    REP(i,N){
        if(b[i]==1||b[i]==3) count[1]++;
        else if(b[i]==2) count[2]++;
        else count[0]++;
    }
    bool ans = false;
    if(count[0]+1>=count[1]+count[2]) ans=true;
    if(count[0]==count[1]&&count[2]>1) ans = true;
    if(ans) Out("Yes");
    else Out("No");
}



Measured memory_bytes: 1792
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))
ok_lst = [x for x in range(0, 10) if x not in D]
stack = deque([x for x in ok_lst if x != 0])
while len(stack) > 0:
    now_num = stack.popleft()
    if now_num >= n:
        print(now_num)
        break
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        stack.append(int(next_num))

Measured memory_bytes: 5692
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      h: usize,
      w: usize,
      d: usize,
      a: [[Usize1; w]; h],
      q: usize,
      lr: [(Usize1, Usize1); q]
   }
   let mut dir = vec![(0, 0);h*w];
   for i in 0..h {
      for j in 0..w {
         dir[a[i][j]] = (i as i32, j as i32);
      }
   }
   let mut mag = vec![vec![]; d];
   let mag_dif = |(x1, y1): (i32, i32), (x2, y2): (i32, i32)| (x1 - x2).abs() + (y1 - y2).abs();
   for i in 0..d {
      mag[i].push(0);
      let mut j = 1;
      while i + d * j < h * w {
         let x = mag[i][j - 1] + mag_dif(dir[i + d * (j - 1)], dir[i + d * j]);
         mag[i].push(x);
         j += 1;
      }
   }
   for (l, r) in lr {
      let i = l % d;
      println!("{}", mag[i][r / d] - mag[i][l / d]);
   }
}


Measured memory_bytes: 11456
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        string st;
        cin>>st;
        if(st[0]==st[1]||st[1]==st[2]||st[2]==st[3])
            cout<<"Bad";
        else
            cout<<"Good";
    }
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template<int mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

//pow
template<typename T, typename U>
T pow(T k, U n, T unity = 1) {
    while (n > 0) {
        if (n & 1) {
            unity *= k;
        }
        k *= k;
        n >>= 1;
    }
    return unity;
}

constexpr int MOD = 1e9 + 7;
vector<int> childcnt;
vector<vector<int>> tree;
vector<mint<MOD>> ans;
int n;

int dfs1(int v, int p) {
    childcnt[v] = 0;
    for (int &u : tree[v]) {
        if (u == p) continue;
        childcnt[v] += dfs1(u, v);
    }
    return childcnt[v] + 1;
}

void dfs2(int v, int p) {
    ans[v] = 1;
    ans[v] -= mint<MOD>(1) * pow(pow(mint<MOD>(2), MOD - 2), n - 1);
    for (int &u : tree[v]) {
        if (u == p) {
            ans[v] -= (pow(mint<MOD>(2), n - childcnt[v] - 1) - mint<MOD>(1)) * pow(pow(mint<MOD>(2), MOD - 2), n - 1);
        }
        else {
            dfs2(u, v);
            ans[v] -= (pow(mint<MOD>(2), childcnt[u] + 1) - mint<MOD>(1)) * pow(pow(mint<MOD>(2), MOD - 2), n - 1);
        }
    }
    ans[v] *= pow(mint<MOD>(2), MOD - 2);
}

int main() {
    cin >> n;
    tree.resize(n);
    childcnt.resize(n, 0);
    ans.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    mint<MOD> sol = 0;
    for (int i = 0; i < n; i++) {
        // cout << i << " : " << ans[i] << endl;
        sol += ans[i];
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 24704
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	a, _ := strconv.Atoi(stringLineScan())
	b, _ := strconv.Atoi(stringLineScan())
	m, _ := strconv.Atoi(stringLineScan())
	as := make([]int, a)
	bs := make([]int, b)
	for i := 0; i < a; i++ {
		as[i], _ = strconv.Atoi(stringLineScan())
	}
	for i := 0; i < b; i++ {
		bs[i], _ = strconv.Atoi(stringLineScan())
	}
	ans := min(as) + min(bs)
	for i := 0; i < m; i++ {
		x, _ := strconv.Atoi(stringLineScan())
		y, _ := strconv.Atoi(stringLineScan())
		c, _ := strconv.Atoi(stringLineScan())
		x--
		y--
		t := as[x] + bs[y] - c
		if t < ans {
			ans = t
		}
	}
	fmt.Println(ans)
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}


Measured memory_bytes: 4864
from functools import lru_cache
while True:
    N = int(input())
    if N==0:
        break
    W = list(map(int, input().split()))
    assert len(W) == N


    @lru_cache(maxsize=None)
    def solve(l, r):
        assert l<=r
        if (r-l)%2==1:
            return False
        if r-l==2:
            return abs(W[l]-W[l+1])<=1

        if solve(l+1, r-1) and abs(W[l]-W[r-1])<=1:
            return True
        for i in range(l+2, r, 2):
            if solve(l, i) and solve(i, r):
                return True
        return False
        # return (solve(l, r-2) and solve(r-2, r)) \
        #     or (solve(l, l+2) and solve(l+2, r)) \
        #     or


    dp = [0]*(N+1)
    for i in range(1, N+1):
        ma = 0
        for j in range(i-1, -1, -1):
            ma = max(ma, dp[j]+solve(j, i)*(i-j))
            #if (j-i)%2==0:
            #    print(f"j={j}, i={i}, dp={solve(j,i)}")
        dp[i] = ma
    #print(dp)
    print(dp[-1])



Measured memory_bytes: 14108
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N;
	cin >> N;

	int before;
	int count = 0;
	int ans = 0;
	for (int i = 0; i < N;++i) {
		int h;
		cin >> h;
		if (i != 0) {
			if (before >= h)count++;
			else {
				ans = max(ans, count);
				count = 0;
			}
		}
		before = h;
	}
	ans = max(ans, count);

	cout << ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<set>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    set<int> A;
    cin >> N;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        if(A.empty()){
            A.insert(tmp);
        }else{
            if(A.find(tmp)==A.end()){
                A.insert(tmp);
            }else{
                A.erase(tmp);
            }
        }
    }
    int ans = A.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int N;
    string a;
    cin >> a >> N;
    string ans;
    for(int i = 0; i < a.length(); i += N){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
} 

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

int main(){
    int s,w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a=sc.nextInt(),b=sc.nextInt();
		System.out.println((a*b)-(a+b)+1);
	}

}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define LiangJiaJun main
#define INF 2147483647
using namespace std;
int n,k,h[100004];
int f[100004];
int w33ha(){
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    f[1]=0;
    f[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        f[i]=INF;
        for(int j=1;i-j>=1&&j<=k;j++){
            f[i]=min(f[i],f[i-j]+abs(h[i]-h[i-j]));
        }
    }
    printf("%d\n",f[n]);
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d%d",&n,&k)!=EOF)w33ha();
    return 0;
}



Measured memory_bytes: 1024