akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
typedef long long ll;
cpnst ll mod=998244353,inv2=(mod+1)>>1;
ll qpow(ll x,ll k)
{ll r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
ll N,A[1111111];
void FWT(ll*x,int op)
{
	for(register int i=1,ii,iii;i<N;i<<=1)
		for(ii=0;ii<N;ii+=(i<<1))
			for(iii=0;iii<i;iii++)
			{
				int px=ii+iii,py=px+i;
				ll vx=x[px]+x[py],vy=x[px]-x[py]+mod;
				if(op<0)vx*=inv2,vy*=inv2;
				x[px]=vx%mod,x[py]=vy%mod;
			}
}
ll C[1111111];
int main()
{
	scanf("%lld",&N),N=1<<N;
	register int i;
	ll S=0;
	for(i=0;i<N;i++)
		scanf("%lld",A+i),S+=A[i];
	S=qpow(S,mod-2);
	for(i=0;i<N;i++)(A[i]*=S)%=mod; 
	C[0]=N-1,A[0]=(mod-1+A[0])%mod;
	for(i=1;i<N;i++)C[i]=mod-1;
	FWT(C,1),FWT(A,1);
	for(i=0;i<N;i++)C[i]=qpow(A[i],mod-2)*C[i]%mod;
	FWT(C,-1);
	for(i=0;i<N;i++)printf("%lld\n",(C[i]-C[0]+mod)%mod);
}
/*
Just go for it.
*/

Measured memory_bytes: 7036
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define REPR(i,n) for(int i = n; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    REP(i,S.size()){
        if(S[i] == 'o')cnt++;
    }
    if(15 - S.size() + cnt >= 8) cout << "YES\n";
    else cout << "NO\n";
}

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

def main():
    s = input()
    q = int(input())
    q_list = list()

    for i in range(q):
        q_list.append(input())

    r_flg = True
    s_str = ''
    e_str = ''

    for query in q_list:
        # query 1
        if query[0] == '1':
            r_flg = not r_flg
        
        # query 2
        else:
            # Fi = 1
            if query[2] == '1':
                if r_flg:
                    s_str = query[4] + s_str
                else:
                    e_str = e_str + query[4]
            # Fi = 2
            else:
                if r_flg:
                    e_str = e_str + query[4]
                else:
                    s_str = query[4] + s_str

        # print('cont:{}, s:{}, r_flg:{}'.format(i, s, r_flg))

    s = s_str + s + e_str

    if not r_flg:
        s = ''.join(reversed(s))

    print(s)

if __name__ == "__main__":
    main()


Measured memory_bytes: 17920
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)

int main() {
    ll N;
    cin>>N;
    vector<ll> A(N,-1);
    rep(i,N){
        cin>>A[i];
    }
    for(ll x: A){
        if (x==0){
            cout<<0<<endl;
            return 0;
        }        
    }
    ll ans=1;
    ll limit = 1000000000000000000;
    for(ll x: A){
        if (ans > limit/x){
            cout<<-1<<endl;
            return 0;
        }
        ans *= x;
    }
    if (ans > limit){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,ans,jc[1000001]={1};
int qpow(int i,int j){return j?j&1?qpow(i*i%mod,j>>1)*i%mod:qpow(i*i%mod,j>>1):1;}
int c(int i,int j)
{
	return jc[i]*qpow(jc[j]*jc[i-j]%mod,mod-2)%mod;
}
signed main()
{
	for(int i=1;i<=1000000;i++)jc[i]=jc[i-1]*i%mod;
	scanf("%lld",&n);
	for(int i=2;i<=n;i++)ans=(ans+(mod+qpow(2,i)-2)*qpow(8,n-i)%mod*c(n,i))%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 11620
import numpy as np
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
p = [K] * N
s = [-Q] * N
for n in A:
  s[n-1] += 1
sum = np.array(p) + np.array(s)
for num in sum:
  if num>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 22092
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    int price = 0;
    for (size_t i = 0; i < N; i++) {
        if (i < K) {
            price += X;
        } else {
            price += Y;
        }
    }
    cout << price << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll dp[51][51];
int a[51];
int main(){
    int n,p,ai;
    cin>>n>>p;
    rep(i,n){
        cin>>ai;
        ai%=2;
        a[i]=ai;
    }
    dp[0][0]=1;
    rep(i,n)rep(j,2){
        dp[i+1][j]+=dp[i][j];
        dp[i+1][(j+a[i])%2]+=dp[i][j];
    }
    cout<<dp[n][p]<<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);
        // 整数の入力
        int a = sc.nextInt();

        int b = sc.nextInt();

        int c = sc.nextInt();


        if (22 <= a + b + c) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }

    }
}


Measured memory_bytes: 21844
def main(input = STDIN)
  sum = 0
  first, second = input.gets.split(",").map(&:to_f), input.gets.split(",").map(&:to_f)
  while (cood = input.gets)
    cood = cood.split(",").map(&:to_f)
    sum += area(*first, *second, *cood)
    second = cood
  end
  puts sum
end
def area(x1, y1, x2, y2, x3, y3)
  a, b, c = e_distance(x1, y1, x2, y2), e_distance(x2, y2, x3, y3), e_distance(x3, y3, x1, y1)
  z = (a + b + c) / 2
  return (z * (z - a) * (z - b) * (z - c)) ** 0.5
end
def e_distance(x1, y1, x2, y2)
  return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
end
#File.open('data'){|f|main(f)}
# >> 2.499999999999999
main

Measured memory_bytes: 6180
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> pll;
#define pb push_back
int main()
{
    ll d,n,cnt=0;

    cin>>n>>d;

    vector<ll>v;

    while(n--)
    {
       double a,b,ans=0;

        cin>>a>>b;

        a*=a;

        b*=b;

       ans=sqrt(a+b);

        if(ans<=d)
        {
            cnt++;

        }

    }


    cout<<cnt<<endl;

}








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

int main(){
    rep(i, 5) {
        int a;
        cin >> a;
        if (a == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }
}

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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A < C && C < B) {
		cout << "Yes" << endl;
	}
	else if (B < C && C < A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	} 
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,m;
long long a[200001],b[200001],d[200001],k;

void nhap()
{
    scanf("%d %d %lld",&n,&m,&k);
    for (int i=1;i<=n;++i)
    {
        scanf("%lld",&a[i]);
    }
    for (int i=1;i<=m;++i)
    {
        scanf("%lld",&b[i]);
        d[i]=d[i-1]+b[i];
    }
}

void process()
{
    int ma=0;
    for (int i=0;i<=n;++i)
    {
        k-=a[i];
        if (k<0) break;
        int vt=lower_bound(d+1,d+1+m,k)-d;
        if (k!=d[vt]) vt--;
        ma=max(ma,i+vt);
    }
    cout<<ma;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 8416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;

ll solve() {
    ll N, M;
    cin >> N >> M;
    if ( abs(N-M) > 1 ) return 0;

    ll ans = 1;
    for ( ll i = 1; i <= N; i++ ) {
        ans = ans * i % MOD;
    }
    for ( ll i = 1; i <= M; i++ ) {
        ans = ans * i % MOD;
    }
    if ( N == M ) {
        ans = ans * 2 % MOD;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >>C >>D;
  if((A+B) < (C+D)){
    cout << "Right" << endl;
  }
  else if((A+B) > (C+D)){
    cout << "Left" << endl;
  }
  else if((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> dp(114514,vector<int>(3,0));
  cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
  for(int i=1;i<n;++i){
    int a,b,c;
    cin>>a>>b>>c;
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
  }
  cout<<max({
    dp[n-1][0],
    dp[n-1][1],
    dp[n-1][2]
  });
}


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

int main(){
    ll D, N;
    cin >> D >> N;
    vector<ll> ans;
    for(ll i = 0; i <= 1e7; i += pow(100LL,D)){
        if(i % (ll)pow(100LL, D+1) != 0) ans.push_back(i);
        if(ans.size() == N) break;
    }
    cout << ans[N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h += [10 ** 10]

ans = 0
x = 0
for i in range(n):
    if h[i] >= h[i+1]:
        x += 1
    else:
        if ans < x:
            ans = x
        x = 0
        
print(ans)

Measured memory_bytes: 14224
package main
import "fmt"

func main(){
  var n string
  f:=false
  fmt.Scan(&n)

 for i:=0;i<=len(n)-3;i++ {
   if(n[i]==n[i+1]&&n[i+1]==n[i+2]){
     f = true
   }
 }
  var x string
 if f {
  x="Yes"
 }else {
  x="No"
 }

 fmt.Println(x)

}


Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = ll(1e9)+7;
const ll inf = ll(5e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

class CRally {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    vector<int> x(n);
	    for(int i=0; i<n; i++){
	        in >> x[i];
	    }
	    ll res = inf;
	    for(int i=0; i<=100; i++){
	        ll sum = 0;
	        for(int j=0; j<n; j++){
                sum += (x[j] - i)*(x[j] - i);
	        }
	        chmin(res, sum);
	    }

	    out << res << endl;
	}
};


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(begin(a),end(a));
	ll x=a[n/2];
	ll ans=0;
	rep(i,n){
		ans+=abs(a[i]-x);
	}
	cout<<ans<<endl;
}

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

namespace AtCoder0815
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            //int N = int.Parse(Console.ReadLine());
            //int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            string  S = Console.ReadLine();
            int ans = 0;

            if (S.IndexOf("R") != -1) { ans = 1; }
            if (S.IndexOf("RR") != -1) { ans = 2; }
            if (S == "RRR") { ans = 3; }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vint a = in(n);

    vint col(8, 0);
    int any = 0;
    rep(i, n)
    {
        if (a[i] < 3200)
        {
            ++col[a[i] / 400];
        }
        else
        {
            ++any;
        }
    }

    int col_num = 0;
    rep(i, 8)
    {
        if (col[i])
            ++col_num;
    }
    int mi = 0, ma = 0;

    if (col_num == 0)
    {
        mi = 1;
        ma = any;
    }
    else
    {
        mi = col_num;
        ma = col_num + any;
    }
    cout << mi << " " << ma << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll x,y;
    cin >> x >> y;
    ll ans = MAXINF;
    ans = min(ans, (ll)((y-x)<0?(MAXINF):(y-x)));
    ans = min(ans, (ll)((y+x)<0?(MAXINF):(y+x)+1));
    ans = min(ans, (ll)((-y-x)<0?(MAXINF):(-y-x)+1));
    ans = min(ans, (ll)((-y+x)<0?(MAXINF):(-y+x)+2));

    pr(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c,N;
    N=0;
    scanf("%d %d %d",&a,&b,&c);
    
    for(int x = a;x <= b;x++){
        if(c%x == 0){
            N++;
        }
    }
    printf("%d\n",N);
    return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top, S[1000];
 
void push(int x){
  S[++top] = x;
}
 
int pop(){
  top--;
  return S[top+1];
}
 
int main(){
  int a, b;
  top = 0;
  char s[100];
 
  while( scanf("%s", s) != EOF ){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(b+a);
    }else if(s[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(b*a);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main () {
  int N;
  vector<int> P;
  vector<pair<int, int>> v;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    P.push_back(p);
    v.push_back(make_pair(p, i));
  }

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  set<int> s;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long pos = v[i].second;
    int val = v[i].first;
    s.insert(v[i].second);

    set<int>::iterator itr1 = s.find(v[i].second);
    long long left = 0;
    bool add_left = false;
    if (itr1 != s.begin()) {
      itr1--;
      left = *itr1 + 1;
      add_left = true;
    }

    set<int>::iterator itr2 = s.find(v[i].second);
    bool add_right = false;
    itr2++;
    long long right = N - 1;
    if (itr2 != s.end()) {
      right = *itr2 - 1;
      itr2++;
      add_right = true;
    }

    if (add_left) {
      long long lleft = 0;
      if (itr1 != s.begin()) {
        itr1--;
        lleft = *itr1 + 1;
      } else {
        lleft = 0;
      }
      ans += val * (right - pos + 1) * (left - lleft);
    }

    if (add_right) {
      long long rright = 0;
      if (itr2 != s.end()) {
        rright = *itr2 - 1;
      } else {
        rright = N-1;
      }
      ans += val * (pos - left + 1) * (rright - right);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6128
#include<iostream>
using namespace std;
int m[9][9];
int w,h;
string s;
main()
{
	while(cin>>s,s!="#")
	{
		h=w=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='/')w=!++h;
			else
			{
				if(s[i]=='b')m[h][w++]=1;
				else
				{
					for(int j=0;j<s[i]-'0';j++)m[h][w++]=0;
				}
			}
		}
		w--;
		int a,b,c,d;cin>>a>>b>>c>>d;
		a--,b--,c--,d--;
		m[a][b]=0,m[c][d]=1;
		for(int i=0;i<=h;i++)
		{
			for(int j=0;j<=w;)
			{
				if(m[i][j++])cout<<'b';
				else
				{
					int cnt=0;
					j--;
					while(j<=w&&!m[i][j])cnt++,j++;
					cout<<cnt;
				}
			}
			if(i!=h)cout<<'/';
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7+5;
const ll inf=2e18;
const int mod=998244353;
string s;
int main(){
    cin>>s;
    if(s[s.length()-1]=='s')s+="es";
    else s+='s';

    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3648
n = int(input())

def factorization(n):
    arr = []
    if n == 1:
        return arr
    tmp = n
    for i in range(2,int(n**0.5)+1):
        if tmp%i == 0:
            cnt = 0
            while tmp%i == 0:
                cnt += 1
                tmp //= i
            arr.append([i,cnt])
    if tmp != 1:
        arr.append([tmp,1])
    if arr == []:
        arr.append([n,1])
    return arr

f_list = factorization(n)    
cnt = 0
for i in range(len(f_list)):
    _tmp = f_list[i][1]
    e = 1
    while _tmp - e >= 0:
        cnt += 1
        _tmp -= e
        e += 1
print(cnt)


Measured memory_bytes: 9436
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

int modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 
 ll dp[200000];

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

ll nck(ll n, ll k) {
	ll ans=1;
	for(int i=1; i<=k; ++i)
		ans=ans*(n-i+1)%mod*dp[i]%mod;
	return ans;
}
	int main(){
    string s; cin >> s; 
    int n = s.size();
    reverse(all(s));
 
    vector<vi> dp(n+1,vi(2,(1<<29)));
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        int x = s[i] - '0';
        dp[i+1][0] = min(dp[i][0]+x, dp[i][1]+x);
        dp[i+1][1] = min(dp[i][0]+1+10-x, dp[i][1]-1+1+10-x-1);
    }
 
    cout << min(dp[n][0], dp[n][1]) << endl;
    
}


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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(s[i]=='1') s[i]='9';
    else s[i]='1';
  }
  cout<<s<<endl;
}

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

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

    int t = 1, ans = 1;
    for (int i = 1; i < N; i++) {
        if (P[i] > P[i - 1]) {
            t++;
        } else {
            t = 1;
        }

        ans = max(ans, t);
    }
    cout << N - ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int n;
	cin>>n;
	vector<int> t(n);
	ll su = 0;
	for(int i=0;i<n;i++){
		cin>>t[i];
		su += t[i];
	}
	int m;
	cin>>m;
	vector<ll> ans(m);
	for(int i=0;i<m;i++){
		int p,x;
		cin>>p>>x;
		p--;
		ans[i] = su - t[p] + x;
	}
	for(int i:ans){
		cout<<i<<endl;
	}
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var V, C []int

func main() {
	var N int
	fmt.Scan(&N)

	V = make([]int, N)
	C = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&V[i])
	}
	for i := 0; i < N; i++ {
		fmt.Scan(&C[i])
	}
	fmt.Println(dfs(0, 0, N-1))
}

func dfs(v int, c int, n int) int {
	if n < 0 {
		return v - c
	}

	x := dfs(v+V[n], c+C[n], n-1)
	y := dfs(v, c, n-1)

	if x < y {
		return y
	}
	return x
}


Measured memory_bytes: 512
import collections
N = int(input())
A = list(map(int,input().split()))
A.sort()
A2 = set(A)
c = collections.Counter(A)
# print(A)
a = [0]*((10**6)+1)
ans = 0
for i in A2:
    k = 1
    while k <= A[-1]//i:
        a[i*k] += 1
        k += 1
for i in range(1,A[-1]+1):
    if c[i] == 1:
        if a[i] == 1:
            ans += 1
print(ans)

Measured memory_bytes: 50732
s=p=q=0
for i in range(int(input())):
 t,x,y=map(int,input().split())
 l=abs(x-p)+abs(y-q)
 if(l-t-s)%2or l>t-s:print("No");break
 s,p,q=t,x,y
else:print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=410;
const ll INF=1e18;
ll dp[maxn][maxn];
vector<ll>pre(maxn);
vector<ll>a(maxn);
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		pre[i]=pre[i-1]+a[i];
	}
	for(int L=n;L>0;--L)
	{
		for(int R=L;R<=n;++R)
		{
			if(L==R)dp[L][R]=0;
			else
			{
				dp[L][R]=INF;
				for(int i=L;i<R;++i)
					dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+pre[R]-pre[L-1]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 1536
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] && s[1]==s[2]){
        cout << "Yes" << endl;
        
    }
    else if(s[1]==s[2] && s[2]==s[3]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  for (int i = 0; i < N ; i++) {
    int x;
    cin >> x;
    if (x <= K - x) {
      ans += x * 2;
    }
    
    if (x > K - x) {
      ans += (K - x) * 2;
    }
  }
  
  cout << ans << endl;
}


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

constexpr ll INF = ll(1e+18) + 1;

int main() {
    int N;
    vector<ll> A;
    ll ans=1, LIM=1e+18, buf;

    cin>>N;
    rep(i, N) {
        cin >> buf;
        if (buf==0) {cout<<0<<endl;return 0;}
        A.push_back(buf);
    }
    rep(i, N) {
        if (LIM/ans < A[i]) {cout << -1 << endl; return 0;}
        ans *= A[i];
    }
    cout << ans << endl;
}


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

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

    int n, y;
    cin >> n >> y;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            int k = n - (i + j);
            int total = i*10000 + j*5000 + k*1000;
            if(k >= 0 && total == y){
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int A, B;
	cin >> A >> B;
	if (A == 1&&B!=1)
	{
		cout << "Alice" << endl;
	}

	else if (B == 1&&A!=1)
	{
		cout << "Bob" << endl;
	}
	else if (A > B)
	{
		cout << "Alice" << endl;
	}
	else if (B > A)
	{
		cout << "Bob" << endl;
	}
	else if (A == B)
	{
		cout << "Draw " << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append(A[i] - i + 1)

B = sorted(B)
mid = B[N // 2]
num = 0
for i in range(N):
    num += abs(B[i] - mid)

print(num)

Measured memory_bytes: 25200
#include <iostream>
#define rep(n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int N,K,result = 1;
  cin >> N >> K;
  
  rep(N){
    if(result * 2 > result + K){
      result += K;
    }
    else{
      result *= 2;
    }
  }
  cout << result << endl;
}




Measured memory_bytes: 256
# 15
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
m = I()
t = LI()
d.sort()
t.sort()
c_t = Counter(t)
c_d = Counter(d)
# print(c_t.items())
# print(c_d.items())
ans = 'YES'
i = 0
c_d = dict([(k, v) for k, v in c_d.items() if k in c_t.keys()])
if len(c_d) != len(c_t):
    ans = 'NO'
    print(ans)
    exit()
for (k_t, v_t), (k_d, v_d) in zip(c_t.items(), c_d.items()):
    if v_t > v_d:
        ans = 'NO'
        break
print(ans)


Measured memory_bytes: 80980
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int m = n * (n - 1) / 2 - k;
  if(m < n-1) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<int, int>> ans;
  for(int i=2;i<=n;i++) {
    ans.emplace_back(make_pair(1, i));
  }
  for(int i=2;i<=n;i++) {
    for(int j=i+1;j<=n;j++) {
      if(ans.size() == m) break;
      ans.emplace_back(make_pair(i, j));
    }
    if(ans.size() == m) break;
  }
  cout << m << endl;
  for(auto& edge : ans) cout << edge.first << " " << edge.second << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
int N,C;
vector< int > sassi;


int solve2(int DP[],int i){
	if(i <= 0){
		return 0;
	}
	else{
		int primo = solve2(DP,i-1);
		int secondo = solve2(DP,i-2);
		
		if(DP[i] == -1){
			if(primo + abs(sassi[i] - sassi[i-1]) < secondo + abs(sassi[i] - sassi[i-2]) ){
				DP[i] = primo + abs(sassi[i] - sassi[i-1]);
			}
			else{
				DP[i] =secondo + abs(sassi[i] - sassi[i-2]);
			}
		}
		
		
		return DP[i];
	}
}


int solve(){
	int DP[N];
	
	DP[0] = 0;
	DP[1] = abs(sassi[1] - sassi[0]) ;
	
	for(int i=2; i < N; i++){
		DP[i] = min( DP[i-1] + abs(sassi[i] - sassi[i-1]) , DP[i-2] + abs(sassi[i] - sassi[i-2]) );
	}
	
	return DP[N-1];
}


int main(int argc, char** argv) {
	cin >> N;
	
	for(int i=0;i< N;i++){
		int p;
		cin >> p;
		sassi.push_back(p);
	}
	
	cout << solve();	
	return 0;
}

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

int main(){
    int d, x, p, y;
    string a;
    
    cin >> d;
    vector<int> dp(d+1, 0);
    
    cin >> x;
    for(int i = 0; i < x; i++){
        cin >> a >> p;
        if(a != "D")    continue;
        for(int j = d-1; j >= 0; j--)   dp[j+1] = max(dp[j+1], dp[j]+p);
    }
    
    cin >> y;
    for(int i = 0; i < y; i++){
        cin >> a >> p;
        if(a != "DD")   continue;
        for(int j = d-2; j >= 0; j--)   dp[j+2] = max(dp[j+2], dp[j]+p);
    }

    cout << dp[d] << endl;

    // int d, x, y;
    // cin >> d >> x;

    // vector<int> v;
    // char a;
    // int p;
    // for(int i = 0; i < x; i++){
    //     cin >> a >> p;
    //     if(a == 'D')    v.push_back(p);
    //     else            v.push_back(0);
    // }

    // cin >> y;
    // string bc;
    // int q;
    // for(int i = 0; i < y; i++){
    //     cin >> bc >> q;
    //     if(bc == "DD")  v.push_back(q);
    //     else            v.push_back(0);
    // }

    // int ans = 0;
    // for(int s = 0; s < 1<<(x+2*y); s++){
    //     int popcnt = 0, score = 0;
    //     for(int j = 0; j < x; j++){
    //         if((s>>j)&1)    popcnt++, score += v[j];
    //     }
    //     for(int j = 0; j < y; j++){
    //         if((s>>(x+2*j))&1 && (s>>(x+2*j+1))&1)  popcnt += 2, score += v[x+j];
    //     }
    //     if(popcnt <= d) ans = max(ans, score);
    // }

    // cout << ans << endl;

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[2*n];
	int ans=0;
	for(int i=0;i<(2*n);i++)
	 cin >> a[i];
	sort(a,a+(2*n));
	for(int i=0;i<2*n;i+=2)
	 ans+=min(a[i],a[i+1]);
	 cout << ans;
	return 0;
}

Measured memory_bytes: 256
#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=5;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	int d; cin>>d;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(v[j]-v[i]>d){cout << ":(" << endl; return 0;}
		}
	}
	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 300000+5
#define MOD 99824353
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &x){
    x=0; 
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
ll n;
ll a[DMAX];
ll ans=0;
int main(){
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}
	ll t=(n-2)/2;
	sort(a+1,a+n+1,greater<ll>());
	for(int i=2;i<=t+1;i++){
		ans+=a[i]*2;
	}
	if(n%2==1){
		ans+=a[2+t];
	}
	ans+=a[1];
	cout<<ans<<endl;
	return 0;
}


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

#define f first
#define s second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define px pair<db, db>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define input(a) for (auto& el : a) cin >> el;
#define output(a) cout << '!'; for (auto& el : a) cout << el << ' '; cout << '\n'; cout.flush();
#define sz(el) int(el.size())
#define sq(a) ((a) * (a))
#define xll bitset<128>
#define xmin(a,b) a = min(a, b)
#define xmax(a,b) a = max(a, b)
#define sun(a) sort(all(a)); a.resize(unique(all(a)) - a.begin());
/**/  /// extra
//#define forn(i,n) for (int i = 0; i < n; ++i)
//#define rforn(i,n) for (int i = n - 1; i >= 0; --i)
#define bn '\n'
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
//#define G vector<vector<pii>>
#define GVE vector<vector<edge>>
#define usi unordered_set<int>
#define usp set<pii>
/**/

using namespace std;

const int INF = 1'000'000'017;
const ll LLINF = 1'000'000'000'000'000'017LL;
const ld inf = 1.0 / 0.0;
const ld eps = 1e-9;
const int MOD = 998244353;

//mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

//uniform_int_distribution<int> uid(l, r); [l, r]
//int x = uid(rng);

string a4[4] = {"abcc", "abdd", "eefg", "hhfg"};
string a5[5] = {"aabbc", "dee.c", "d.fgg", "hif..", "hi.jj"};
string a7[7] = {"aabbcc.", "de....f", "de....f", "gh....i", "gh....i", "..jjkkl", "..mmnnl"};

const int N = 1003;

string res[N];

int draw4(int x) {
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            res[x + i][x + j] = a4[i][j];
        }
    }
    return x + 4;
}

int draw5(int x) {
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            res[x + i][x + j] = a5[i][j];
        }
    }
    return x + 5;
}

int draw7(int x) {
    for (int i = 0; i < 7; ++i) {
        for (int j = 0; j < 7; ++j) {
            res[x + i][x + j] = a7[i][j];
        }
    }
    return x + 7;
}

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

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        res[i] = string(n, '.');
    }

    if (n == 2) {
        cout << -1;
        return 0;
    }
    if (n == 3) {
        cout << "a..\na..\n.aa";
        return 0;
    }
    if (n == 6) {
        cout << "a.....\na.....\n.aa...\n...a..\n...a..\n....aa";
        return 0;
    }

    int m = n;
    int x = 0;
    if (n % 4 == 1) {
        x = draw5(x);
        n -= 5;
    } else if (n % 4 == 2) {
        x = draw5(x);
        x = draw5(x);
        n -= 10;
    } else if (n % 4 == 3) {
        x = draw7(x);
        n -= 7;
    }
    while (n) {
        x = draw4(x);
        n -= 4;
    }

    for (int i = 0; i < m; ++i) {
        cout << res[i] << '\n';
    }
    return 0;
}


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

namespace _1129
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                List<int> cards = new List<int>();
                for (int i = x[0]; i > 0; i--) cards.Add(i);
                for (int i = 0; i < x[1]; i++)
                {
                    int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    int[] now = new int[a[1]];
                    for (int j = 0; j < a[1]; j++)
                    {
                        now[j] = cards[a[0] - 1];
                        cards.RemoveAt(a[0] - 1);
                    }
                    List<int> after = new List<int>();
                    foreach (var item in now) after.Add(item);
                    foreach (var item in cards) after.Add(item);
                    cards = after;
                }
                Console.WriteLine(cards[0]);
            }
        }
    }
}


Measured memory_bytes: 9868
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Weighted Union-Find Forest.
class WeightedUnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;
  std::vector<int> weight_;

 public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1, weight_[i]=0.
  WeightedUnionFindForest(int n);
  // Get the number of the root of the node q.
  int Root(int q);
  // Return true if the roots of x and y is same.
  bool IsSame(int x, int y);
  // Unite the tree x and tree y(weight is w).
  // If x and y already have been united, return false.
  // Weight(y)-Weight(x)=w
  bool Unite(int x, int y, int w);
  // Get the number of nodes which are the same group as node q.
  int Size(int q);
  // Get the weight of node q.
  int Weight(int q);
  // Get the weights' difference of node x and y(Weight(y)-Weight(x)).
  int Diff(int x, int y);
};

WeightedUnionFindForest::WeightedUnionFindForest(int n) {
  for (int i = 0; i < n; i++) {
    parent_.push_back(i);
    rank_.push_back(0);
    size_.push_back(1);
    weight_.push_back(0);
  }
}
int WeightedUnionFindForest::Size(int q) {
  return size_[Root(q)];
}
int WeightedUnionFindForest::Root(int q) {
  if (parent_[q] == q) {
    return q;
  } else {
    int r = Root(parent_[q]);
    weight_[q] += weight_[parent_[q]];
    return parent_[q] = r;
  }
}

bool WeightedUnionFindForest::IsSame(int x, int y) {
  return Root(x) == Root(y);
}

int WeightedUnionFindForest::Weight(int q) {
  Root(q);  // compress path
  return weight_[q];
}
int WeightedUnionFindForest::Diff(int x, int y) {
  if (Root(x) != Root(y)) {
    cerr << "WeightedUnionFindForest: Error" << endl;
    cerr << "Roots of node x and y aren't same" << endl;
    return INT32_MAX;
  }
  return Weight(y) - Weight(x);
}

bool WeightedUnionFindForest::Unite(int x, int y, int w) {
  w += Weight(x);
  w -= Weight(y);
  x = Root(x);
  y = Root(y);

  if (x == y) return false;
  if (rank_[x] < rank_[y]) {
    weight_[x] = w * (-1);
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    weight_[y] = w;
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
  return true;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  WeightedUnionFindForest WUFF(n + 1);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    if (WUFF.IsSame(l, r)) {
      if (WUFF.Diff(l, r) == d) {
        // no conflict
      } else {
        // conflict
        cout << "No" << endl;
        exit(0);
      }
    } else {
      WUFF.Unite(l, r, d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2528
X,N=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
nai=[]

for i in range(0,102):
  if i not in p:
    nai.append(i)
nai.append(X)
nai.sort()
ind=nai.index(X)
if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
  print(nai[ind-1])
else:
  print(nai[ind+1])



Measured memory_bytes: 9104
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

string signature(const string& s) {
  string r;
  r.reserve(10);
  char prev = s[0];
  int x = 1;
  for (int i = 1; i < s.size(); i++) {
    char c = s[i];
    if (prev == c) {
      x++;
    } else {
      r += prev;
      r.append(to_string(x));
      x = 1;
    }
    prev = c;
  }
  r += prev;
  r.append(to_string(x));
  return r;
}

int main() {
  int N;
  cin >> N;
  unordered_map<string, int> m;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[signature(s)]++;
  }
  size_t ans = 0;
  for (auto p : m) {
    auto x = static_cast<size_t>(p.second);
    ans += x * (x - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12196
#include <bits/stdc++.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define ll long long
    #define endl '\n'
    int main()
    {
        IOS;
        ll n;
        cin>>n;
        vector<ll> v(n);
        for(ll i=0;i<n;i++)
            cin>>v[i];
        vector<pair<ll,ll> > count1(100001);
        vector<pair<ll,ll> > count2(100001);
        ll c2[100001];
        for(ll i=0;i<=100000;i++)
        {
            count1[i].first=0;
            count2[i].first=0;
            c2[i]=0;
        }
        for(ll i=0;i<100001;i++)
        {
            count1[i].second=i;
            count2[i].second=i;
        }
        for(ll i=0;i<n;i+=2)
        {
            count1[v[i]].first++;
        }
        for(ll i=1;i<n;i+=2)
        {
            count2[v[i]].first++;
            c2[v[i]]++;
        }
        vector<ll> tmp;
        sort(count2.begin(),count2.end());
        for(ll i=100000;i>=99999;i--)
        {
            if(count2[i].first)
                tmp.push_back(count2[i].second);
        }
        ll even=n/2;
        ll odd=n/2+(n%2!=0);
        if(tmp.size()==1)
        {
            ll ans=1e18;
            for(ll i=1;i<=100000;i++)
            {
                if(i==tmp[0])
                    continue;
                ans=min(ans,odd-count1[i].first);
            }
            cout<<ans;
            return 0;
        }
        trace2(tmp[0],tmp[1]);
        ll ans=1e18;
        ll m=tmp.size();
        for(ll i=1;i<=100000;i++)
        {
            if(count1[i].first==0)
                continue;
            if(i==tmp[0])
            {
                ans=min(ans,even-count1[i].first+odd-c2[tmp[1]]);
            }
            else
            {
                ans=min(ans,even-count1[i].first+odd-c2[tmp[0]]);
            }
        }
        cout<<ans;
    }


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='1'){
			cout << 9;
		} else {
			cout << 1;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
	int n, w;
	cin>>n>>w;
	int weight[n + 1];
	lli value[n + 1];
	for(int i = 1; i <= n; i++) cin>>weight[i]>>value[i];
	lli dp[n + 1][w + 1];
	for(int i = 0; i <= n; i++) fill(dp[i], dp[i] + w + 1, 0);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= w; j++)
			if(j < weight[i]) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]);
	cout<<dp[n][w];
	return 0;
}

Measured memory_bytes: 79104