akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int soredake(int point, int kazu, int bonasu, int goal) {
  int tokukazu = goal / point;
  if (goal % point > 0) {
    tokukazu++;
  }
  if (tokukazu > kazu) {
    tokukazu = kazu;
  }
  return tokukazu;
}

int search(vector<vector<int>> questions, int goal) {

  int minimum = 0;
  for (int i = 0; i < questions.size(); i++) {
    minimum += questions.at(i).at(1);
  }
  for (int i = 0; i < questions.size(); i++) {
    int point = questions.at(i).at(0);
    int kazu = questions.at(i).at(1);
    int bonasu = questions.at(i).at(2);
    int goukei = questions.at(i).at(3);

    vector<vector<int>> q = questions;
    q.erase(q.begin() + i);
    if (goukei < goal) {
      int nokori = search(q, goal - goukei) + kazu;
      if (nokori < minimum) {
        minimum = nokori;
      }
    } else {
      int nokori = soredake(point, kazu, bonasu, goal);
      if (nokori < minimum) {
        minimum = nokori;
      }
    }
  }
  return minimum;
}

int main() {
  int d, g;
  cin >> d >> g;

  vector<vector<int>> questions(d, vector<int>(4));
  for (int i = 0; i < d; i++) {
    questions.at(i).at(0) = 100 * (i + 1);
    cin >> questions.at(i).at(1);
    cin >> questions.at(i).at(2);
    questions.at(i).at(3) =
        questions.at(i).at(0) * questions.at(i).at(1) + questions.at(i).at(2);
  }

  cout << search(questions, g) << endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> A;

	cin >> N;
	A.resize(N+1,0);
	for(int i = 1; i <= N; i++)
		cin >> A[i];
	cerr << endl;

	llong ans = 0;
	for(int i = N; i >= 1; i--){
		ans += A[i]/2;
		A[i] %= 2;
		ans += min(A[i], A[i-1]);
		A[i-1] -= min(A[i], A[i-1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#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 fi first
#define se 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 T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(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 v_bool = vector<bool>;
using v_Pii = 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;



signed main(){

    int H, W, M; cin >> H >> W >> M;
    vec sh(H, 0), sw(W, 0);
    set<Pii> s;
    REP(i, M){
        int h, w; cin >> h >> w;
        h--; w--;
        sh[h]++;
        sw[w]++;
        s.insert(Pii(h, w));
    }

    int Mh = 0;
    vec vh;
    REP(i, H){
        if(sh[i] > Mh){
            Mh = sh[i];
            vh = vec({i});
        }else if(sh[i] == Mh){
            vh.pb(i);
        }
    }

    int Mw = 0;
    vec vw;
    REP(i, W){
        if(sw[i] > Mw){
            Mw = sw[i];
            vw = vec({i});
        }else if(sw[i] == Mw){
            vw.pb(i);
        }
    }

    int ans = Mh + Mw;
    if(SZ(vh) * SZ(vw) <= M){
        bool f = false;
        REP(i, SZ(vh)) REP(j, SZ(vw)){
            if(s.count(Pii(vh[i], vw[j])) == 0) f = true;
        }
        if(!f) ans--;
    }

    Out(ans);

    return 0;
}


Measured memory_bytes: 35048
#include <bits/stdc++.h>
using namespace std;
constexpr int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
inline int mow(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      b--;
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
int cal (vector<int>& v) {
  if (v.size() <= 1) return 0;
  int k = v.size();
  v.insert(v.begin(), 0);
  vector<int> dp(k + 1, 0), acm(k + 1, 0);
  dp[1] = acm[1] = v[1];
  for (int i = 2; i <= k; i++) {
    dp[i] = mul(v[i], acm[i - 1]);
    acm[i] = acm[i - 2]; add(acm[i], dp[i]);
  }
  return mul(dp[k], inv(mul(v[1], v[k])));
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] ^= a[i - 1];
  }

  constexpr int amx = 1 << 20;
  vector<vector<int>> rnl(amx, vector<int>(0));
  unordered_map<int, int> mp;
  vector<int> prv(amx, 0);
  vector<int> acm_z(n + 1, 1);
  for (int i = 1; i <= n; i++) {
    int crr = a[i];
    acm_z[i] = acm_z[i - 1];
    if (crr) mp[crr]++;
    if (!crr) {
      acm_z[i]++;
      for (auto it = mp.begin(); it != mp.end(); it++) {
        int p = it->first; int m = it->second;
        rnl[p].push_back(acm_z[i] - acm_z[prv[p]]);
        rnl[p].push_back(m);
        prv[p] = i;
      }
      mp.clear();
    }
  }
  for (int i = 0; i < amx; i++) {
    rnl[i].push_back(acm_z[n] - acm_z[prv[i]] + 1);
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int p = it->first; int m = it->second;
    rnl[p].push_back(m);
  }
  if (a[n]) {
    cout << cal(rnl[a[n]]) << endl;
    return 0;
  }
  int ret = 0;
  for (int i = 1; i < amx; i++) {
    add(ret, cal(rnl[i]));
  }
  add(ret, mow(2, rnl[0][0] - 2));
  cout << ret << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
string ans = "ABD";
	if(n<1000){
		ans = "ABC";
	}
	cout << ans << endl;
	return 0;


}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,sum=0,m=1000000;
    cin>>n;
    vector<ll> x(n);
    rep(i,n){
        cin>>x[i];
    }
    for(ll p=1;p<=100;p++){
        rep(i,n){
            sum+=(x[i]-p)*(x[i]-p);
        }
        m=min(m,sum);
        sum=0;
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
def actual(n, D):
    D.sort()

    idx = int(len(D) // 2)
    abc_max = D[:idx][-1]
    arc_min = D[idx:][0]

    k = 0

    for i in range(abc_max + 1, arc_min + 1):
        k += 1

    return k

n = int(input())
D = list(map(int, input().split()))

print(actual(n, D))


Measured memory_bytes: 14428
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var k = cin.nextInt();
            var s = cin.next();

            if(s.Length <= k)
            {
                Console.WriteLine(s);
            }
            else
            {
                var ss = s.Substring(0,k);
                Console.WriteLine(ss + "...");
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 27540
N,K,C = map(int, input().split())
S = input()
dp0 = [0]*K
dp1 = [0]*K
step = C
cnt = 0
for i in range(N):
  if step>=C and S[i]=='o':
    dp0[cnt] = i
    cnt += 1
    if cnt==K:
      break
    step = 0
  else:
    step += 1
step = C
cnt = K-1
for i in range(N-1,-1,-1):
  if step>=C and S[i]=='o':
    dp1[cnt] = i
    cnt -= 1
    if cnt==-1:
      break
    step = 0
  else:
    step += 1
ans = 0
for i,(a,b) in enumerate(zip(dp0,dp1)):
  if a==b:
    print(a+1)

Measured memory_bytes: 24944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pre(i,a,b) for(int i=(a);i>(b);i--)
const int maxn=1e5+10;
const int mod=998244353;
const int inf=0x3f3f3f3f;
ll book[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll ans=1;
	int x;
	cin>>x;
	if(x!=0) ans=0;
	book[0]=1;
	rep(i,1,n)
	{
		cin>>x;
		book[x]++;
	}
	if(book[0]>1) ans=0;
	if(ans==0)
	{
		cout<<0<<'\n';
		return 0;
	}
	rep(i,1,n)
	{	
		if(book[i]==0) continue;
		if(book[i-1]==0) ans=0;
		else 
		{
			rep(j,0,book[i]) ans=ans*book[i-1]%mod;
		}
	}
	cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 1024
import numpy as np

W,H,N = map(int,input().split())
l = np.zeros((H,W)) #	要素0のH×W配列

for i in range(N):
  x,y,a = map(int,input().split())

  if a==1:
    l[:,:x] = 1
    #print(l[:,x:])
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
#print(H*W-int(l.sum().sum()))
print(H*W-int(l.sum()))

Measured memory_bytes: 27148
#include <iostream>

using namespace std;

const int N = 1e5+10;

typedef long long ll;

ll n;
ll a[N];

int main()
{
    cin >> n;

    for (int i = 1; i <= n; i ++ ) cin >> a[i];

    ll sum1 = 0,sum2 = 0;//前i项和
    ll cnt1 = 0,cnt2 = 0;//操作次数

    if(a[1] == 0)
    {
        sum1 = 1;
        sum2 = -1;
        cnt1 = 1;
        cnt2 = 1;
    }
    else if(a[1] > 0)
    {
        sum1 = a[1];
        sum2 = -1;
        cnt2 = a[1] + 1;
    }
    else if(a[1] < 0)
    {
        sum1 = 1;
        sum2 = a[1];
        cnt1 = abs(a[1]) + 1;
    }//判断a[1]的符号

    for (int i = 2; i <= n; i ++ )
    {
        if(sum1 > 0)//上一个和为sum1
        {
            if(sum1+a[i] < 0)
            {
                sum1 += a[i];
            }
            else
            {
                cnt1 += abs(sum1+a[i])+1;
                sum1 = -1;
            }
        }
        else//sum1 < 0的情况
        {
            if(sum1+a[i] > 0)
            {
                sum1 += a[i];
            }
            else
            {
                cnt1 += abs(sum1+a[i]) + 1;
                sum1 = 1;
            }
        }
    }

    for (int i = 2; i <= n; i ++ )
    {
        if(sum2 > 0)//上一个和为sum2
        {
            if(sum2+a[i] < 0)
            {
                sum2 += a[i];
            }
            else
            {
                cnt2 += abs(sum2+a[i])+1;
                sum2 = -1;
            }
        }
        else//sum2 < 0的情况
        {
            if(sum2+a[i] > 0)
            {
                sum2 += a[i];
            }
            else
            {
                cnt2 += abs(sum2+a[i]) + 1;
                sum2 = 1;
            }
        }
    }
    cout << min(cnt1,cnt2) <<endl;
    return 0;
}


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

#define INF INT_MAX
#define BEAMMAX 25000

using namespace std;
//ルートクラス
class Root{
public:
	int cost;
    set<char> key;
	bool flag;
    int x,y;

	Root(int xx,int yy,int cc,bool rr){x = xx; y = yy;cost = cc;flag = rr;}
	Root(const Root &r){
		x = r.x, y = r.y;
		flag = r.flag;
		cost = r.cost;
	}
    Root(){};

	bool operator > (const Root &container) const{
		return (cost > container.cost);
	}
};

//右、下
int dy[2] = {0,1};
int dx[2] = {1,0};


int main(void){
    int w,h;
    cin >> h >> w;
    vector<string> map(h);
    for(int i = 0;i < h;i++){
        cin >> map[i];
    }
    int sy,sx,gy,gx;
    sx = 0,sy = 0,gx = w-1 ,gy = h-1;

    priority_queue< Root , vector<Root>, greater<Root> > que;
    priority_queue< Root , vector<Root>, greater<Root> > goal;

    Root init_r(sx,sy,0,true);	//初期状態
    vector< vector<int> >memo(h, vector<int>(w,INF));	//(y,x)の最小コスト記録用
    que.push(init_r);	//初期状態をプライオリティーキューに格納
	while(que.size() > 0){
			if(que.size() == 0)break;
			Root r = que.top();
			int posx = r.x, posy = r.y;
			que.pop();

            if(r.flag){
                if(map[posy][posx] == '#'){
                    r.cost++;
                    r.flag = false;
                }
            }else{
                if(map[posy][posx] == '.'){
                    r.flag = true;
                }
            }

            // cout << posy << " a " << posx  << " " <<  r.cost << endl;
			//ゴール地点へ到着したらゴールキューに入れる
			if(posx == gx && posy == gy){
				goal.push(r);
				continue;
			}
			//取り出したコストがその地点までの最小コストかチェック
			if(memo[posy][posx] > r.cost){
				memo[posy][posx] = r.cost;
			}else{
				continue;
			}
			//方向調査
			for(int i = 0;i < 2;i++){
				Root rr = r;
				int posxx = posx + dx[i], posyy = posy + dy[i];
                // cout << posyy << " b " << posxx  << " " <<  rr.cost << endl;
				if(!(0 <= posxx && posxx < w && 0 <= posyy && posyy < h))continue;	//範囲外に出てしまった時は何もしない                
                rr.x = posxx, rr.y = posyy;
                que.push(rr);
			}
    }
    // for(int i = 0;i < goal.top().root.size();i++){
    //     cout << goal.top().root[i] << endl;
    // }
    cout << goal.top().cost << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

typedef struct TREE{
	int id;
	struct TREE *parent;
	struct TREE *child[2];
	int depth;
	int height;
}Tree;

Tree tree[100];

int setDepthHeight(Tree *nt, int depth){
	if( nt == NULL ){ return -1; }
	nt->depth = depth;
	int lh = setDepthHeight(nt->child[0], depth+1);
	int rh = setDepthHeight(nt->child[1], depth+1);
	nt->height = (lh>rh?lh:rh) + 1;
	return nt->height;
}

void output(Tree *tr){
	char *nodetype[3] = {"root", "internal node", "leaf"};
	int pid, sibling = -1, degree = 0, ni;
	if( tr->child[0] != NULL ) degree++;
	if( tr->child[1] != NULL ) degree++;
	if( tr->parent != NULL ){
		if( tr->parent->child[0] != NULL && tr->parent->child[0]->id != tr->id ){
			sibling = tr->parent->child[0]->id;
		}
		else if( tr->parent->child[1] != NULL && tr->parent->child[1]->id != tr->id ){
			sibling = tr->parent->child[1]->id;
		}
		if( degree == 0 ){
			ni = 2;
		}else{
			ni = 1;
		}
		pid = tr->parent->id;
	}else{
		ni = 0;
		pid = -1;
	}
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
		tr->id, pid, sibling, degree, tr->depth, tr->height, nodetype[ni]
	);
	return;
}

int main(){
	int n, id, id2, i, j;
	Tree *root = NULL;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		tree[i].id = -1;
		tree[i].parent = NULL;
		tree[i].child[0] = NULL;
		tree[i].child[1] = NULL;
		tree[i].depth = -1;
		tree[i].height = -1;
	}
	for(i=0;i<n;i++){
		scanf("%d",&id);
		tree[id].id=id;
		scanf("%d",&id2);
		if(0<=id2 && id2<n){
			tree[id].child[0] = &tree[id2];
			tree[id2].parent = &tree[id];
		}
		scanf("%d",&id2);
		if(0<=id2 && id2 < n ){
			tree[id].child[1] = &tree[id2];
			tree[id2].parent = &tree[id];
		}
	}
	for(i=0;i<n;i++){
		if(tree[i].parent==NULL){
			root = &tree[i];
			break;
		}
	}
	setDepthHeight(root, 0);
	for( i = 0; i < n; i++ ) output(&tree[i]);
	return 0;
}



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

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

const string YES = "Yes";
const string NO = "No";

void solve(long long D, long long T, long long S){
    double t = (double)D/S;
    if(t > T){
        cout << NO << endl;
    } else{
        cout << YES << endl;
    }



}

int main(){
    long long D;
    scanf("%lld",&D);
    long long T;
    scanf("%lld",&T);
    long long S;
    scanf("%lld",&S);
    solve(D, T, S);
    return 0;
}


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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VL d(n);
    REP(i,n)cin>>d[i];
    LL ans = 0;
    REP(i,n)FOR(j,i+1,n){
        ans += d[i] * d[j];
    }
    PUTS(ans);
}

Measured memory_bytes: 256
import sys
S = input()

if S[0] != 'A':
    print('WA')
    sys.exit()
elif sum([1 for c in S[2:-1] if c == 'C']) != 1:
    print('WA')
    sys.exit()
else:
    for c in S:
        if ord('A') <= ord(c) <= ord('Z') and not c in ['A', 'C']:
            print('WA')
            sys.exit()
print('AC')


Measured memory_bytes: 3060
public class Main {
	public static void main(String args[]) {

		java.util.Scanner sc = new java.util.Scanner(System.in);
		long N = sc.nextLong();

		long A = 0;
		long B = 0;
		for (long i = (long) Math.sqrt(N); i > 0; i--) {
			if (N % i == 0) {
				A = i;
				B = N / i;
				break;
			}
		}

		System.out.println(A + B - 2);
	}

}

Measured memory_bytes: 23764
#include<stdio.h>


typedef struct{
	int v;
	int l,r;
}node;

int check(int a[],int n){
	int i;
	for(i=0;i<n;i++){
		if(a[i]==0)return 0;
	}
	return 1;
} 

void searchRoot(int v[],int id,node t[]){
	if(id==-1)return;
	v[id]=1;
	searchRoot(v,t[id].l,t);
	searchRoot(v,t[id].r,t);
}

void search(int key,int id,node t[],int p,int s,int d){
	if(id==-1)return;
	if(key==id){
		int count=0;
		if(t[key].l!=-1)count++;
		if(t[key].r!=-1)count++;
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, ",key,p,s,count,d);
		return;
	}
	search(key,t[id].l,t,id,t[id].r,d+1);
	search(key,t[id].r,t,id,t[id].l,d+1);
}

int max(int a,int b){
	if(a>b)return a;
	return b;
}

int searchH(int key,node t[]){
	if(key==-1)return -1;
	return max(searchH(t[key].l,t),searchH(t[key].r,t))+1;
}


int main(void){
	node tree[26];
	int visit[26];
	int n,id,l,r;
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&id,&l,&r);
		tree[id].l=l;
		tree[id].r=r;
		visit[id]=0;
	}
	int root;
	for(i=0;i<n;i++){
		searchRoot(visit,i,tree);
		if(check(visit,n)==1){
			root=i;
			break;
		}
	}
	int maxH;
	for(i=0;i<n;i++){
		search(i,root,tree,-1,-1,0);
		printf("height = %d, ",searchH(i,tree));
		if(root==i)printf("root");
		else if(tree[i].r==-1&&tree[i].l==-1)printf("leaf");
		else printf("internal node");
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1816
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func countStudents(height []int32) int32 {
	// Write your code here
	// var count int32
	ideal := make([]int32, len(height))
	for i := 0; i < len(height); i++ {
		ideal[i] = height[i]
	}

	for i := 0; i < len(ideal); i++ {
		for j := i; j < len(ideal)-1; j++ {
			if ideal[j] > ideal[j+1] {
				tmp := ideal[j]
				ideal[j] = ideal[j+1]
				ideal[j+1] = tmp
			}
		}
	}

	for i := 0; i < len(height); i++ {
		fmt.Print(height[i])
	}
	var count int32
	for i := 0; i < len(height); i++ {
		if ideal[i] != height[i] {
			count++

		}
	}

	return count
}
func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b :=nextInt()
	c :=nextInt()
	if a%2==1 || b%2==1 || c%2==1 {
		fmt.Println(0)
		return
	}
	if a==b && b == c{
		fmt.Println(-1)
		return
	}
	for i:=0;;i++{
		if a%2==1 || b%2==1 || c%2==1{
			fmt.Println(i)
			return
		}
		na:=a/2
		nb:=b/2
		nc:=c/2
		a=nb+nc
		b=na+nc
		c=na+nb
	}



}


Measured memory_bytes: 1772
from collections import defaultdict

def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    d = defaultdict(int)

    for h in range(H):
        for w in range(W):
            d[A[h][w]] += 1
            d[A[h][w]] %= 4

    e = defaultdict(int)
    for a in d.values():
        e[a] += 1

    if H % 2 == 0 and W % 2 == 0:
        if e[1] or e[2] or e[3]:
            print('No')
        else:
            print('Yes')
    elif H % 2 == 1 and W % 2 == 1:
        if e[1] + e[3] == 1:
            if e[2] <= (H // 2 + W // 2):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        if e[1] or e[3]:
            print('No')
        else:
            if H % 2 == 0:
                cnt = H // 2
            else:
                cnt = W // 2
            if e[2] <= cnt:
                print('Yes')
            else:
                print('No')




if __name__ == "__main__":
    main()

Measured memory_bytes: 68944
#include <stdio.h>

int main(){
  int n,a,b,l[2048][8192]={},c[2048][8192]={},i,j,k,d;
  long m=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a);
    if(i>=a){
      b=(i-a)>>11;
      d=(i-a)&2047;
      for(j=1;j<=l[d][0];j++){
        if(l[d][j]==b) break;
      }
      if(j<=l[d][0]){
        m+=(long)c[d][j];
      }
    }
    a+=i;
    b=a>>11;
    d=a&2047;
    for(j=1;j<=l[d][0];j++){
      if(l[d][j]==b) break;
    }
    if(j>l[d][0]){
      l[d][j]=b;
      l[d][0]++;
    }
    c[d][j]++;
  }
  printf("%ld",m);
  return(0);
}

Measured memory_bytes: 132808
n, m = gets.split.map(&:to_i)

adj = (n+1).times.map{Array.new}
m.times do
  a, b = gets.split.map(&:to_i)
  adj[a].push b
  adj[b].push a
end

parents = Array.new(n+1, nil)
parents[1] = 0

queue = [1]
count = 1
loop do
  parent = queue.shift
  adj[parent].each do |child|
    if parents[child].nil?
      parents[child] = parent
      queue.push child
      count += 1
    end
  end
  if count == n
    break
  end
end

puts 'Yes'
parents[2..n].each do |parent|
  puts parent
end


Measured memory_bytes: 32728
#include <iostream>
#include <string>
#include <locale>
#include <cstdlib>
#include <algorithm>

using namespace std;
using lli = long long int;

int main()
{
    string str;
    
    while (cin >> str)
    {
        if (str == "0"s)
            break;

        lli sum {};

        for (const auto c : str)
        {
            sum += atoi(&c);
        }

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3232
#include <iostream>

int main()
{
    int N, M;
    std::cin >> N >> M;

    for (auto i = 0; i < M && N >= 0; i++) {
        int Ai;
        std::cin >> Ai;

        N -= Ai;
    }

    if (N < 0) {
        std::cout << "-1" << std::endl;
    } else {
        std::cout << N << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
typedef long long ll;
const int MOD = 1e9 + 7;
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 cmb(ll n, ll a) {
	if (n - a < a) return cmb(n, n - a);

	ll res = 1;
	for (ll i = n; n - a + 1 <= i; i--) { res *= i;  res %= MOD; }
	for (ll i = 2; i <= a; i++) { res = res * modinv(i, MOD) % MOD; }

	return res;
}

int main() {
	ll n, k;
	cin >> n >> k;
	for (ll i = 1; i <= k; i++) {
		if (n - k + 1 >= i)
			cout << cmb(n - k + 1, i) * cmb(k - 1, i - 1) % MOD << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int N;
    cin >> N;
    if(N % 2){
        cout << 2 * N << endl;
    }else{
        cout << N << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <string>
#include<climits>
#include <cmath>
# define P 3.14159265358979323846
using namespace std;
int main()
{
double a,b,h,m;
   cin>>a>>b>>h>>m;
  double ang=abs((h*5*6)-(m*6)+(m*0.5));
   ang=(ang>180)?(360-ang):ang;
    double d=cos((ang*P)/(180.0));
   double k=(a*a)+(b*b)-(2*a*b*d);
   double c=sqrt(k);
   printf("%.20lf",c);

    return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if(a*b%2==1){
    cout<<"Odd"<<endl;
  }else{
    cout<<"Even"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  100012101;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
 


int main(){
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N+1);
    rep(i,M){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> flag(N+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    flag[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (flag[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            flag[nv] = v;
            que.push(nv);
        }
    }
bool judge=true;
rep3(i,N){
    if(flag[i]==-1){
        judge=false;
    }
}
if(judge){
    cout<<"Yes"<<endl;
    rep4(i,2,N){
        cout<<flag[i]<<endl;
    }
}
else{
    cout<<"No"<<endl;
}
return 0;
}

Measured memory_bytes: 10328
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int n, m; cin >> n >> m;
    vector<pair<int,int>> vec(m);
    rep(i, m){
        int a, b; cin >> a >> b;
        vec[i].first = b;
        vec[i].second = a;
    }
    sort(vec.begin(), vec.end());
    int pos = 0;
    int ans = 0;
    rep(i, m){
        if(vec[i].second > pos){
            pos = vec[i].first - 1;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
  char a;
  cin >> a;
  if(a == 'A') {
    cout << 'T';
  } else if(a == 'C') {
    cout << 'G';
  } else if(a == 'T') {
    cout << 'A';
  } else {
    cout << 'C';
  }
  cout << "\n";
}

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

namespace ConsoleApp86 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = st[0];
            int M = st[1];

            var P = new int[M];
            var Y = new int[M];
            var index = new int[M];

            for (int i = 0; i < M; i++) {
                var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

                P[i] = x[0];
                Y[i] = x[1];
                index[i] = i;
            }


            var a = new List<Tuple<int, int>>[N];

            //初期化
            for (int i = 0; i < N; i++) {
                a[i] = new List<Tuple<int, int>>();
            }

            for (int i = 0; i < M; i++) {
                a[P[i] - 1].Add(new Tuple<int, int>(index[i], Y[i]));
            }

            for (int i = 0; i < N; i++) {
                a[i].Sort((p, q) => p.Item2.CompareTo(q.Item2));
            }

            var ans = new int[M];
            int counter = 1;

            for (int i = 0; i < N; i++) {
                counter = 1;
                for (int j = 0; j < a[i].Count(); j++) {
                    ans[a[i][j].Item1] = counter;
                    counter++;
                }
            }


            for (int i = 0; i < M; i++) {
                Console.WriteLine(String.Format("{0:D6}", P[i]) + String.Format("{0:D6}", ans[i]));


            }

        }
    }
}


Measured memory_bytes: 33600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

string s;
ll ans;

signed main() {
	cin >> s;
	int n = (int)s.size();
	for (int i = 0; i < (1 << (n - 1)); i++) {
		int p = 0;
		ll cnt = 0;
		for (int j = 0; j < n - 1; j++)if (i&(1 << j)) {
			cnt += stoll(s.substr(p, j - p + 1));
			p = j + 1;
		}
		cnt += stoll(s.substr(p, n - p));
		ans += cnt;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <set>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;

int n, a[9], b[9], c[9];

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) c[i] = i + 1;

  int cnt = 0, ans = 0;
  do {
    ++cnt;
    bool ma = true, mb = true;
    for(int i = 0; i < n; ++i) {
      if (c[i] != a[i]) ma = false;
      if (c[i] != b[i]) mb = false;
    }
    if (ma) ans -= cnt;
    if (mb) ans += cnt;
  } while(next_permutation(c, c + n));
  cout << abs(ans);
  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final String ABC = "ABC";

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

		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		int count = 0;
		int it = 0;
		int result = 0;
		while (result != -1) {
			result = s.indexOf(ABC, it);
			if (result != -1) {
				count++;
				it = result + ABC.length();
			}
		}

		System.out.println(count);

	}
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
int dfs(vvi &dp, vi &v, int i, int j) {
	if (dp[i][j] != -1)return dp[i][j];
	int ret = 0;
	chmax(ret, dfs(dp, v, i + 1, j));
	FOR(k, i + 1, j) {
		if (abs(v[k] - v[i]) <= 1 && dfs(dp, v, i + 1, k) == k - (i + 1)) {
			chmax(ret, (int)k - (i + 1) + 2 + dfs(dp, v, k + 1, j));
		}
	}
	return dp[i][j] = ret;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vi v(n);
		REP(i, n)cin >> v[i];
		vvi dp(n + 1, vi(n + 1, -1));
		REP(i, n + 1)dp[i][i] = 0;
		cout << dfs(dp, v, 0, n) << endl;
	}
}


Measured memory_bytes: 3384
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int a=sc.nextInt();
	int b=sc.nextInt();
	int total=0;

	for(int i=1;i<=n;i++) {
		int sum=intSumDigits(i);
		if(a<=sum&&sum<=b) {
		total +=i;
		}
	}
		System.out.println(total);
	}

//各桁の和を計算する関数
	public static int intSumDigits(int x) {
		int sum=0;
		while(x>0) {
			sum += x%10;
			x /=10;
		}
		return sum;
	}
}

Measured memory_bytes: 21844
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var X = int.Parse(Console.ReadLine());
            var ans = 1;
            while(true) {
                if((X*ans)%360 == 0) {
                    break;
                }
                ans++;
            }
            Console.Write(ans);
        }
    }
}

Measured memory_bytes: 27248
import math

N = int(input())

def check(N):
	n2 = math.floor(math.sqrt(N))
	min = N - 1
	for i in range(2, n2 + 1):
		if N % i == 0:
			j = N // i
			d = i + j - 2
			if d < min:
				min = d
	return min

print(check(N))


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, A, B;
    cin >> N >> A >> B;

    string S;
    cin >> S;

    ll C = A+B;
    ll cnt = 0;
    ll bcnt = 0;
    rep (i, N) {
        if (S[i] == 'a') {
            if (C > cnt) {
                Yes;
                cnt++;
            } else {
                No;
            }
        } else if (S[i] == 'b') {
            if (C > cnt) {
                if (B > bcnt) {
                    Yes;
                    bcnt++;
                    cnt++;
                } else {
                    No;
                }
            } else {
                No;
            }
        } else {
            No;
        }
    }
    return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	vector<char> s;
	vector<char>::iterator it;
	char c, t;
	int q, f, flag = 1, num;
	while(scanf("%c", &t), t != '\n')
		s.push_back(t);
	cin>>q;
	while(q--){
		scanf("%d", &num);
		getchar();
		if(num == 1) flag *= -1;
		else{
			scanf("%d %c", &f, &c);
			getchar();
			if(f == 1){
				if(flag == 1) s.insert(s.begin(), c); 
				else s.push_back(c);
			}else{
				if(flag == -1) s.insert(s.begin(), c); 
				else s.push_back(c);
			}
		} 
	}
	if(flag == 1){
		for(it = s.begin(); it < s.end(); it++)
			printf("%c", *it);
	}else{
		for(it = s.end(), it--; it >= s.begin(); it--)
			printf("%c", *it);
	}
	return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   V<int> a(7);
   for (int i = 0; i < 7; i++) {
      cin >> a[i];
   }
   int ans = (a[0] - a[0]%2) + a[1] + (a[3] - a[3]%2) + (a[4] - a[4]%2);
   if (a[0]%2 == 1 && a[3]%2 == 1 && a[4]%2 == 1) {
      ans += 3;
   } else if (a[0] > 0 && a[3]%2 == 1 && a[4]%2 == 1) {
      ans += 1;
   } else if (a[0]%2 == 1 && a[3] > 0 && a[4]%2 == 1) {
      ans += 1;
   } else if (a[0]%2 == 1 && a[3]%2 == 1 && a[4] > 0) {
      ans += 1;
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
N=int(input())
b=[int(i) for i in input().split()]
A=True
a=[]
for _ in range(N):
  ans=0
  for j in range(len(b)):
    if j+1==b[j]:
      ans=max(ans,j+1)
  if ans==0:
    A=False
    break
  a.append(ans)
  del b[ans-1]
    
a=a[::-1]
if A:
  for i in a:
    print(i)
else:
  print(-1)
  


Measured memory_bytes: 3064
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
	long long k;
	cin>>k;
	long long a[51]={0};
	long long q, r;
	r=k%50;
	q=k/50;
	int i;
	for(i=1;i<=50;i++){
		if(i<=50-r) a[i]=q+49-r;
		else a[i]=q+100-r; 
	}
	cout<<50<<endl;
	for(i=1;i<=49;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[50];
	return 0;
}

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

using namespace std;
typedef pair<int, int> ii;

int n;
int arr[401];

const int MOD = (int)1e9 + 7;

long long cost = 0;

long long dp[401][401];

long long funct(int i, int j) {
    if(i == j) {
        return 0;
    }
    if(dp[i][j]) return dp[i][j];

    int idx, mx = 0;
    long long sum = 0;

    for(int s = i; s <= j; ++s) {
        sum += arr[s];
    }

    long long mn = 1e18L + 9;

    for(int s = i; s < j; ++s) {
        long long a = funct(i, s); 
        long long b = funct(s + 1, j);
        mn = min(mn, a + b + sum);
    }
    dp[i][j] = mn;
    return mn;
}


int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    funct(0, n-1);

    cout << dp[0][n-1];
}

Measured memory_bytes: 1536
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    print("#" * b)
    for i in range(a - 2):
        print("#", end = "")
        print("." * (b - 2), end = "#\n")
    print("#" * b)
    print()


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    string ans="No";
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(N==i*j) ans="Yes";
        }
    }
    cout << ans << endl;


}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int x=read(),y=read(),ans=0;
	while(x<=y){
		ans++;
		x*=2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		String[] array = new String[N];
		for(int i = 0; i < N; i++){
			//System.out.println(i + "moji");
			array[i] = sc.next();
		}
		Arrays.sort(array);
		String str = "";
		for(int i = 0;i < N;i++){
			str += array[i];
		}
		System.out.println(str);
	}
}

Measured memory_bytes: 24020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.xml.crypto.KeySelector.Purpose;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		try {
			while (input.ready()) {
				String[] dataStr = input.readLine().split(" ");
				int[] dataInt = new int[dataStr.length];
				for (int i = 0; i < dataStr.length; i++) {
					dataInt[i] = Integer.valueOf(dataStr[i]);
				}
				System.out.println(getGCD(dataInt[0], dataInt[1]) + " " + getLCM(dataInt[0], dataInt[1]));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/***
	 * ?????§??¬?´???°
	 */
	public static int getGCD(int a, int b) {
		if (a == b)
			return a;
		int d = 1;
		if (a < b) {
			d = a;
		} else {
			d = b;
		}
		for (int i = d; i > 0; i--) {
			if ((a % i == 0) & (b % i == 0)) {
				return i;
			}
		}
		return 0;
	}

	/***
	 * ????°???¬?????°
	 *
	 * @param a
	 * @param b
	 * @return
	 */
	public static int getLCM(int a, int b) {
		int productA = a;
		int productB = b;
		while (productA <= 2000000000) {
			if (productA == productB) {
				return productA;
			}
			if (productA < productB) {
				productA += a;
			} else {
				productB += b;
			}
		}
		return 0;
	}
}

Measured memory_bytes: 24920
D, G = map(int, input().split(" "))
p = [0] * D
c = [0] * D
for i in range(D):
    p[i], c[i] = map(int, input().split(" "))


def solve(G, i):
    """100i点以下の問題だけでGを達成する最小問題数"""
    if i <= 0:
        return 1e9
    n = min(int(G/(100*i)), p[i-1])
    s = 100 * i * n
    if n == p[i-1]:
        s += c[i-1]
    if G > s:
        n += solve(G-s, i-1)
    return min(n, solve(G, i-1))

print(solve(G, D))

Measured memory_bytes: 3064