akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int n;
ll arr[101];
int ans = 0;
vector<int> tmp;
void dfs(int idx, int cnt)
{
	if (cnt == 3)
	{

		if(arr[tmp[0]]!=arr[tmp[1]]&&arr[tmp[1]]!=arr[tmp[2]])
			if (arr[tmp[0]] + arr[tmp[1]] > arr[tmp[2]])
				ans++;
		
		
		return ;
	}
	for (int i = idx + 1; i < n; i++)
	{
		tmp.push_back(i);
		dfs(i, cnt + 1);
		tmp.pop_back();
	}
	return;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin>>arr[i];
	sort(arr, arr + n);

	dfs(-1, 0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
    int n,ave=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        ave+=a[i];
    }
    if(ave%n>n/2)
        ave=ave/n+1;
    else
        ave/=n;
    int x=0;
    for(int i=0;i<n;i++){
        x+=(a[i]-ave)*(a[i]-ave);
    }
    printf("%d\n",x);
    return 0;
}

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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
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();}

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

typedef long long ll;

const ll MOD = 1e9 + 7;

class BTwoColorsCardGame {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, M;
        unordered_map<string, int> cnt;
        in >> N;
        REP(i,0,N) {
            string s;
            in >> s;
            cnt[s]++;
        }
        in >> M;
        REP(i,0,M) {
            string s;
            in >> s;
            cnt[s]--;
        }
        int answer = 0;
        for (const auto& p : cnt) {
            if (p.second > answer) answer = p.second;
        }
        out << answer << "\n";
    }
};


signed main() {
    BTwoColorsCardGame 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>
#define ll long long
#define MAX 1e9+7
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
using namespace std;
int main()
{
    ll n;
    i(n);
    ll a[n],b[n],c=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(ll i=0;i<n;i++)
    {
        if(a[i] != b[i])
        {
            c++;
        }
    }
    if(c==0 || c==2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


Measured memory_bytes: 256
(* O(n) *)
let rec fold_btw f a i n = if i >= n then a else fold_btw f (f a i) (i + 1) n
let fold_int f a n = fold_btw f a 0 n

let is_acgt_char = function
| 'A' | 'C' | 'G' | 'T' -> true
| _ -> false

(* O(|s|) *)
let acgt_length s i =
  let n = String.length s in
  let rec count acc j =
    if j >= n || not (is_acgt_char s.[j]) then
      acc
    else
      count (acc + 1) (j + 1)
  in
    count 0 i

(* O(|s|^2) *)
let solve s = fold_int (fun acc i -> max acc (acgt_length s i)) 0 (String.length s)

let _ = read_line () |> solve |> string_of_int |> print_endline

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
    string n;
    cin >> n;
    int a_min;
   
    for(int i = 0;i<n.length()-2;i++){
        char c = n[i];
        int x = c - '0';
        c = n[i+1];
        int y = c - '0';
        c = n[i+2];
        int z = c - '0';
        int a = abs(753-x*100-y*10-z);
        if(i == 0)   a_min = a;
        if(a_min>a)  a_min = a;
    }
    cout << a_min << endl;
    
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int k,s,ans=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++)for(int j=0;j<=k;j++)if(0<=s-i-j&&s-i-j<=k)ans++;
  cout<<ans<<endl;
         
}

        


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;
    int ans = 10000000;
    for (int i = 0; i < S.length() - 2; i++)
    {
        int s = 0;
        s += (S[i] - '0') * 100;
        s += (S[i + 1] - '0') * 10;
        s += S[i + 2] - '0';
        ans = min(ans, abs(753 - s));
    }
    cout << ans << endl;
}

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

int main() {
    int N,M;cin >> N >> M;
    vector<vector<int>> V(M + 1);
    for (int i = 0;i < N;i++){
        int a,b;cin >> a >> b;
        if (a > M) continue;
        else {
            V[M - a].push_back(b);
        }
    }
    priority_queue<int> que;
    ll ans = 0;
    for (int i = M - 1;i >= 0;i--){
        for (int b : V[i]){
            que.push(b);
        }
        if (que.size()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
string s;
int main() {
  cin >> n >> k >> s;

  i64 scr = 0;
  for (i64 i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) scr++;
  }
  
  cout << min(n - 1, scr + 2 * k) << endl;
  return 0;
}

//2 2 5
// 2 5


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll double
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int,pair<int,int>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll dp[301][301][301];
ll solve(int one, int two, int three, int& n)
{
    if(one < 0 || two < 0 || three < 0)
        return 0;
    if(three == 0 && two == 0 && one == 0)
        return 0;

    if(dp[one][two][three] > 0)
        return dp[one][two][three];

    int remaining = one + two + three;
    ll exp_val = n+one*solve(one-1,two,three,n) + two*solve(one+1,two-1,three,n) +
                    three*solve(one,two+1,three-1,n);

    return dp[one][two][three] = exp_val/remaining;
}

int main(){
    int i,j,t,n,m,p,k;
    //fast_io;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n;
        int one=0,two=0,three=0;

        fr(0,n){
            int x;
            cin >> x;
            if(x == 1)one++;
            else if(x == 2)two++;
            else three++;
        }

        memset(dp, -1, sizeof dp);
        cout<<fixed<<setprecision(9)<<solve(one,two,three,n);
    }
    return 0;
}


Measured memory_bytes: 216872
#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 RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
                            #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
                            #define FILL(a, value) memset(a, value, sizeof(a)

                            #define SZ(a) (int)a.size()
                            #define ALL(a) a.begin(), a.end()
                            #define PB push_back
                            #define MP make_pair
                            #define er erase
                            #define in insert
                            #define f first
                            #define s second



                            typedef  long long LL;
                            typedef vector<int> VI;
                            typedef vector<LL > VL;
                            typedef vector<vector<int > > VVI;
                            typedef vector<vector<LL>> VVL;
                            typedef vector <vector<pair<int, int >> >VVPI;
                            typedef vector<vector<pair<LL, LL >> >VVPL;
                            typedef vector<pair<LL, LL >> PL;
                            typedef vector<PL> VPL;
                            typedef pair<int, int> PII;
                            typedef vector<PII> VPI;

                            const double PI = acos(-1.0);
                            const int INF = 1e9;
                            const LL LINF = (LL)1e18;

                            const double EPS = 1e-7;
                            const int MAS =  3 *1e5 + 10;
                            const int mod = 998244353;
                            const int MOD =1e9+7;
                            const int LOG= 19;
                            const int ar = 1e5 +100;
                            const int MAX = 1e6 + 1e2;
                         LL dp[ar * 3];
                         int a[ar][3];

                        int main() {
                            ios_base::sync_with_stdio(false);
                            cin.tie(NULL);
                            int n,wag;
                            cin >> n >> wag;
                            rep(i,n)
                            {
                                int w,v;
                                cin >> w >> v;
                                RFOR(alr,wag - w + 1 , 0)
                                {
                                    dp[alr + w] = max(dp[alr + w],dp[alr] + v);
                                }
                            }
                            cout << *max_element(dp,dp + wag +1);

                            }

















































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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ret = 0;
    ret += min(a, k), k -= min(a, k);
    k -= min(b, k);
    ret -= k;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int N, x;
    scanf("%d", &N);
    x=N%10;
    if(x==3){
        printf("bon\n");
    }
    else if(x==0 || x==1 || x==6 || x==8) printf("pon\n");
    else
        printf("hon\n");
    return 0;
}


Measured memory_bytes: 1620
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll X,t;
  cin>>X>>t;
  X-=t;
  if(X<0) X=0;
  cout<<X<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

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


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

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  
  int T=N*A;
  
  if(T>B){
    cout<<B<<endl;
  }
  else if(T==B){
    cout<<B<<endl;
  }
  else{
    cout<<T<<endl;
}
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

string solve(ll a, ll b) {
	if (a <= 0 && 0 <= b) {
		return "Zero";
	} else if (a > 0) {
		return "Positive";
	}

	return (llabs(a - b) + 1LL) & 1LL ? "Negative" : "Positive";
}

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

	ll a, b;
	cin >> a >> b;

	cout << solve(a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
// C#練習
// 解説参照
// なぜ必要十分なのかも、2つ目の条件だけでよいのかも分からない
// intだと足りない？
using System;
using System.Linq;
public class AA{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        long[] b = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        
        long bai = 0;
        for (int i = 0;i<n;i++){
            bai += Math.Max((b[i]-a[i]+1)/2, 0);
        }
        long abi = 0;
        for (int i = 0;i<n;i++){
            abi += Math.Max(a[i]-b[i], 0);
            }
        
        long mx = b.Sum()-a.Sum();

        if (mx>=bai & mx>=abi){
            Console.WriteLine("Yes");
        }
        else{
            Console.WriteLine("No");
        }
        
    }
}


Measured memory_bytes: 15456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << setprecision(10) << w * h /2 << ' ';
  if(w/2 == x && h/2 == y) cout <<1<< endl;
  else cout << 0 << endl;
  return 0;
}



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

typedef long long ll;

ll N;
multiset<pair<ll, ll>> XY;
multiset<ll> R, B;
ll Res = 1ll << 60;

int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    R.insert(x);
    B.insert(y);
    XY.insert(make_pair(x, y));
  }
  for (auto xy : XY) {
    ll x, y;
    tie(x, y) = xy;
    Res = min(Res, (*R.rbegin() - *R.begin()) * (*B.rbegin() - *B.begin()));
    R.erase(R.find(x));
    R.insert(y);
    B.erase(B.find(y));
    B.insert(x);
    assert(R.size() == N && B.size() == N);
  }
  cout << Res << endl;
  return 0;
}


Measured memory_bytes: 31616
N = int(input())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))
last = -1
num = 0
for A in Alist:
    num += Blist[A-1]
    if A == (last+1):
        num += Clist[last-1]
    last = A

print(num)

Measured memory_bytes: 3064
#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N;
    long long P, Q, total = 0;
    cin >> N;
    cin >> P;
    for (int i = 1; i < N; i++) {
        if (i == 1) {
            cin >> Q;
            if (P <= Q)
                continue;
            else {
                total += (P - Q);
                Q = P;
            }
        } else {
            P = Q;
            cin >> Q;
            if (P <= Q)
                continue;
            else {
                total += (P - Q);
                Q = P;
            }
        }
        }
        cout << total << endl;
        return 0;
    }


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;
static const int MAX = 2000000;

int main(){
	int R[MAX], n;

	cin >> n;
	for(int i = 0; i < n; i++) cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for(int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    VI b(m);
    REP(i,m) cin >> b[i];
    int ans = 0;
    REP(i,n){
        int s = c;
        REP(j,m){
            int a = in();
            s += a * b[j];
        }
        if (s > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
struct edge {ll to,cost;};
#define VMAX 200000+10
    ll d[VMAX];
    ll N,M,L[VMAX],R[VMAX],D[VMAX];
    ll ans=0;
    std::vector<edge> G[VMAX];
    bool dijkstra(int s){
        //頂点数N 辺の数 E
        std::priority_queue<P,vector<P>,std::greater<P>> que;
//一回もチェックしたことがないなら距離を0にする
        if(d[s]==INF) d[s]=0;
        que.push(P(d[s],s));
        while(!que.empty()){

            P p =que.top();que.pop();
            int v=p.second;
            for(int i=0;i<(signed)G[v].size();i++){
                edge e =G[v][i];
//まだ訪れていないなら
                    if(d[e.to]==INF)
{
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
//訪れていて与えられた情報と異なる場合
              else if(d[e.to]!=d[v]+e.cost){ 
                return false;
                }
              }
        }
        return true;
    }

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,M){
		cin>>L[i]>>R[i]>>D[i];

			G[L[i]].push_back({R[i],D[i]});
//線をx座標として考えると,右から左に向かうということはxを小さくするということ
G[R[i]].push_back({L[i],-D[i]});
	}
    bool f=true;
    std::fill(d,d+N + 1,INF);
    EREP(i,N){
        if(!dijkstra(i))f=false;
    }
    cout<<(f?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 21744
#include <iostream>

using namespace std;

int main()
{
    double a ,odd=0,even=0;
    cin>>a;
    if (a==1)
    {cout<<1;return 0;}
    for (int i = 1;i<=a;++i)
        if (i%2==0)
            even++;
        else
            odd++;
    cout<<odd/a;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <queue>
#include <cmath>
#include <unordered_map>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct Q {
	int n, c, o;
};

int pow10(int p) {
	return pow(10, p);
}

unordered_map<int, int> all() {
	static const int r[] = {1, 4, -1, -4};
	unordered_map<int, int> m;
	queue<Q> q;
	q.push({1234567, 0, 7});
	m[1234567] = 0;
	while (!q.empty()) {
		Q a = q.front();
		q.pop();
		for (auto x: r) {
			int p = x + a.o;
			if (p >= 0 && p < 8 && !(p == 4 && x == 1) && !(p == 3 && x == -1)) {
				int t = a.n + a.n / pow10(p) % 10 * (pow10(a.o) - pow10(p));
				if (!m.count(t)) {
					m[t] = a.c + 1;
					q.push({t , a.c + 1, p});
				}
			}
		}
	}
	return move(m);
}

int main() {
	unordered_map<int, int> m = all();
	for (;;) {
		int t = 0;
		for (int i = 0, a; i < 8; i++) {
			if (!scan(a))
				return 0;
			t *= 10;
			t += a;
		}
		outl(m[t]);
	}
}


Measured memory_bytes: 3256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,K=map(int,input().split())
A=list(map(int,input().split()))

for k in range(min(50,K)):
    B=[0]*N
    for i in range(N):
        l=max(0,i-A[i])
        r=min(N,i+A[i]+1)
        B[l]+=1
        if r<N:
            B[r]-=1
    for i in range(N-1):
        B[i+1]+=B[i]
    A=B[:]
print(*A)

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

int main() {
  int ans = 0;
  string predict;
  string real;
  cin >> predict >> real;
  for (int i = 0; i < 3; i++) {
    if (predict[i] == real[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  int h, w, d;
  scanf("%d %d %d", &h, &w, &d);
  if (d & 1) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if ((i + j) & 1) printf("R");
        else printf("G");
      }
      printf("\n");
    }
  } else {
    int before = d / 2;
    int beforeDelta = -1;
    char firstRB;
    char secondRB;
    char firstGY = 'G';
    char secondGY = 'Y';
    for (int i = 0; i < h; i++) {
      if (i % (2 * d) < d) {
        firstRB = 'R';
        secondRB = 'B';
      } else {
        firstRB = 'B';
        secondRB = 'R';
      }

      if (i % (2 * d) < d / 2 || i % (2 * d) > 3 * d / 2) {
        firstGY = 'G';
        secondGY = 'Y';
      } else {
        firstGY = 'Y';
        secondGY = 'G';
      }

      int numFirstRB = d - 2 * before;
      for (int j = 0, cur = 0; j < w; j++) {
        if (j < before) printf("%c", secondGY);
        else {
          if (cur < numFirstRB) printf("%c", firstRB);
          else printf("%c", firstGY);
          cur++;
          if ((j - before + 1) % d == 0) swap(firstGY, secondGY);
          if (cur == d) {
            cur = 0;
            swap(firstRB, secondRB);
          }
        }
      }

      printf("\n");
      before += beforeDelta;
      if (before < 0) {
        before = 1;
        beforeDelta = 1;
      } else if (before > d / 2) {
        before = d / 2 - 1;
        beforeDelta = -1;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>

using namespace std;

int main(){
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int ans = 0;
    for(int i = 0; i < n; i++){
        set<char> s;
        s.insert(a[i]);
        s.insert(b[i]);
        s.insert(c[i]);
        ans += s.size() - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
#include<iostream>  
#include<string>  
#include<vector>  
#include<stack>  
#include<bitset>  
#include<cstdlib>  
#include<cmath>  
#include<set>  
#include<list>  
#include<deque>  
#include<map>  
#include<queue>
using namespace std;
typedef long long ll;
const ll inf=1<<29;
const ll Maxn=1e6;

int main(){
	ll x,a,b,sum;
	cin>>x>>a>>b;
	sum=x-a;
	sum=sum%b;
	printf("%lld",sum);
}

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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &x : a)
		cin >> x;
	int cnt = 0;
	for (int i = 1; i < n - 1; ++i)
	{
		vector<int> temp;
		temp.pb(a[i - 1]);
		temp.pb(a[i]);
		temp.pb(a[i + 1]);
		sort(temp.begin(), temp.end());
		if (a[i] == temp[1])
			cnt++;
	}
	cout << cnt;
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e3+11;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        ll a;
        ld b;
        cin>>a>>b;
        
        ld ans=(ld)(a*b);
        cout<<(ll)ans<<endl;
}
int main(){
        FS;
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3752
/**
* @author Ashini Singha
* IIT,Jahangirnagar University
*/
#include<bits/stdc++.h>
using namespace std;
#define     ll          long long int
#define     fo(i,b,n)   for(int i=(b); i<(n) ; i++)
#define     xx          first
#define     yy          second
#define     pb          push_back
#define     sz(n)       int(n.size())
#define     pii         pair
#define     MP          make_pair
#define     PI          acos(-1.0)

#define read(x)         scanf("%d",&x)
#define read2(x,y)      scanf("%d%d",&x,&y)
#define readl(x)        scanf("%lld",&x)
#define readl2(x,y)     scanf("%lld%lld",&x,&y)
#define readd(x)        scanf("%lf",&x)
#define readd2(x,y)     scanf("%lf%lf",&x,&y)

#define pr(n)           printf("%d",n)
#define prn(n)          printf("%d\n",n)
#define prl(n)          printf("%lld",n)
#define prln(n)         printf("%lld\n",n)
#define prd(x)          printf("%lf",x)
#define prdn(x)         printf("%lf\n",x)
#define TC(n) printf("Case %d: ",n)
/*_____________E_N_D______________*/



int main()
{

      int n,m;
      read2(n,m);
      cout<<(n+m)%24<<endl;


      return 0;
}



















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

using ll = long long;

int main(){
  ll n,output=0;
  cin>>n;
  for(ll i=1;i<=n;i++){
    for(ll j=1;j<=n;j++){
      for(ll k=1;k<=n;k++){
        ll gcd = __gcd(i,__gcd(j,k));
        output+=gcd;
      }
    }
  }
  cout<<output;

}


Measured memory_bytes: 3632
S = input()
hS = int(len(S) / 2)
if len(S) == 1:
  s1 = '1'
  s2 = '0'
elif len(S) % 2 == 1:
  s1 = '10' * hS
  s1 = s1 + '1'
  s2 = '01' * hS
  s2 = s2 + '0'
else:
  s1 = '10' * hS
  s2 = '01' * hS
  
ns1, ns2 = 0, 0

for i, s in enumerate(S):
  if s != s1[i]:
    ns1 += 1

for i, s in enumerate(S):
  if s != s2[i]:
    ns2 += 1

print([ns1, ns2][ns2 < ns1])

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define mod 998244353 
int32_t main()
{
    int n,k;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    int dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,y;
  cin>>n;
  int i,a[n];
  for(i=0;i<n;i++)
     cin>>a[i];
  int ans[n];
  ans[0]=0;
  ans[1]=abs(a[1]-a[0]);
  for(i=2;i<n;i++)
  {
    x=ans[i-2]+abs(a[i-2]-a[i]);
    y=ans[i-1]+abs(a[i-1]-a[i]);
    ans[i]=min(x,y);
  }
  cout<<ans[n-1];
  return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct PrimeList
{
    PrimeList(ll n)
    {
        vector<bool> isPrime(n, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i <= n; ++i)
        {
            if (!isPrime[i])
                continue;
            mPrimeList.push_back(i);
            for (int j = i * 2; j <= n; j += i)
                isPrime[j] = false;
        }
    }

    //! i番目の素数を取得
    int get(int i)
    {
        return mPrimeList[i];
    }

    vector<int> mPrimeList;
};

ll A[505];
vector<ll> D;

void dfs(vector<pll> p, ll n = 1, int index = 0)
{
    if (p.size() == index)
    {
        D.push_back(n);
        return;
    }

    REP(i, p[index].second + 1)
    {
        dfs(p, n, index + 1);
        n *= p[index].first;
    }
}

int main()
{
    ll N, K;
    cin >> N >> K;
    ll sum = 0;
    REP(i, N)
    {
        cin >> A[i];
        sum += A[i];
    }

    vector<pll> p;
    PrimeList pl(100000);
    REP(i, pl.mPrimeList.size())
    {
        if (sum % pl.get(i) != 0)
            continue;
        ll n = 0;
        while (sum % pl.get(i) == 0)
        {
            sum /= pl.get(i);
            n++;
        }
        p.push_back(pll(pl.get(i), n));
    }
    if (sum > 1)
        p.push_back(pll(sum, 1));

    D.clear();
    dfs(p);

    sort(D.begin(), D.end(), [](ll a, ll b) { return a > b; });
    REP(i, D.size())
    {
        vector<ll> B;
        ll d = D[i];
        REP(j, N)
        {
            B.push_back(A[j] % d);
        }
        sort(B.begin(), B.end());
        int l = 0, r = N - 1;
        ll k = 0;
        while (l < r)
        {
            if (B[l] == 0)
            {
                l++;
                continue;
            }
            if (B[r] == 0)
            {
                r--;
                continue;
            }

            ll m = std::min(B[l], d - B[r]);
            k += m;
            B[l] -= m;
            B[r] = (B[r] + m) % d;
        }
        if (k <= K)
        {
            cout << d << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
# Bの足し算
ans += sum(b)

# Cの足し算
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        ans += c[a[i] - 1]

print(ans)


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    if (s[2] == s[3] and s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int rt[] = new int[n];
        int diff[] = new int[n];
        
        for (int i = 0; i < n; i++) {
            rt[i] = Integer.parseInt(sc.next());  
        }

        int minv = rt[0];
        int maxv = rt[1] - rt[0];
        for (int j = 1; j < n; j++) {
            maxv = Math.max(maxv, rt[j] - minv);
            minv = Math.min(minv, rt[j]);
        }

        System.out.println(maxv);
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}
const int INF=1001001001;
signed main(){
	int N;
	cin>>N;
	vint W(N);
	rep(i,N)cin>>W[i];

	int ans=INF;
	rep(i,N-1){
		int s1=accumulate(W.begin(),W.begin()+i+1,0ll);
		int s2=accumulate(W.begin()+i+1,W.end(),0ll);
		chmin(ans,abs(s1-s2));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int N;
cin >> N;
int V[N];
int C[N];
for(int i=0;i < N;i++){
    cin >> V[i];
}
for(int i=0;i < N;i++){
    cin >> C[i];
}
int sum=0;
for(int i=0;i<N;i++){
if(V[i] > C[i]){
    sum += V[i] - C[i];
      }     
    }
    cout << sum << endl;
}


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

int main(void)
{
	char str[101];
	int i, k, j,len;
	scanf("%s", str);
	len = strlen(str);
	for (i = 0; i < len; i++)
	{
		k = 0;
		for (j = 0; j < len; j++)
		{
			if (i == j) continue;
			else if (str[i] == str[j])
			{
				k++;
			}
		}
		k = k % 2;
		if (k == 0)
		{
			printf("No\n");
			break;
		}
		if (k == 0) break;
	}
	if (k == 0) return 0;
	else
	{
		printf("Yes\n");
		return 0;
	}
}

Measured memory_bytes: 128
long M=1e9+7,m[1<<18],h,w,a,s;p(a,b)long a;{return b?p(a*a%M,b/2)*(b%2?a:1)%M:1;}main(i){for(*m=1;i<1<<18;)m[i]=m[i-1]*i++%M;for(scanf("%d%d%d%d",&h,&w,&a,&i);i<w;)s=(s+m[h-a-1+i]*m[a+w-i-2]%M*p(m[h-a-1]*m[i]%M*m[a-1]%M*m[w-++i]%M,M-2)%M)%M;printf("%d",s);}

Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
typedef long long ll;
ll F (ll A, ll B) {
    string SA = to_string(A);
    string SB = to_string(B);
    return max(SA.length(), SB.length());
}
int main (void) {
    ll N;

    cin >> N;

    ll ans = LLONG_MAX;
    for (ll A = 1; A <= sqrt(N); A++) {
        if (N % A == 0) {
            ll B = N / A;
            ans = min(ans, F(A, B));
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		
		int ans;
		
		if(n<100) {
			ans = n * (int)Math.pow(100, d);
		}else {
			ans = (n+1) * (int)Math.pow(100,d);
		}
		
		System.out.println(ans);

		sc.close();
	}

}

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

int main() {
  int a = 0, b = 0, c = 0;
  cin >> a >> b >> c;
  
  if(a == b && a != c) {
    cout << "Yes" << endl;
  }
  
  else if(a == c && a != b) {
    cout << "Yes" << endl;
  }
  
  else if(b == c && b != a) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

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

int main() {
    int N, cnt = 1, tmp; cin >> N >> tmp;
    int state = 0;
    for (int i = 1; i < N; i++) {
        int x; cin >> x;
        if (state == -1) {
            if (tmp < x) {
                state = 0;
                cnt++;
            }
        } else if (state == 1) {
            if (tmp > x) {
                state = 0;
                cnt++;
            }
        } else {
            if (tmp < x) state = 1;
            else if (tmp > x) state = -1;
        }
        tmp = x;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	string S;
	cin >> N >> S;
	int r = 0, g = 0, b = 0;
	for (auto i : S) {
		if (i == 'R')r++;
		else if (i == 'G')g++;
		else b++;
	}
	int num = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (S[i] == S[j])continue;
			int k = j - i + j;
			if (k >= N || S[k] == S[i] || S[k] == S[j])continue;
			num++;
		}
	}
	int ans = r * g * b;
	ans -= num;
	cout << ans;
}

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

#include<string.h>
 
#define T int t, q; scanf("%d", &t); for(q=1; q<=t; q++)
 typedef long long int ll;

 int main(){
 	ll n,m,l,k;
 	cin >> n >> m >>l >>k;
 	if(n==l)
 		cout <<"0" <<endl;
 	else
 		cout << "1" << endl;
 }

Measured memory_bytes: 256
#include<stdio.h>
int main (){
	int dia,a,sum=0;
    scanf("%d %d",&dia,&a);
    for (int i=1; i<=a; i++){
    	int x;
        scanf("%d",&x);
        sum=sum+x;
    }
    int ans=dia-sum;
    if (ans<0)
       	printf("-1\n");
    else
    	printf("%d\n",ans);
	return 0;
 }

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
      
      
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  for(int i=0;i<105;i++){
    c-=b;
    if(c<=0){cout << "Yes" << endl;
    return 0;}
    a-=d;
    if(a<=0){cout << "No" << endl;
    return 0;}
  }
}

Measured memory_bytes: 3596
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(S, Q, Qs):
    rev_flg = False
    bef = ''
    aft = ''
    for q in Qs:
        if q[0] == 1:
            rev_flg = not rev_flg
            bef, aft = aft, bef
        else:
            bf = q[1]
            if bf == 1:
                bef += q[2]
            elif bf == 2:
                aft += q[2]
    bef = bef[::-1]
    if rev_flg:
        S = S[::-1]
    print(bef + S + aft)


    # for q in Qs:
    #     if q[0] == 1:
    #         rev_flg = not rev_flg
    #     else:
    #         bf = q[1]
    #         if (bf == 1 and not rev_flg) or (bf == 2 and rev_flg):
    #             ans = q[2] + ans
    #         else:
    #             ans = ans + q[2]
    # if rev_flg:
    #     ans = ans[::-1]
    # print(ans)


if __name__ == '__main__':
    # # handmade
    # S = 'h' * 10 ** 5
    # Q = 2 * 10 ** 5
    # Qs = []
    # for i in range(Q - 1):
    #     if i % 2 == 0:
    #         Qs.append([2, 1, 'a'])
    #     else:
    #         Qs.append([2, 2, 'b'])
    # Qs.append([1])

    # input
    S = input()
    Q = int(input())
    Qs = []
    i = 0
    for _ in range(Q):
        s = input()
        i += 1
        if s[0] == '1':
            q = [1]
        else:
            q = s.split()
            q[0] = int(q[0])
            q[1] = int(q[1])

        Qs.append(q)
    solve(S, Q, Qs)


Measured memory_bytes: 40472
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
#define Fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define f(i, n) for (long long int i = 0; i < n; i++)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9 + 7;
const ll modc = 998244353;
#define MAX 100002

ll maxi(ll a,ll b){
	if(a>=b)return a;
	return b;
}

int main(){
	Fio;
	ll n;
	cin>>n;
	vl A(n);
	f(i,n)cin>>A[i];
	ll dp[n+1][n+1] = {0};
	//dp[i][j] = x-y we can obtain in a[i:j]
	for(ll i = n-1;i>=0;i--){
		for(int j = i;j<n;j++){
			if(i==j)dp[i][j] = A[j];
			else dp[i][j] = maxi(A[i]-dp[i+1][j],A[j]-dp[i][j-1]);
		}	
	}
	cout<<dp[0][n-1];
	return 0;
}

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

signed main() {
	int n, p; cin >> n >> p;
	int o = 0, e = 0;
	rep(i, n) {
		int a; cin >> a;
		if (a & 1)o++; else e++;
	}
	if (!o) {
		if(p)cout << 0 << endl;
		else cout << (1ll << e) << endl;
	}
	else cout << (1ll << (e + o - 1)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	long long a,b;
	double bin;
	cin >> a >> bin;
	b = (long long)((bin+0.001) * 100.0);
	
	
	cout << (a*b)/100 << endl;
	
	
	return 0;
}

Measured memory_bytes: 3716
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	string s, t;
	cin >> s >> t;
	string ans = t+s;
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

bool check(vi &poly, int x){
  ll yo = 1;
  ll tes = 0;
  for(int y : poly){
    tes += yo * y;
    yo *= x;
  }
  return tes==0;
}

int main(){
  vi poly(6,0);
  string s;
  cin>>s;
  // parse
  {
    int kei = 0;
    int mode = 0;
    bool neg = false;
    REP(i,s.size()){
      char c = s[i];
      if(c=='x'){
        if(kei==0)kei=1;
        if(i+2<s.size() && s[i+1]=='^'){
          char d = s[i+2]-'0';
          poly[d] = kei * (neg?-1:1);
          i += 2;
        }else{
          poly[1] = kei * (neg?-1:1);
        }
        kei = 0;
        neg = false;
      }else if(isdigit(c)){
        kei *= 10;
        kei += c-'0';
        if(i==s.size()-1){
          poly[0] = kei * (neg?-1:1);
        }
      }else if(c=='-'){
        neg = true;
      }
    }
  }
  vi ans;
  FOR(re,1,2001){
    if(check(poly,-re)){
      ans.push_back(re);
    }
    if(check(poly,re)){
      ans.push_back(-re);
    }
  }
  sort(ALL(ans));
  for(int x : ans){
    printf("(x%c%d)",x<0?'-':'+',abs(x));
  }
  puts("");
  return 0;
}

Measured memory_bytes: 3316
n, m = map(int, input().split())
mask = [0] * m
for i in range(m):
	l = list(map(int, input().split()))
	for x in l[1:]:
		mask[i] += 2 ** (x - 1)
p = list(map(int, input().split()))
ans = 0
cnt = [0] * (2 ** n)
for sta in range(2 ** n):
	now = sta
	while now > 0:
		cnt[sta] += now & 1
		now //= 2
	valid = True
	for i in range(m):
		if cnt[mask[i] & sta] & 1 != p[i]:
			valid = False
			break
	if valid:
		ans += 1
print(ans)

Measured memory_bytes: 3064
def f(i):
    global m
    if i == n:
        c = 1
        for j in s:
            if j == 0:
                c *= 2
            else:
                c += k
        if m > c:
            m = c
        return
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

n = int(input())
k = int(input())
s = [0] * n
m = 114514
f(0)
print(m)

Measured memory_bytes: 3064