akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

int main(void) {
  int n, A, B;
  std::cin >> n;
  std::cin >> A;
  std::cin >> B;

  int val;
  int count_a = 0;
  int count_b = 0;
  int count_c = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> val;
    if (val <= A) {
      count_a++;
    } else if (val <= B) {
      count_b++;
    } else {
      count_c++;
    }
  }

  int result = 0;
  if (count_a <= count_b) {
    if (count_a <= count_c) {
      result = count_a;
    } else {
      result = count_c;
    }
  } else {
    if (count_b <= count_c) {
      result = count_b;
    } else {
      result = count_c;
    }
  }

  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
s=str(input())
if s[len(s)-1]=='s':
  print(s+'es')
else:
  print(s+'s')

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll A,B;
    string S;
    cin >> A>>B;

    if(A<=8&&B<=8){
        cout << "Yay!" << endl;
    }
    else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), k = sc.nextInt();
		
		double sum = 0;
		if(n < k) {
			sum = get(n, k);
		} else {
			sum = (n - k + 1) + get(k - 1, k);
		}
		
		sum *= (1.0 / (n * 1.0));
		System.out.println(sum);
	}
	
	public static double get(int n, int k) {
		double sum = 0;
		for(int i = 1; i <= n; i++) {
			int p = (int)Math.ceil(Math.log10((k * 1.0) / i) / Math.log10(2));
			sum += Math.pow(0.5, (p * 1.0));
		}
		return sum;
	}
}


Measured memory_bytes: 22228
#include <stdio.h>

int main(){

int h, w;
int x, y;

while (1){
scanf("%d %d", &h, &w);

if (h == 0 && w == 0) break;

for  (y = 0; y < h; y++ ){
	for (x = 0; x < w; x++){
		printf("#");}
		printf("\n");
			}
		printf("\n"); 
}
return 0;
}

Measured memory_bytes: 572
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _s(): return sys.stdin.readline().strip()
def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    s = _s()
    t = _s()
    return "Yes" if t.startswith(s) else "No"

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 61688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  if(n % 2 == 0)cout << n * n / 4 << endl;
  else cout << (n / 2) * (n / 2 + 1) << endl;
}

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

int selectionSort(int A[], int N){
    int count = 0;
    
    for (int i = 0; i < N; i++) {
        int min = A[i];
        int j_min = i;
        for (int j = i; j < N; j++) {
            if(A[j] < min) {
                min = A[j];
                j_min = j;
            }
        }
        if (i != j_min){
            swap(A[i], A[j_min]);
            count++;
        }
    }
    return count;
}

int main(void)
{
    int N;
    int A[107];
    cin >> N; 
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int count = selectionSort(A, N);
    
    for (int i = 0; i < N-1; i++) {
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3084
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

void solve(){

   int a, b, c, d;
   cin >> a >> b >> c >> d;

   if (d == 1){
      cout<<1;
   }
   else{
      cout<<0;
   }

}

int32_t main(){_
   
   int t = 1;
//   cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


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

	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  ll x,y;
  cin >> x >> y;
  ll ans=abs(abs(x)-abs(y));
  if(x*y>0 && x>y)ans+=2;
  if(x*y<0)ans++;
  if(x*y==0 && x>y)ans++;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
N=int(input())
s=[]
for _ in range(N):
    s.append(int(input()))
if sum(s)%10 != 0:
 print (sum(s))
else:
    min_s = 0
    sorted_s = sorted(s, reverse=True)
    for ss in sorted_s:
        if ss % 10 != 0:
            min_s = ss
 
    if min_s == 0:
        print (0)
    else:
        print(sum(s) - min_s)

Measured memory_bytes: 3060
package main

import (
	"fmt"
	"math"
	"strconv"
	"strings"
)

func main() {
	var s string
	_, _ = fmt.Scan(&s)

	sl := strings.Split(s, "")
	min := 999
	n := 753
	for i := 0; i < len(sl) -2; i++ {
		t, _ := strconv.Atoi(strings.Join(sl[i:i+3], ""))
		d := int(math.Abs(float64(n-t)))
		if d < min {
			min = d
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=0,b=0,c=0;
	for(int i=0;i<3;i++){
		if(s[i]=='a') a++;
		else if(s[i]=='b') b++;
		else c++;
	}
	
	if(a&&b&&c) cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll dp[1010][1010];

int main(){
  string s1,s2;
  cin >> s1 >> s2;
  for (int i = 0; i < sz(s1); i++) {
    dp[0][i] = 1;
  }
  for (int i = 0; i < sz(s2); i++) {
    for (int j = 0; j < sz(s1); j++) {
      if (s1[j] == s2[i]) {
        dp[i+1][j+1] += dp[i][j];
        dp[i+1][j+1] %= MOD;
      }
      dp[i+1][j+1] += dp[i+1][j];
      dp[i+1][j+1] %= MOD;
    }
  }
  // for (int i = 0; i <= sz(s2); i++) {
  //   for (int j = 0; j <= sz(s1); j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  cout << dp[sz(s2)][sz(s1)] << endl;
  return 0;
}



Measured memory_bytes: 11112
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

#N = ii()
#ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
#for i in range(N):
S = input()
T = input()
#S = ss[2*i]
#T = ss[2*i+1]

ls, lt = len(S), len(T)
dp = dp2(0, ls+1, lt+1)
#if S[0] == T[0]:
    #dp[1][1] = 1

for i in range(1, lt+1):
    for j in range(1, ls+1):
        #if (i < lt and j < ls) and S[j] == T[i]:
            #dp[i+1][j+1] = dp[i][j] + 1
        #if j < ls:
            #dp[i][j+1] = max(dp[i][j], dp[i][j+1])
        #if i < lt:
            #dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

        
        
#if not dp[lt][ls]:
    #dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])

i, j = lt, ls
ans = ''

while dp[i][j] != 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += S[j-1]
        i -= 1
        j -= 1

print(ans[::-1])

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

int main(){
  int N;
  cin >> N;
  int even=0;
  int fourt=0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    if(a%4==0) fourt++;
    else if(a%2==0) even++;
  }
  string ans="No";
  if(fourt>=N/2) ans="Yes";
  else if(fourt*2+even>=N) ans="Yes";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,c,flag;
    string s1,s2;
    stack<char>st;
    char x;
    cin>>s1;
    flag=1;
    c=0;
    s2="";
    for(i=0; i<s1.size(); i++)
    {
        if(s1[i]=='0'&&s1[i+1]=='1')
        {
            c++;
            i++;
        }
        else if(s1[i]=='1'&&s1[i+1]=='0')
        {
            c++;
            i++;
        }
        else if(s1[i]=='0'&&s1[i+1]=='0'||s1[i]=='1'&&s1[i]=='1')
        {
            if(!st.empty())
            {
                x=st.top();
                if(x!=s1[i])
                {
                    c++;
                    st.pop();
                }
                else if(x==s1[i])
                {
                    st.push(s1[i]);
                }
            }
            else if(st.empty())
            {
                st.push(s1[i]);
            }
        }
        else if(i==(s1.size()-1))
        {
            x=s1[i];
            if(!st.empty())
            {
                x=st.top();
                if(x!=s1[i])
                {
                    c++;
                    st.pop();
                }
                else if(x==s1[i])
                {
                    st.push(s1[i]);
                }
            }
            else if(st.empty())
            {
                st.push(s1[i]);
            }

        }
    }

    c*=2;
    cout<<c<<endl;
    return 0;
}


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

#define ll long long
#define N 100005
#define mod 1000000007


int main() 
{
    int  n,i,a[N],num,div4=0,div2=0;
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
        cin>>num;
        if(num%4==0)
        {
            div4++;
        }
        else if(num%2==0)
        {
            div2++;
        }
    }
    int cnt=div4+div2/2;
    
    if(cnt>=(n)/2)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

cost = np.zeros(n)


for i in range(1,n):
    left = 0 if i-k<0 else i-k
    cost[i] = (cost[left:i]+abs(h[i]-h[left:i])).min()
     

print(int(cost[-1]))


Measured memory_bytes: 22912
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] t=new int[n];
		int[] x=new int[n];
		int[] y=new int[n];
		for(int i=0;i<n;i++) {
			t[i]=sc.nextInt();
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			if(i!=0) {
				if(t[i]-t[i-1]<Math.abs(x[i]-x[i-1])+Math.abs(y[i]-y[i-1])) {
					System.out.println("No");
					System.exit(0);
				}
				if((t[i]-t[i-1]-(Math.abs(x[i]-x[i-1])+Math.abs(y[i]-y[i-1])))%2!=0) {
					System.out.println("No");
					System.exit(0);
				}
			}else {
				if(t[i]<x[i]+y[i]) {
					System.out.println("No");
					System.exit(0);
				}
				if((t[i]-(x[i]+y[i]))%2!=0) {
					System.out.println("No");
					System.exit(0);
				}
				
			}
		}
		
		System.out.println("Yes");
	}
}



Measured memory_bytes: 91028
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,b;cin>>n;
  long long int sum=0;
  unordered_map<int,int> mp;
  int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; mp[a[i]]++; } 
  int q;cin>>q;
  while(q--){
    cin>>b>>c;
    sum=sum+mp[b]*(c-b);
    cout<<sum<<endl;
    mp[c]+=mp[b]; mp[b]=0;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n,m;    cin>>n>>m;
    vector<int> x(m),dis(m-1);
    
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    sort(x.begin(),x.end());
    
    
    for(int i=0;i<m-1;i++){
        dis[i]=x[i+1]-x[i];
    }
    sort(dis.begin(),dis.end());
    
    
    int sum=0;
    for(int i=0;i<m-n;i++){
        sum+=dis[i];
    }
    
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
object Main {

  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine().toInt
    val hList = io.StdIn.readLine().split(" ").map(_.toInt).toList
    val answer = solve(n, hList)
    println(answer)
  }

  private def solve(n: Int, hList: List[Int]): String = {

    val test = hList.foldLeft(Some(0): Option[Int]) { (acc, h) =>
      acc.flatMap { v =>
        if (h - v >= 1) Some(h - 1)
        else if (h >= v) Some(h)
        else None
      }
    }

    if (test.isDefined) "Yes"
    else "No"
    
  }
}


Measured memory_bytes: 50904
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const ll mod=1e9+7;
vector<ll>pos,neg;
bool cmp(int x,int y){return y<x;}
int main()
{
	int n,k,a;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a>0)pos.pb(a);
		else if(a<0)neg.pb(a);
	}
	int ps=0,ns=0;
	if(!pos.empty())ps=pos.size();
	if(!neg.empty())ns=neg.size();
	if((ps+ns/2*2>=k&&k%2==0)||(ps&&ps-1+ns/2*2>=k-1&&k%2==1))
	{
		ll ans=1,i=0,j=0;
		if(ps)sort(pos.begin(),pos.end(),cmp);
		if(ns)sort(neg.begin(),neg.end());
		if(k&1)ans=pos[i++],k--;
		while(k)
		{
			if(i+1<ps&&j+1<ns)
			{
				ll t1=pos[i]*pos[i+1],t2=neg[j]*neg[j+1];
				if(t1>t2)ans=ans*(t1%mod)%mod,i+=2;
				else ans=ans*(t2%mod)%mod,j+=2;
			}
			else if(i+1<ps)ans=ans*(pos[i]*pos[i+1]%mod)%mod,i+=2;
			else ans=ans*(neg[j]*neg[j+1]%mod)%mod,j+=2;
			k-=2;
		}
		cout<<ans<<endl;
	}
	else
	{

		if(ps+ns!=n)puts("0");
		else
		{
			ll ans=1;
			int i=0,j=0;
			if(ps)sort(pos.begin(),pos.end());
			if(ns)sort(neg.begin(),neg.end(),cmp);
			while(k--)
			{
				if(i<ps&&j<ns)
				{
					if(pos[i]<=abs(neg[j]))ans*=pos[i++],ans%=mod;
					else ans*=(neg[j++]+mod)%mod,ans%=mod;
				}
				else if(i<ps)ans*=pos[i++],ans%=mod;
				else ans*=(neg[j++]+mod)%mod,ans%=mod;

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


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

using namespace std;

#define F first
#define S second

int N;
int H[100005];
int dp[100005][5];

int solve(int cost, int ind, int j) {
	if (ind > N) return INT32_MAX;
	if (ind == N) return cost;

	if (~dp[ind][j]) return dp[ind][j];
	
	dp[ind][j] = cost;
	dp[ind][j] += min(solve(abs(H[ind] - H[ind + 1]), ind + 1, 0), 
					solve(abs(H[ind] - H[ind + 2]), ind + 2, 1));
	return dp[ind][j];
}

int main() {
	cin >> N; 
	H[0] = INT32_MAX; // to avoid RTE
	for (int i = 1; i <= N; i++) cin >> H[i];
	int ans = 0;
	
	memset(dp, -1, sizeof dp);
	cout << solve(0, 1, 0) << endl;

	return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
int a[105];
int main()
{
	int n,x;scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	int ans=0,flag=0;
	for(int i=1;i<=n;i++)
	{
		if(x<a[i]) break;
		x-=a[i];ans++;
		if(i==n) flag=1;
	}
	if(flag&&x) ans--;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){

	int n,m,a[100],i,count=0,sum=0;

	scanf("%d%d",&n,&m);

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}

	for(i=0;i<n;i++){
		if((float)a[i]/(float)sum>=1.0/(4.0*(float)m))
			count++;
	}

	if(count>=m)
		printf("Yes");

	else
		printf("No");	

	return 0;
}

Measured memory_bytes: 2124
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
a = LIST()
b = LIST()
xyc = [LIST() for _ in range(M)]

sum = [min(a)+min(b)]
for i in range(M):
	sum.append(a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2])

print(min(sum))

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

int main(){
  int n,t,a,b,c;
  cin >> n >> t;
  c=10000;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    if(b<=t && a<=c){
      c=a;
    }
  }
  if(c==10000){
    cout << "TLE" << endl;
  }else{
    cout << c << endl;
  }
}

Measured memory_bytes: 256
//cod2016_qualB_b.cpp
//Sat Nov 10 18:52:37 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	string s;
	cin >> s;

	int totalqual = 0;
//	int aqual = 0;
	int bqual = 0;
	for (int i=0;i<s.size();i++){
		if (s[i] == 'a'){
			if (totalqual < a+b){
				cout << "Yes" << endl;
				totalqual++;
			}else {
				cout << "No" << endl;
			}
		}else if (s[i] == 'b'){
			if (totalqual < a+b && bqual < b){
				cout << "Yes" << endl;
				totalqual++;
				bqual++;
			}else{
				cout << "No" << endl;
			}
		}else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  map<string,int> mp;
  bool f = true;
  rep(i,n-1) {
    if(s[i][(int)s[i].size()-1] != s[i+1][0] ) {
      f = false;
      break;
    }
    if(mp[s[i]] > 0) {
      f = false;
      break;
    }
    mp[s[i]]++;
  }
  if(mp[s[n-1]] > 0) f =false;
  if(f) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AOJ_Progran
{
    class Program
    {
        static void Main(string[] args)
        {
            bool x = true;
            while(x)
            {
                string str = Console.ReadLine();
                if (str == null)
                    break;
                string[] s = str.Split(' ');
                int a = int.Parse(s[0]);
                int b = int.Parse(s[1]);
                int num = a+b;
                string strNum = num.ToString();
                
                Console.WriteLine("{0}",strNum.Length);
            }
        }
    }
}

Measured memory_bytes: 9000
n,q=gets.split.map &:to_i
l=[-1]+[0]*n
i=1
m=0
q.times{a,v=gets.split.map &:to_i
j=l[a]+=v
v>0?(m<j)?(i,m=a,j):(m==j&&i>a&&i=a):a==i&&(m=l.max;i=l.index m)
puts [i,m]*" "}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w;
    cin >> h >> w;
    string s;
    for(ll i=0;i<h;i++) {
        cin >> s;
        cout << s << '\n' << s << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
vector<P>vec;
signed main(){
    int n,m;
    cin>>n>>m;
    int c=1;
    rep(i,m){
        c*=2;
    }
    int ans=(1900*m+100*(n-m))*c;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();

        double l = Math.sqrt((Math.pow((x2-x1) , 2) + Math.pow((y2-y1) , 2)));
        
        System.out.println(l);
    }
}



Measured memory_bytes: 27764
#include<stdio.h>
int main()
{
    int a,b,c;
    int i,j,k;
    scanf("%d%d%d", &a, &b, &c);
    int x[a][b], y[b][c];
    long long z;
    for(i=0;i<a;i++){
        for(j=0;j<b;j++){
            scanf("%d", &x[i][j]);
        }
    }
    for(j=0;j<b;j++){
        for(k=0;k<c;k++){
            scanf("%d", &y[j][k]);
        }
    }
    for(i=0;i<a;i++){
        for(k=0;k<c;k++){
            z =0;
            for(j=0;j<b;j++){
                z += x[i][j] * y[j][k];
            }
            if (k == c - 1)printf("%ld\n", z);
            else printf("%ld ", z);
        }
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> ans(n);
  rep(i,n) cin >> a[i];
  // ans[0]の設定
  rep(i,n){
    if(i%2==0) ans[0] += a[i];
    else ans[0] -= a[i];
  }
  for(int i=1; i<n; i++){
    ans[i] = (a[i-1] - ans[i-1]/2)*2;
  }
  rep(i,n) cout << ans[i] << endl;
  
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

#define llint long long int 
using namespace std;

int main()
{
    int n, s;
    vector<llint> x, d;

    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        int a;  cin >> a;
        x.push_back(a);
    }
    x.push_back(s);

    sort(x.begin(), x.end());
    for (int i = 0; i < n; i++) {
        llint a = x[i + 1] - x[i];
        d.push_back(a);                     // dはn要素
    }

    llint g = d[0];
    for (int i = 1; i < n; i++) {

        llint r;
        while (d[i] != 0) {
            r = g % d[i];
            g = d[i], d[i] = r;
        }
    }

    cout << g << endl;
}

Measured memory_bytes: 2548
#include<iostream>
using namespace std;
using ll = long long;

int main() {
  ll X,a,b;
  cin>>X;
  bool cont = true;
  for (a=-1000;a<=1000 && cont;a++) {
    for (b=-1000;b<=1000 && cont;b++) {
      if (X == (a*a*a*a*a - b*b*b*b*b)) cont = false;
    }
  }
  cout<<a-1<<" "<<b-1<<endl;
  return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji,moji2;
bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{

	cin >> a >> b >> c;
	cout << (a - c) / (b + c) << endl;
}

	
	





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;


//0~n-1というデータを扱うことが前提となっている
//unique_ptr<UFtree<int>> uf(new UFtree<int>(n));
template <typename T>
class UFtree{
public:
    UFtree(int data_num){
        v.resize(data_num);
        for (int i = 0; i < data_num; i++){
            v[i] = i;
        }
    }
    ~UFtree(){}

    T get_root(T a){
        T result;
        if(a==v[a]){
            return v[a];
        }else{
            T result;
            vector<T> path;
            T now_where=a;
            while(now_where!=v[now_where]){
                path.push_back(now_where);
                now_where=v[now_where];

            }
            for(T &x:path){
                v[x] = now_where;
            }
            return now_where;
        }
    }

    //aにbをつける
    void attach(T a,T b){
        v[get_root(b)] = v[get_root(a)];
    }

    
    
    void check(){for(T &x:v){
            cout << x<<" ";
        }
        cout << endl;
    }

  private:
    vector<T> v;


};



int main(){

    int n;
    cin >> n;
    unique_ptr<UFtree<long long int>> uf(new UFtree<long long int>(n));
    int q;
    cin >> q;
    long long int tmpa, tmpb,tmpc;
    REP(i,q){
        scanf("%lld %lld %lld", &tmpa, &tmpb, &tmpc);

        if(tmpa){
            
            printf("%d\n", uf->get_root(tmpb) == uf->get_root(tmpc));
        }else{
            uf->attach(tmpb,tmpc);
        }
    }

    


    return 0;
}



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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

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

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)%2==0){
    	cout<<(a+b)/2<<endl;
    }
    else{
    	cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# A, Can'tWait for Holiday
# 今日の曜日を表す文字列Sが与えられます。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれかであり、それぞれ日曜日、月曜日、火曜日。水曜日、木曜日、金曜日、土曜日を表します。
# 月の日曜日（あす以降）が何日後か求めてください。

# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれか。

S = input()

if S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)
else:print(7)

Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int l=a+b,r=c+d;
  if(l<r) cout<<"Right"<<endl;
  else if(l==r) cout<<"Balanced"<<endl;
  else cout<<"Left"<<endl;
 
}

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


int main()
{
    int N;
    cin >> N;
    vector<double> t(N+2, 0), v(N+2, 0);
    for(int i = 1; i <= N; i++) cin >> t[i];
    for(int i = 1; i <= N; i++) cin >> v[i];
 
 
    vector<double> l(N+2, 0), r(N+2, 0);
    for(int i = 2; i < N+2; i++) l[i] = l[i-1] + t[i-1];
    for(int i = 1; i < N+2; i++) r[i] = r[i-1] + t[i];

    vector<double> sv;
    for(double x = 0; x <= r[N+1]; x += 0.5) {
        double minv = 1e9+1;
        for(int i = 0; i < N+2; i++) {
            if( x <= l[i] ) minv = min(minv, v[i] + (l[i] - x));
            if( l[i] < x && x < r[i]) minv = min(minv, v[i]);
            if( r[i] <= x ) minv = min(minv, v[i] + (x - r[i]));
        }
        sv.push_back(minv);
    }
 
    double ans = 0;
    for(int i = 1; i < sv.size(); i++) ans += 0.25 * (sv[i] + sv[i-1]);

    cout << fixed << setprecision(3) << ans << endl;
 
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

int main() {
  //  READ();
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;cin>>n;
    int cnt=0;
    for(int i=1;i<n;++i){
        int x;cin>>x;
        if (x!=i){
            if (++cnt>2) {cout << "NO";return 0;}
        }
    }
    cout << "YES";
    return 0;
}



Measured memory_bytes: 256
import statistics

n=int(input())
x=list(map(int,input().split()))
p1 = int(statistics.mean(x))
p2=p1+1
s1=0
s2=0
for i in range(n):
    s1+=(x[i]-p1)**2
    s2+=(x[i]-p2)**2
print(min(s1,s2))


Measured memory_bytes: 77268
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	int n,m,l;
	Scanner in =new Scanner(System.in);
	n = in.nextInt();
	m = in.nextInt();
	l = in.nextInt();

	int[][] A = new int[n][m];
	int[][] B = new int[m][l];
	long[][] C = new long[n][l];

	// fill A
	for(int i=0;i<n;i++){
	    for(int j=0;j<m;j++){
		A[i][j] = in.nextInt();
	    }
	}

	// fill B
	for(int i=0;i<m;i++){
	    for(int j=0;j<l;j++){
		B[i][j] = in.nextInt();
	    }
	}


       	for(int i=0;i<n;i++){
	    for(int k=0;k<l;k++){
		C[i][k]=0;
		for(int j=0;j<m;j++){
		    C[i][k]+=A[i][j]*B[j][k];
		}
	    }
	}

	
	for(int i=0;i<n;i++){
	    for(int k=0;k<l;k++){
		System.out.print(C[i][k]);
		if(k!=l-1)System.out.print(" ");
	    }
	    System.out.println();
	}
    }
}
	   

	
	    
	
	



Measured memory_bytes: 53056
import sys
read = sys.stdin.read

N, *s = map(str, read().split())
answer = 0
first = 0
last = 0
BA = 0
for i in s:
    answer += i.count('AB')
    if i[0] == 'B' and i[-1] == 'A':
        BA += 1
        continue

    if i[0] == 'B':
        first += 1
    if i[-1] == 'A':
        last += 1

if BA:
    answer += BA - 1
    if first:
        answer += 1
        first -= 1
    if last:
        answer += 1
        last -= 1

answer += min(first, last)
print(answer)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
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<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	int N; cin >> N;
	V<int> A(N),B(N),C(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N-1) cin >> C[i];
	int ans = accumulate(all(B),0);
	rep(i,N-1) if(A[i]+1 == A[i+1]) ans += C[A[i]-1];
	cout << ans << endl;
}


Measured memory_bytes: 256
//07-5 ????????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    bool flg = true;
    while(flg){
        int a,b,c;
        cin >> a >> b >> c;
        if(a==0 && b==0 && c==0){
            flg = false;
        }
        else{
            int N;
            cin >> N;

            int item[301] = {};//??????1?????????0????????????-1
            int memo_i[1000] = {};
            int memo_j[1000] = {};
            int memo_k[1000] = {};

            int x = 0;

            for(int l=0; l<N; l++){
                int i,j,k,r;
                cin >> i >> j >> k >> r;
                if(r==1){//??????
                    item[i-1] = 1;
                    item[j-1] = 1;
                    item[k-1] = 1;
                }
                else{//?????????
                    memo_i[x] = i-1;
                    memo_j[x] = j-1;
                    memo_k[x] = k-1;
                    x++;
                }
            }

            int change = 1;
            while(change != 0){
                change = 0;
                for(int i=0; i<x; i++){
                    if(item[memo_i[i]]==1 && item[memo_j[i]]==1 && item[memo_k[i]]==0){
                        item[memo_k[i]] = -1;
                        change++;
                    }
                    else if(item[memo_i[i]]==1 && item[memo_j[i]]==0 && item[memo_k[i]]==1){
                        item[memo_j[i]] = -1;
                        change++;
                    }
                    else if(item[memo_i[i]]==0 && item[memo_j[i]]==1 && item[memo_k[i]]==1){
                        item[memo_i[i]] = -1;
                        change++;
                    }
                }
            }

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

        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

string S;

bool dfs(string &a){
    if(S.size() == a.size() && S == a){
        return true;
    }

    if (S.size() < a.size()) return false;
    if (!equal(a.begin(), a.end(), S.begin())) return false;

    vector<string> z = {"dream", "dreamer", "erase", "eraser"};

    for(auto y : z){
        a += y;
        if (dfs(a)) {
            return true;
        }
        a.erase(a.size() - y.size());
    }
    return false;
}

int main() {
    cin >> S;

    string T;
    string ans = dfs(T) ? "YES" : "NO";

    cout << ans << endl;
}


Measured memory_bytes: 10064
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

const int N=1e5;
int n;
int a[N+5];
int rank[N+5];

int main()
{
	scanf("%d",&n);
	int ans=0;
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		rank[a[i]]=i;
	}
	for(register int i=1;i<n;i++)
		printf("%d ",rank[i]);
	printf("%d\n",rank[n]);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  bool  a = false;
  
  for(int i=0;N>i;i++){
    string c;
    cin >> c;
    
    if( c == "Y"){
      a = true;
    }
  }
  if(a){
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
  
}

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

class node{
public:
  int v;
  node *next, *prev;
};

void solve(){
  int n; cin >> n;
  string c;
  int a;
  node *null = new node;
  null->next = null;
  null->prev = null;
  for(int i = 0; i < n; i++){
    cin >> c;
    if(c == "insert"){
      cin >> a;
      node *x = new node;
      null->next->prev = x;
      x->next = null->next;
      null->next = x;
      x->prev = null;
      x->v = a;
    }
    else if(c == "delete"){
      cin >> a;
      node *x = null->next;
      while(x != null){
        if(x->v == a){
          x->prev->next = x->next;
          x->next->prev = x->prev;
          free(x);
          break;
        }
        x = x->next;
      }
    }
    else if(c == "deleteFirst"){
      node *x = null->next;
      null->next = x->next;
      x->next->prev = null;
      free(x);
    }
    else{
      node *x = null->prev;
      null->prev = x->prev;
      x->prev->next = null;
      free(x);
    }
  }
  node *s = null->next;
  while(s != null->prev){
    cout << s->v << " ";
    s = s->next;
  }
  cout << s->v <<endl;
  free(null);
  return;
}

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



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

int main() {


    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 0;
    for(int i = 0; i <= N - 3; i++){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

ll N, A, B;

int main(void) {
    cin >> N >> A >> B;

    if ((N == 1 && A != B) || A > B) {
        cout << 0 << endl;
        return 0;
    }

    ll n = N - 2;

    ll result = n * (B - A) + 1;

    cout << result << endl;
    return 0;
}

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

int main() {
	v(a); v(b); v(c);
	a = a - b;
	a = c - a;
	if (a < 0) cout << 0 << endl;
	else cout << a << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector <P> p(n);
    rep(i,n){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(), p.end());

ll t;
t=0;
int k=0;
    rep(i,n){
        t+=p[i].second;
        if(t>p[i].first){
            k=1;
            break;
        }    
    }

    if(k==1){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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)

int main() {
	int A, B;
	cin >> A >> B;
	if (A + B >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << A + B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  if a[i]==b[i]:
    if not b[i]==c[i]:
      ans+=1
  else:
    if b[i]==c[i]:
      ans+=1
    elif a[i]==c[i]:
      ans+=1
    else:
      ans+=2
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>

namespace fk
{
	const int N=21;

	int t0[1<<N][N];

	int suf[N+1];

	void initialize()
	{
		for(int i=N-1;i;i--)
			suf[i]=suf[i+1]|(1<<i);
	}
	
	inline int& f(int S,int len,int ind)
	{
		return t0[S|suf[len+1]][ind];
	}

	int err_val=-1;
	int& to(int S,int len,int ind,bool rag)
	{
		if(ind==len)return err_val;

		if(((S>>ind)&1)==rag)
		{
			return f(S,len,ind+1);
		}
		else 
		{
			int fk=(1<<ind)-1,a=S&fk,b=S>>(ind+1);

//			bool flag=0;
//			if(S==2 && len==4 && ind==0)flag=1;

//			if(flag)printf("fuck : %d %d %d\n",fk,a,b);

			S=a|(b<<ind);

//			if(flag)printf("S --> %d\n",S);

			return to(S,len-1,ind,rag);
		}
	}

	char str[1<<N];

	int n,m;

	void output(int S,int len)
	{
		for(int i=0;i<len;i++)
			printf("%d",(S>>i)&1);
	}

	void solve()
	{
		initialize();

		scanf("%d%d",&n,&m);

		int ept;
		scanf("%d",&ept);
		for(int i=1;i<=n;i++)
		{
			scanf("%s",str);
			for(int j=0;j<(1<<i);j++)
				if(str[j]=='1')
				{
					int tmp=0;
					for(int k=0;k<i;k++)
						tmp|=((j>>k)&1)<<(i-k-1);

//					output(tmp,i),printf("\n");

//					printf("at begining : f["),output(tmp,i);
//					printf("][%d] = %d\n",0,1);

					f(tmp,i,0)=1;
				}
		}

		for(int len=n;len;len--)
			for(int i=0;i<(1<<len);i++)
				for(int ind=0;ind<=len;ind++)
				{
					int v=f(i,len,ind);

//					if(len==4 && i==2)
//					{
//						printf("f["),output(i,len),printf("][%d] = %d\n",ind,v);
//					}

					for(int rag=0;rag<2;rag++)
					{
						int &w=to(i,len,ind,rag);


//						if(len==4 && i==2)
//						{
//							printf("%d:::%d\n",rag,w);
//						}

						if(w==-1)continue;

						w+=v;
					}

					if(ind>0 && ind<len)
					{
						int &w=f(i&((1<<ind)-1),ind,ind);

						w+=v;
					}
				}

//		printf("%d\n",f(1,3,0));
//		printf("%d\n",f(1,3,1));

		int ans=-1,anslen=0; 

		for(int len=n;len;len--)
		{
			for(int i=0;i<(1<<len);i++)
			{

				int j=0;
				for(int k=0;k<len;k++)
					j|=((i>>k)&1)<<(len-k-1);

//				output(i,len);
//				printf(" ---> %d\n",f(i,len,len));

				if(f(j,len,len)>=m)
				{
					ans=j,anslen=len;
					goto out;
				}
			}
		}

//		printf("anslen = %d\n",anslen);

out:	output(ans,anslen);
		printf("\n");
	}

}

int main()
{
//	freopen("F.in","r",stdin);

	fk::solve();
	return 0;
}


Measured memory_bytes: 173312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll fac[100005];
const ll mod = 1e9+7;
void solve() {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return;
  }
  if (n == m) {
    cout << (fac[n] * fac[m] * 2ll) % 1000000007ll << endl;
  } else {
    cout << (fac[n] * fac[m]) % 1000000007ll << endl;
  }
  return;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cout<<fixed<<setprecision(12);
	fac[0] = 1;
	for(int i=1;i<100005;i++){
		fac[i] = fac[i-1]*i;
		fac[i]%=mod;
	}
	int t=1; 
//	cin>>t;
	while(t--)solve();
  return 0;
}


Measured memory_bytes: 1024
/*Infor {{{
 ******************************************************
 * > File Name: a.cpp
 * > Author: samcompu
 * > Mail: admin@samcompu.com
 * > Created Time: 2018/9/15 19:59:46
 ******************************************************
}}}*/

#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define cini(a) scanf("%d", &(a))
#define cinc(a) scanf("%c", &(a))
#define cinl(a) scanf("%lld", &(a))
#define cins(a) scanf("%s", (a))
#define cind(a) scanf("%lf", &(a))
#define coui(a) printf("%d", (a))
#define couc(a) printf("%c", (a))
#define coul(a) printf("%lld", (a))
#define cous(a) printf("%s", (a))
#define coud(a) printf("%f", (a))
#define SPA printf(" ")
#define LIN printf("\n")
#define ull unsigned long long int
/*}}}*/

/*Constant {{{*/
const int MAXN = 100;
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
int a[MAXN + 1];
int get[MAXN + 1];
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
//  freopen("a.in", "r", stdin);
//  freopen("a.out", "w", stdout);
  int n, x;
  cin >> n >> x;
  FOR(i, 1, n) cin >> a[i];
  sort(a + 1, a + n + 1);
  FOR(i, 1, n) {
    if (x > a[i]) x -= a[i];
    else if (x == a[i]) {
      cout << i << endl;
      return 0;
    }
    else {
      cout << i - 1 << endl;
      return 0;
    }
  }
  if (x) cout << n - 1 << endl;
  else cout << n << endl;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/


Measured memory_bytes: 256