akhauriyash/Code-Regression huggingface dataset:
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

bool solve() {
    string S;
    cin >> S;
    if (S == "#") return false;
    V<string> vs = { S } ;
    for (ll i = 25; 1 <= i; i--) {
        char src = 'a' + i;
        char dst = 'a' + (i - 1);
        V<string> buf;
        for (auto e : vs) {
            bool must = false;
            for (ll j = 0; j < e.size(); j++) {
                if (e[j] == src) {
                    must = true;
                    break;
                }
                if (e[j] == dst) {
                    e[j] = src;
                    buf.push_back(e);
                    e[j] = dst;
                }
            }
            if (!must) buf.push_back(e);
        }
        sort(ALL(buf));
        auto ite = unique(ALL(buf));
        buf.erase(ite, buf.end());
        vs = move(buf);
    }
        
    cout << vs.size() << endl;
    if (10 <= vs.size()) {
        for (ll i = 0; i < 5; i++) cout << vs[i] << endl;
        for (ll i = vs.size() - 5; i < vs.size(); i++) cout << vs[i] << endl;
    } else {
        for (auto &&e : vs) cout << e << endl;
    }
    return true;
}

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



Measured memory_bytes: 5028
#include<stdio.h>
#include<string.h>

int main(void)
{
    char S[100];
    fscanf(stdin, "%s", S);
    int i,j,len,count=0;
    len=strlen(S);
    for(i=0,j=len-1; i<len/2; i++,j--)
    {
        if(S[i]!=S[j])
        {
            count++;
        }
        else
        {
            continue;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
import numpy as np

N = int(input())
input_values = list(map(int, input().split()))
np_values = np.array(input_values)

def cost(np_values, a):
    """
    input:
        np_values = number list of input_values (N,)
        a = constant (1)
    
    output:
        cost = summation of the each L2 cost
    """
    
    cost = np.sum((np_values - a) ** 2)
    return cost
  
#test_values = np.array([1, 2, 3, 4])
#test_a = 3
#cost(test_values, test_a)

cost_list = []
for a in range(-100, 101):
    cost_list.append(cost(np_values, a))
print(min(cost_list))

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
long long a,b,x,y;
int main()
{
	scanf("%lld%lld",&a,&b);
	x=min(a,b);
	y=max(a,b);
	if(x==1)
	{
		if(y==1)
		{
			printf("1\n");
		}else
		{
			printf("%lld\n",y-2);
		}
	}else
	{
		printf("%lld\n",(x-2)*(y-2));
	}
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, x) for (auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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

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

    int n;
    cin >> n;
    vector<int> Q(n);
    rep(i, n) {
        int p;
        cin >> p;
        Q[p - 1] = i;
    }

    int max_conti = -1, conti = 1;
    for (int i = 0; i < n; ++i) {
        if (Q[i] < Q[i + 1]) {
            ++conti;
        } else {
            chmax(max_conti, conti); 
            conti = 1;
        }
    }

    cout << n - max_conti << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <math.h>
using namespace std;
using s64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    int zero_cnt = 0;
    int one_cnt = 0;
    rep(i,n)
    {
        if(s[i] == '0') ++ zero_cnt;
        else ++one_cnt;
    }

    int remove_cnt = 2 * min(zero_cnt, one_cnt);

    cout << remove_cnt << endl;
    return 0;
}

Measured memory_bytes: 512
score = []
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break
    if m == -1 or f == -1:
        score.append('F')
    elif 80 <= m + f:
        score.append('A')
    elif 65 <= m + f < 80:
        score.append('B')
    elif 50 <= m + f < 65:
        score.append('C')
    elif 30 <= m + f < 50:
        if 50 <= r:
            score.append('C')
        else:
            score.append('D')
    elif m + f < 30:
        score.append('F')
for s in score:
    print(s)


Measured memory_bytes: 5600
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

char s[105];
int n,w[26],f[26];

int main() {
	n=rd();
	memset(f,-1,sizeof f);
	For (i,1,n) {
		scanf("%s",s+1);
		memset(w,0,sizeof w);
		For (j,1,strlen(s+1)) w[s[j]-'a']++;
		For (j,0,25) if (f[j]==-1) f[j]=w[j]; else f[j]=min(f[j],w[j]);
	}
	For (i,0,25) if (f[i]!=-1) while (f[i]--) putchar('a'+i);
	return 0;
}






Measured memory_bytes: 128
import static java.lang.System.out;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int H = scan.nextInt();
            int W = scan.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int i = 0; i < H; i += 1) {
                for (int j = 0; j < W; j += 1) {
                    if (i == 0 || i == H - 1) {
                        out.print("#");
                    } else if (j == 0 || j == W - 1) {                 
                        out.print("#");
                    } else {
                        out.print(".");
                    }
                }
                out.println();
            }
            out.println();
        }
    }   
}

Measured memory_bytes: 34716
#include<bits/stdc++.h>
using namespace std;
int m[2000][2000];
int main()
{
	int a,b,s;
	cin>>a>>b;
	s=a-b;
	if(a==0||b==0)
	cout<<"Zero";
	if(a>0&&b<0||a<0&&b>0)
	cout<<"Zero";
	if(a>0&&b>0)
	cout<<"Positive";
	if(a<0&&b<0)
	{
		if(s%2==0)
		cout<<"Negative";
		else
		cout<<"Positive";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
         
int main() {
  int N,cmax=0;
  cin >> N;
  vector<int> C(N,0), V(N,0);
  
  for(int i=0; i<N; i++){
    cin >> V.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> C.at(i);
  }

  for(int i=0; i<N; i++){
    if(V.at(i)-C.at(i) > 0){
      cmax = cmax+V.at(i)-C.at(i);
    }
  }
    
  cout << cmax << endl;
}

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

typedef long long ll;

int main () {
	ll X;
	cin >> X;
	ll c=100;
	int n=0;
	while (c<X) {
		c = c*1.01;
		n++;
	}
	cout <<n << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] count = new int[N+1];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            count[A[i]]++;
        }

        long sum = 0;
        for (int i = 1; i <= N; i++) {
            if (count[i] >= 2) {
                sum += (long)count[i]*(count[i]-1)/2;
            }
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < N; i++) {
            long tmp = count[A[i]] == 2 ? sum-1 : sum-(count[A[i]]-1);
            ans.append(tmp).append('\n');
        }

        System.out.print(ans);
    }
}



Measured memory_bytes: 91796
import copy
N, M = map(int, input().split())
K = []
for i in range(N):
    x, y, z = map(int, input().split())
    K.append([x, y, z])

ans = 0
for i in range(2**3):
    dp = [[-10**12] * (M + 1) for _ in range(N + 1)]
    for u in range(N):
        dp[u][0] = 0
    P = copy.deepcopy(K)
    for l in range(3):
        if ((i >> l) & 1):
            for t in range(N):
                P[t][l] *= -1
    for j in range(1, N+1):
        for k in range(1, M+1):
            if k <= j:
                dp[j][k] = max([dp[j-1][k], dp[j-1][k-1] + sum(P[j-1])])
            else:
                dp[j][k] = dp[j-1][k]
    ans = max(ans, dp[N][M])

print(ans)

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

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

    int sumV = 0;
    for(int i=0; i<N; i++){
        sumV += A[i];
    }

    int cntPP = 0;
    for(int i=0; i<N; i++){
        if(!(A[i]*4*M < sumV)){
            cntPP++;
        }
        if(cntPP >= M){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  string a;
  cin>>a;
  int low,high;
  bool found = false;
  for(int i=0;i<a.length();i++){
  	if(a[i]=='A'&&!found){
  		low=i;
  		found=true;
  	}
  	if(a[i]=='Z'){
  		high=i;
  	}
  }
  cout<<high-low+1<<endl;
}









Measured memory_bytes: 720
if __name__ == '__main__':
    S = input()

    bit_num = 2 ** (len(S) - 1)

    ans = 0
    for i in range(bit_num):
        formula = S[0]
        for j in range(len(S) - 1):
            if i & 2 ** j:
                formula += "+"
            formula += S[j + 1]

        ans += eval(formula)

    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  string v[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

  string s;
  cin>>s;
  int ans=0;
  rep(i,7){
    if(s==v[i]) ans=i;
  }

  cout<<7-ans<<endl;


}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int x[15],l[15],r[15];
int kase;
void dfs(int i,int j,int k)//i 是当前下落的球，j是左?的桶的第几个球，k 是右?放入
{
    if(i>10)//如果可以全部下落，肯定?足
    {
        kase=1;
        return;
    }
    if(kase)
    {
        return;
    }
    if(x[i]>l[j-1])//??落在左?
    {
        l[j]=x[i];dfs(i+1,j+1,k);
    }
    if(x[i]>r[k-1])//??落在右?
    {
        r[k]=x[i];dfs(i+1,j,k+1);
    }
}
int main()
{
    int t;
    //freopen("shuju.txt","r",stdin);
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1;i<=10;++i)
        {
            scanf("%d",&x[i]);
        }
        kase=0;
        dfs(1,1,1);
        if(kase)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2588
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  vi x(m); rep(i, m) cin >> x[i];
  sort(all(x));

  if(n >= m){
    std::cout << 0 << '\n';
    return 0;
  }

  vi y(m-1); rep(i, m-1) y[i] = x[i+1] - x[i];
  sort(all(y));
  int ans = 0;
  rep(i, m-n) ans += y[i];

  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int n,i,j,k,key,s[100];
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0; i<n; i++)
            scanf("%d",&s[i]);
        for(i=0; i<n; i++)
        {
            key=s[i];
            j=i-1;
            while(j>=0&&s[j]>key)
            {
                s[j+1]=s[j];
                j--;
            }
            s[j+1]=key;
            for(k=0; k<n; k++)
            {
                printf("%d",s[k]);
                if(k!=n-1)
                    printf(" ");
                else
                    printf("\n");
            }
        }
    }
    return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using R=long double;
using P=complex<R>;
const int vmax=210;

vector<int> graph[vmax];
int match[vmax];
bool used[vmax];

bool dfs(int v){
	used[v]=true;
	for(auto &u:graph[v]){
		int w=match[u];
		if(w < 0 || (!used[w] && dfs(w)) ){
			match[v]=u,match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(int n,int m){
	int res=0;
	rep(i,vmax) match[i]=-1;
	rep(v,n+m){
		if(match[v]<0){
			rep(i,vmax) used[i]=0;
			if(dfs(v)) res++;
		}
	}
	return res;
}

int tx[110],ty[110],tv[110];
int bx[110],by[110];


int main(void){
	int n,m;
	while(cin >> n >> m,n){
		rep(i,n) cin >> tx[i] >> ty[i] >> tv[i];
		rep(i,m) cin >> bx[i] >> by[i];

		R left=0.0,right=1e10;
		rep(loop,200){
			const R mid=(left+right)/2.0;
			rep(i,vmax) graph[i].clear();
			rep(i,n)rep(j,m){
				R d=abs(P(tx[i]-bx[j],ty[i]-by[j]));
				if(tv[i]*mid>d){
					graph[i].push_back(j+n);
					graph[j+n].push_back(i);
				}
			}
			int ret=bipartite_matching(n,m);
			if(ret>=m)
				right=mid;
			else
				left=mid;
		}
		cout.precision(20);
		cout << fixed << left << endl;
	}
	return 0;
}

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

int main() {
    int n,i;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
       cin>>a[i]>>b[i]>>c[i];
    int dp[n][3];
    memset(dp,-1,sizeof(dp));
    dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
    //findmaxhappiness(a,b,c,dp,n,0);
    for(i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    int res=max(dp[n-1][0],dp[n-1][1]);
    res=max(res,dp[n-1][2]);
    cout<<res;
	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||b+c==a||c+a==b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h_array = list(map(int, input().split()))
flags = [1 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    h_a, h_b = h_array[a], h_array[b]
    if h_a > h_b:
        flags[b] = 0
    elif h_a < h_b:
        flags[a] = 0
    else:
        flags[a], flags[b] = 0, 0
print(sum(flags))

Measured memory_bytes: 20040
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,l,m,n,p,s,t,x,y,a[200040],b[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;++i<n;)
	{
		cin>>x>>y;
		if(x>y)swap(x,y);
		a[y]+=x;
	}
	for(i=0;i++<n;)
	{
		m+=i-a[i];
		s+=m;
	}
	cout<<s;
}

Measured memory_bytes: 5128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	deque<int> a;
	for (int i = 0; i < n; i++)
	{
		int q;
		cin >> q;

		int d, x;

		switch (q)
		{
			case 0:
				cin >> d;
				cin >> x;
				if (d == 0)
				{
					a.push_front(x);
				}
				else
				{
					a.push_back(x);
				}
				break;

			case 1:
				cin >> x;
				println(a[x]);
				break;

			case 2:
				cin >> d;
				if (d == 0)
				{
					a.pop_front();
				}
				else
				{
					a.pop_back();
				}
				break;
		}
	}
}




Measured memory_bytes: 4624
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
lis=sorted(list(zip(a, b)))
ans=0
tmp=0
i=0
flag=False
while True:
    ans+=lis[i][0]*lis[i][1]
    tmp+=lis[i][1]
    if tmp>=m:
        flag=True
        ans-=(tmp-m)*lis[i][0]
        break
    i+=1
print(ans)

Measured memory_bytes: 19284
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define nn 500008
int deg[nn];vector<int> v[nn],rv[nn];
int dp[nn];
int n;char str[nn];
void link(int x,int y){
	v[y].push_back(x);rv[x].push_back(y);
	deg[y]++;
}
signed main(){
	scanf("%s",str+1);int n=strlen(str+1)+1;
	for(int i=1;i<n;i++)
		if(str[i]=='<') link(i,i+1);
		else link(i+1,i);
	
	queue<int> q;
	for(int i=1;i<=n;i++) if(!deg[i]) q.push(i);
	while(q.size()){
		int x=q.front();q.pop();
		for(int i=0;i<rv[x].size();i++){
			int y=rv[x][i];dp[y]=max(dp[y],dp[x]+1);
			deg[y]--;if(!deg[y]) q.push(y);
		}
	}
	
	
	int ans=0;for(int i=1;i<=n;i++) ans+=dp[i];
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 63232
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())

	A := make([]int, N)
	arr := make([]int, 0, N)
	for i := 0; i < N; i++ {
		A[i], _ = strconv.Atoi(read())
	}
	for i := 0; i < N; i++ {
		m := binary_tree(len(arr), -1, A[i], arr)
		if m == len(arr) {
			arr = append(arr, A[i])
		} else {
			arr[m] = A[i]
		}
	}
	fmt.Println(len(arr))
}

func binary_tree(right, left, target int, a []int) int {
	if len(a) == 0 {
		return len(a)
	}
	for left < right-1 {
		c := (left + right) / 2
		if a[c] < target {
			right = c
		} else {
			left = c
		}
	}
	return right
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 3840
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

result = 0
for n in range(N):
    result += B[A[n]-1]
    if n != 0:
        if A[n]-A[n-1] == 1:
            result += C[A[n-1]-1]
print(result)

Measured memory_bytes: 3064
using System;

class MainClass {
    static void Main() {
        string[] s = Console.ReadLine().Split(' ');
        int d = int.Parse(s[0]);
        int n = int.Parse(s[1]);
        if (n != 100)Console.WriteLine(n * Math.Pow(100, d));
        else Console.WriteLine((n+1) * Math.Pow(100, d));
    }
}

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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))

using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

int main(){
  string ch;

  getline(cin,ch);
  REP(i,ch.size()){
  if(isalpha(ch[i])){
  if('a'<=ch[i]&&ch[i]<='z'){
    ch[i]-=32;
    cout<<ch[i];
  }else if('A'<=ch[i]&&ch[i]<='Z'){
    ch[i]+=32;
    cout<<ch[i];
  }
  }else{
    cout<<ch[i];
  }
  }
  cout<<endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

  int N;
  cin >> N;
  map<int,int> A;

  int a;
  REP(i, N) {
    cin >> a;
    if(A.find(a) == A.end()) {
      A.insert({a,1});
    } else {
      A.find(a)->second++;
    }
  }

  vector<int> l;
  for(auto itr = rbegin(A); itr != rend(A); ++itr) {
    while (itr->second >= 2 && l.size() < 2) {
      l.pb(itr->first);
      itr->second -= 2;
    }
    if (l.size() == 2) {
      cout << l[0] * l[1] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

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

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

int main(void){
    string S,T; cin >> S >> T;
    int N = S.size();
    cout << (S == T.substr(0,N) ? "Yes" : "No") << en;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int l[100000];
int r[100000];
int f[100000];

int main() {
    int n, x = 0, i, j, k;
    long long ans = 0, sum = 0;
    vector <pair<int, int>> v, w;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d %d", &l[i], &r[i]);
    
    for (i = 0; i < n; i++) v.push_back(make_pair(l[i], i));
    for (i = 0; i < n; i++) w.push_back(make_pair(r[i], i));
    
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    reverse(v.begin(), v.end());
    
    for (i = 0, j = 0, k = 0; i < n; i++) {
        if (i % 2 == 0) {
            while (f[v[j].second] == 1) j++;
            
            if (v[j].first >= x) {
                sum += v[j].first - x;
                x = v[j].first;
                f[v[j].second] = 1;
            }
        } else {
            while (f[w[k].second] == 1) k++;
            
            if (x >= w[k].first) {
                sum += x - w[k].first;
                x = w[k].first;
                f[w[k].second] = 1;
            }
        }
    }
    
    sum += abs(x);
    
    ans = max(ans, sum);
    
    x = 0;
    sum = 0;
    for (i = 0; i < n; i++) f[i] = 0;
    
    for (i = 0, j = 0, k = 0; i < n; i++) {
        if (i % 2 == 1) {
            while (f[v[j].second] == 1) j++;
            
            if (v[j].first >= x) {
                sum += v[j].first - x;
                x = v[j].first;
                f[v[j].second] = 1;
            }
        } else {
            while (f[w[k].second] == 1) k++;
            
            if (x >= w[k].first) {
                sum += x - w[k].first;
                x = w[k].first;
                f[w[k].second] = 1;
            }
        }
    }
    
    sum += abs(x);
    
    ans = max(ans, sum);
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 3316
void main(){
	ulong n, k;
	readf("%d %d\n", &n, &k);
	ulong[] a = _scanln!ulong();
	
	foreach(i; k..a.length){
		writeln(a[i-k] < a[i]? "Yes": "No");
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var n = input[0];
            var k = input[1];
            var h = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(s => s).ToList();
            Func<int, bool> judge = i => h[i] >= k;

            var ans = judge(0) ? SearchLast(judge, 0, n - 1) + 1 : 0;
            Console.WriteLine(ans);
        }

        public static int SearchLast(Func<int, bool> f, int min, int max)
        {
            if (f(max)) return max;
            var k = min + (max - min) / 2;

            return f(k) ? SearchLast(f, k, max - 1) : SearchLast(f, min, k);
        }
    }
}


Measured memory_bytes: 20576
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];

		int ans = 0;
		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt();
			if(i % 2 == 0 && a[i] % 2 != 0) {
				ans++;
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 35888
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	while(cin >> n, n){
		int ans = 1000000;
		for(int z=0;z*z*z<=n;z++)for(int y=0;z*z*z+y*y<=n;y++) ans = min(ans, z+y+n-z*z*z-y*y);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main()
{
	char c[11][20]={"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};
	double h,sum=48.0,j;
	int i;

	while(scanf("%lf",&h)!=EOF)
	{
		sum=48.0;
		if(h<=48.0)
			i=0;
		else if(h>91.0)
			i=10;
		else
		{
			for(i=1;i<10;i++)
			{
				if(i<=4)
					j=3.0;
				else if(i<=7)
					j=(double)i-1.0;
				else if(i==8)
					j=6.0;
				else
					j=10.0;
				if(sum<h&&sum+j>=h)
						break;
				sum+=j;
			}
		}
		printf("%s\n",c+i);
	}

	return 0;
}

Measured memory_bytes: 608
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#N = int(input())
	#S = list(input())
	N,D = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	Xs = []
	for i in range(N):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		Xs.append(tmp)

	ans = 0
	for i, val in enumerate(Xs):
		for ii in range(i+1, len(Xs)):

			vol = Xs[ii]

			to = 0
			for j in range(D):
				tmp = (abs(vol[j] - val[j]))**2
				to += tmp

			to = to ** (1/2)
			#print(to)
			if to.is_integer():
				ans += 1

	print(ans)




if __name__ == "__main__":
	main()

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
int n=0,ans=0,a[200000];
main() {
	cin>>n;
	for(int i=1,x;i<=n;i++) scanf("%d",&x),a[x]++;
	for(int x=-1;x<=(int) 1e5  + 10;x++)
		ans=max(ans,a[x]+a[x-1]+a[x+1]);
	cout<<ans<<"\n";
}

Measured memory_bytes: 640
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, a, b, dp[maxn][2], p[maxn][2], v[maxn];
int A[maxn], B[maxn], aF[maxn], bF[maxn];
ll get(ll l, ll r, ll t) {
	if(l > r) return 0;
	return (mod + p[r][t] - (l>0?p[l-1][t]:0))%mod;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++) cin >> v[i];
	v[0] =  -(1ll<<61);
	v[n + 1] = 1ll<<61;
	A[0] = B[0] = aF[0] = bF[0] = 0;
	for(int i = 1; i <= n+1; i++) {
		if(i) A[i] = A[i-1], B[i] = B[i-1], aF[i] = aF[i-1], bF[i] = bF[i-1];
		if(v[i] - v[i-1] < a) A[i] = i;
		if(v[i] - v[i-1] < b) B[i] = i;
		while(aF[i] < i && v[i] - v[aF[i]+1] >= a) aF[i]++;
		while(bF[i] < i && v[i] - v[bF[i]+1] >= b) bF[i]++;
	}
	memset(dp, 0, sizeof dp);
	memset(p, 0, sizeof p);
	dp[0][0] = dp[0][1] = p[0][1] = p[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		dp[i][0] = get(A[i]-1, min(i-1, bF[i+1]), 1);
		p[i][0] = (p[i-1][0] + dp[i][0])%mod;
		dp[i][1] = get(B[i]-1, min(i-1, aF[i+1]), 0);
		p[i][1] = (p[i-1][1] + dp[i][1])%mod;
	}
	cout << (dp[n][0]+dp[n][1])%mod;
}
//1 3 6 9 12


Measured memory_bytes: 13440
n,m=map(int,input().split())
mod=10**9+7
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
Sx,Sy=0,0
for i in range(n):
  Sx+=((2*i-n+1)*x[i])%mod
  Sx%=mod
for j in range(m):
  Sy+=((2*j-m+1)*y[j])%mod
  Sy%=mod
print((Sx*Sy)%mod)

Measured memory_bytes: 83684
#include <bits/stdc++.h>
using namespace std;
std::vector<int> v;

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

// 	while(N!=0){
// 	     v.push_back(N%10);
// 	     N/=10;
// 	}
	int sum = 0;
	for(auto x:N){
	     sum+=((int)x)-48;
	    // cout << x << " ";
	}
// 	cout << sum << endl;
     // cout << N.size() << endl;
	int ans = 9*(N.size()-1);
// 	cout << ans << endl;
// 	cout << ((int)N[N.size()-1]) << endl;
	
	ans+=((int)N[0])-49;
	cout  << max(ans,sum) << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
      int a, b;
      cin >> a >> b;
      if (b>=a)cout << "unsafe" << endl;
      else cout << "safe" << endl;
 	return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    int res = 0;
    rep(i, 3) {
        if(S[i] == 'R') {
            cnt++;
        } else {
            cnt = 0;
        }
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
int n, m, k;
int par[N];
int sz[N];
bool f[N];

struct Edge {
	int v, u;
	ll w;

	Edge() : v(), u(), w() {}

	void scan() {
		scanf("%d%d%lld", &v, &u, &w);
		v--;
		u--;
		u += n;
	}

	bool operator < (const Edge &e) const {
		return w > e.w;
	}
};
Edge ed[N];

int getPar(int v) {
	return par[v] == -1 ? v : par[v] = getPar(par[v]);
}
bool unite(int v, int u) {
	v = getPar(v);
	u = getPar(u);
	if (v == u) {
		if (f[v]) return false;
		f[v] = true;
		return true;
	}
	if (f[v] && f[u]) return false;
	if (sz[v] < sz[u]) swap(v, u);
	sz[v] += sz[u];
	f[v] |= f[u];
	par[u] = v;
	return true;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d%d", &m, &n, &k);
	for (int i = 0; i < m; i++)
		ed[i].scan();
	n += k;
	sort(ed, ed + m);
	for (int i = 0; i < n; i++) {
		par[i] = -1;
		sz[i] = 1;
		f[i] = 0;
	}
	ll ans = 0;
	for (int i = 0; i < m; i++)
		if (unite(ed[i].v, ed[i].u))
			ans += ed[i].w;
	printf("%lld\n", ans);

	return 0;
}


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

using namespace std;

int ans[100];

void solve(int n, int p);
void print(int p);

int main() {
    int n;

    while (cin >> n) {
        if(n == 0) break;

        solve(n, 0);
    }

    return 0;
}

void solve(int n, int p) {
    if(n <= 0) {
        print(p);
    } else {
        for (int i=n; i>0; i--) {
            if (p == 0 || ans[p-1] >= i) {
                ans[p] = i;
                solve(n-i, p+1);
            }
        } 
    }
}

void print(int p) {
    for(int i=0; i<p-1; i++) {
        cout << ans[i] << " ";
    }
    cout << ans[p-1] << endl;
}

Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for(int i=0;i<n;i++){
    double d; cin >> d;
    v[i] = d;
  }
  sort(v.begin(), v.end());
  double ans=0;
  if(n<=2){
    ans = (v[0]+v[1])/2;
  }else if(n>=3){
    ans = (v[0]+v[1])/2;
    for(int i=2;i<n;i++){
      ans = (ans+v[i])/2;
  }
  }
  printf("%.8f",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long int factorial(long long int k){
    long long int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
        sum %= MOD;
    }
    return sum;
}
int main()
{
    int n,m;
    cin >> n >> m;
    if(fabs(n - m) >= 2)
    {
        cout << "0";
    }
    else if(fabs(n - m) == 1)
    {
        cout << (factorial(n) * factorial(m)) % MOD;
    }
    else
    {
        cout << (((factorial(n) * factorial(m)) % MOD) * 2) % MOD;
    }
    
    return 0;
}

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

#define zton(i,n) for(int i=0;i<=n;i++)
#define oneton(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define loop(i,b,a) for(int i=a;i>=b;i--)
#define dsort(arr,n) sort(arr, arr + n, greater<int>())
#define vsortd(a) sort(a.begin(), a.end(), greater<double>())
#define vsort(a) sort(a.begin(), a.end())
#define ll long long int
#define test int tc;cin>>tc;while(tc--)
#define dbg(x) cout<<#x<<'='<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl<<#w<<"="<<(w)<<endl;
#define minheap priority_queue <int, vector<int>, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define ff first
#define ss second
#define mpr make_pair
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mkv vector<int>
#define allzero(dp) memset(dp,0,sizeof(dp))
#define endl "\n"
#define print(x) cout<<x<<endl;

const int mod=1e9+7;
using namespace std;
bool sortcol( const vector<int>& v1,const vector<int>& v2 ) {return v1[1] < v2[1];}

void fastio()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b){
    if(a.first>b.first)return true;
    if(a.first==b.first)return a.second<b.second;
    return false;
}

ll power(ll x, ll y){
    ll res = 1;x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;x=(x*x)%mod;}
    return res;
}

vector<int>ch;
void solve()
{
    string s;cin>>s;
    char r='R';
    if(s[0]==r&&s[1]==r&&s[2]==r){
        print(3)
        return;
    }
    if(s[1]==r){
        if(s[0]==r||s[2]==r){
            print(2)
            return;
        }
    }
    if(s[0]==r||s[1]==r||s[2]==r){
        print(1)
        return;
    }
    print(0)
}

int main()
{
  //  fastio();
   // test
    solve();
}


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


int main() {
  int n; cin >> n;
  vector<int> vec(n);
  int sum = 0;
  
  for(int i=0; i < n; i++){
    int t; cin >> t;
    vec.at(i) = t;
    sum += t;
  }
  
  int m; cin >> m;
  
  for(int i=0; i < m; i++){
    int p,x; cin >> p >> x;
    cout << sum - (vec.at(p-1) - x) << endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
using std::cin,std::cout;
using std::string;

int main(){
  int n,r=0,m=0;
  string s;
  cin>>n>>s;
  for(auto &c:s){
    if(c=='R') r++;
  }
  for(auto &c:s.substr(0,r)){
    if(c=='W') m++;
  }
  cout<<m;
  return 0;
}

Measured memory_bytes: 3732
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll k,n;
        cin>>k>>n;
        ll a[n+3];
        for(int i=1;i<=n;i++)
            {
                cin>>a[i];
            }
        ll x=0;
        for(int i=2;i<=n;i++)
        {
            x=max(x,a[i]-a[i-1]);
        }
        cout<<min(k-x,a[n]-a[1]);

        
    }
    return 0;
}

Measured memory_bytes: 1792