akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

vvi to;
vi dp;

int rec(int v) {
    if (dp[v] >= 0) return dp[v];
    int res = 0;
    for (int nv : to[v]) {
        chmax(res, rec(nv) + 1);
    }
    return dp[v] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    to.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].pb(b);
    }
    int ans = 0;
    dp.resize(n, -1);
    rep(v, n) {
        chmax(ans, rec(v));
    }
    cout << ans << endl;
}

Measured memory_bytes: 8192
import sys
(n, k) = map(int, input().split())

a1 = k // 10000
k %= 10000
a2 = k // 5000
k %= 5000
a3 = k // 1000
for i in range(a1 + 1):
    for j in range(a2 + i * 2 + 1):
        if (a1 - i) +(a2 + i * 2 - j) + (a3 + j * 5) == n:
            print(str(a1 - i) + ' ' + str(a2 + i * 2 - j) + ' ' + str(a3 + j * 5))
            sys.exit(0)
print('-1 -1 -1')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;
int A[200003];

bool is_large(int X) {
  int cnt=0;
  rep(i, N) {
    cnt+=(A[i]+X-1)/X-1;
  }
  return cnt > K;
}

int binary_search(int l, int r) {
  while(r-l>1) {
    int mid = (r+l)/2;
    if (is_large(mid)) l = mid;
    else r = mid;
  }
  return r;
}

int main() {
  INCANT;
  cin >> N >> K;
  rep(i, N) cin >>A[i];
  cout << binary_search(0, 1e9) << endl;

  return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
int dp[100001][3], arr[100001][3], N, maxe=INT_MIN;
void solve(){
	int lasteve=-1,lindex=-1;
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	maxe=max(dp[0][0],max(dp[0][1],dp[0][2]));
	for(int i=1;i<N;i++)
	{
		for(int j=0;j<3;j++)
		{
				//if(i==1)
				//{
				    for(int k=0;k<3;k++)
                    {
                        if(k==j)continue;
                        else
                        {
                            dp[i][j] = max(dp[i-1][k]+arr[i][j],dp[i][j]);
                            if(dp[i][j] > maxe){maxe = dp[i][j]; lasteve=j;}
                        }
                    }
				/*}
				else
				{
					if(j!=lasteve)
					{
						dp[i][j] = max(dp[i-1][lasteve]+arr[i][j],dp[i][j]);
						//cout << dp[i][j] << "  ";
						if(dp[i][j] > maxe){maxe = dp[i][j]; lindex=j;}
					}
				}*/
		}
		//if(i!=1)lasteve = lindex;
		//cout << lasteve << " " << maxe << endl;
	}
}
void printarr() {
	for(int i=0;i<N;i++)
		for(int j=0;j<3;j++)
			cout << arr[i][j] << " ";
	cout << endl;
}
void printdparr()
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<3;j++)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
}
int main() {
	// your code goes here
	memset(dp,-1,sizeof(dp));
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			cin >> arr[i][j];
		}
	}
	//printarr();
	solve();
	//printdparr();
	cout << maxe << endl;
	return 0;
}
/*
3
10 15 20
5 10 20
10 7 6

7
6 7 8
8 8 3
5 2 2
7 8 6
4 6 8
2 3 4
7 5 1
*/


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble
    ld a,b,h,m;
    cin>>a>>b>>h>>m;
    ld x=m/60.0;
    x=(x+h)*5.0;//see(x);
    ld y=m;see(y);
    x=min(x-y,60.0-(x-y));//see(x);
    ld ang=x*6.0;
  //  see(ang);
    ang*=pi/180.0;
    ld as=a*a+b*b-2*a*b*cos(ang);//see(as);
    as=1.0*(sqrt(as));
    cout<<preci(10)<<as<<nl;
    return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll res = -1e18;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    res = max(a * c, b * d);
    res = max3(res, a * d, b * c);
    cout << res << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int s[N], t[N], d[N], x[N];
vector<int> ans[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, q;   cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> s[i] >> t[i] >> x[i];
        s[i] -= x[i];  t[i] -= x[i];
    }   
    for(int i = 1; i <= q; i++)
        cin >> d[i];
    for(int i = 1; i <= n; i++){
        int p = lower_bound(d + 1, d + q + 1, s[i]) - d;
        ans[p].push_back(x[i]);
        p = lower_bound(d + 1, d + q + 1, t[i]) - d;
        ans[p].push_back(-x[i]);
    }
    multiset<int> m;
    for(int i = 1; i <= q; i++){
        for(auto j: ans[i]){
            if(j > 0)
                m.insert(j);
            else
                m.erase(m.lower_bound(-j));
        }
        if(m.empty()) 
            cout << -1 << endl;
        else
            cout << *m.begin() << endl;
    }
    return 0;
}

Measured memory_bytes: 29416
/*
 * 0652_Social_Game.c
 *
 *  Created on: 2019/05/12
 *      Author: nagashima
 */

#include <stdio.h>

int main()
{
  int A,B,C;
  int total=0;
  int res=0;

  scanf("%d %d %d",&A,&B,&C);

  for(;total<C;){
	  res++;
	  if(res%7==0)total+=B;
	  total+=A;
  }

  printf("%d\n",res);

  return 0;
}




Measured memory_bytes: 2100
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll a, b;
  cin >> a >> b;
  ll c = a * b;
  cout << (c % 2 == 0 ? "Even" : "Odd") << endl;
  return 0;
}


Measured memory_bytes: 256
S=input()
T=input()
a=len(S)
b=len(T)
maxa=1000000
for i in range(a-b+1):
  A=S[i:i+b]
  ans=0
  for j in range(b):
    if A[j]!=T[j]:
      ans+=1
  maxa=min(maxa,ans)
print(maxa)

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

int main(){
    int n,k,x,y,ans;
    cin >> n >> k >> x >> y;
    if (n < k){
        cout << (x * n);
    }
    else{
        cout << (x * k) + (y * (n - k));
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

const int N=300005;

int w,h,m;

set<pii> c[N];
set<pii> r[N];

multiset<int> mx;

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    cin>>w>>h>>m;
    
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        c[x].insert(mp(x,y));
        r[y].insert(mp(x,y));
    }
    
    for(int i=0;i<N;i++)
        if(r[i].size())
            mx.insert(-(int)r[i].size());
    
    int res=0;
    for(int i=0;i<N;i++)
        if(c[i].size())
        {
            int cur=0;
            for(pii p : c[i])
            {
                cur=max(cur,(int)r[p.s].size()-1);
                mx.erase(mx.lower_bound(-(int)r[p.s].size()));
            }
            if(mx.size())
                cur=max(cur,-*mx.begin());
            for(pii p : c[i])
                mx.insert(-(int)r[p.s].size());
            res=max(res,(int)c[i].size()+cur);
        }
    
    cout<<res<<endl;
    
  

}


Measured memory_bytes: 59404
#include<stdio.h>
#include<stdlib.h>


int main()
{

    int a,b,nd=0,x,y,z=1,i,X,sum=0;

    scanf("%d",&a);

    int A[a];

    for(i=0;i<a;i++){

        scanf("%d",&A[i]);

    }




    for(i=0;i<a;i++,z++)
    {

       if(A[i]!=z) sum++;


    }


    if(sum<=2)printf("YES\n");

    else printf("NO\n");


    return 0;

}



Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 10;
const int INF = 2e9;

int dp[MAXN], seg[4 * MAXN], x[MAXN];

void _set(int v, int l, int r, int p, int x) {
    if (r - l == 1) {
	seg[v] = x;
	return;
    }
    int mid = (r + l) / 2;
    if (p < mid) 
	_set(2 * v, l, mid, p, x);
    else
	_set(2 * v + 1, mid, r, p, x);
    seg[v] = min(seg[2 * v], seg[2 * v + 1]);
}

int query(int v, int l, int r, int s, int t) {
    if (s <= l && r <= t)
	return seg[v];
    int mid = (l + r) / 2, res = INF;
    if (s < mid)
	res = min(res, query(2 * v, l, mid, s, t));
    if (t > mid)
	res = min(res, query(2 * v + 1, mid, r, s, t));
    return res;
}

int lower(int val, int s, int t) {
    if (t - s == 1)
	return s;
    int mid = (s + t) / 2;
    if (x[mid-1] >= val)
	return lower(val, s, mid);
    else
	return lower(val, mid, t);
}

main() {
    int N, T, E;
    cin >> N >> E >> T;
    T *= 2;
    for (int i = 0; i < N; i ++) cin >> x[i], x[i] *= 2;
    for (int i = 0; i < N; i ++) {
	int last = lower(x[i] - T/2, 0, N);
	if (last <= 1) {
	    dp[i] = (last?2 * x[i] - 2 * x[0] : T);
	    if(last)dp[i] = min(dp[i], dp[last - 1] + T);
	    _set(1, 0, N, i, dp[i] - 2 * x[i+1]);
	    continue;
	}
	dp[i] = query(1, 0, N, 0, last-1) + 2 * x[i]; 
	dp[i] = min(dp[i], dp[last- 1] + T);
	dp[i] = min(dp[i], 2 * (x[i] - x[0]));
	_set(1, 0, N, i, dp[i] - 2 * x[i+1]);
    }
    cout << dp[N -1]/2 + E << endl;
}

Measured memory_bytes: 4992
/*
  AOJ 0578
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int N;
char name[25];
int namelen;
char buf[101];
int buflen;

int mycomp(char d[],char s[],int len,int skip)
{
        int i;

        for(i=1;i<len;i++)
                if(d[skip*i]!=s[i])
                        return(0);
        return(1);
}
int solve()
{
        int i,j;

        for(i=0;i<=buflen-namelen;i++)
                if(buf[i]==name[0])
                {
                        for(j=1;j<=(buflen-i)/(namelen-1);j++)
                                if(mycomp(&buf[i],name,namelen,j))
                                {
                                        //printf("ANS=%d\n",j);
                                        return(1);
                                }
                }
        return(0);
}
int main()
{
        int i,cnt;

        scanf("%d",&N);
        scanf("%s",&name[0]);
        namelen=strlen(name);
        for(i=0,cnt=0;i<N;i++)
        {
                scanf("%s",buf);
                buflen=strlen(buf);
                cnt+=solve();
        }
        printf("%d\n",cnt);
  return(0);
}

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<int>;
constexpr ll inf = 1ll<<61;
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

signed main(){
  int a,b,q; cin >> a >> b >> q;
  vi s(a+2), ms(a+2);
  rep(i,a){
    cin >> s[i];
    ms[i] = -s[i];
  }
  vi t(b+2), mt(b+2);
  rep(i,b){
    cin >> t[i];
    mt[i] = -t[i];
  }
  s[a] = t[b] = ms[a] = mt[b] = inf;
  s[a+1] = t[b+1] = ms[a+1] = mt[b+1] = -inf;
  sort(all(s));
  sort(all(t));
  sort(all(ms));
  sort(all(mt));

  rep(k,q){
    int x; cin >> x;
    
    int la = -*lower_bound(all(ms),-x);
    int lb = -*lower_bound(all(mt),-x);
    int ra = *lower_bound(all(s),x);
    int rb = *lower_bound(all(t),x);

    int res = inf;
    chmin(res, abs(x - la) + abs(-*lower_bound(all(mt),-la) - la));
    chmin(res, abs(x - la) + abs(*lower_bound(all(t),la) - la));

    chmin(res, abs(x - lb) + abs(-*lower_bound(all(ms),-lb) - lb));
    chmin(res, abs(x - lb) + abs(*lower_bound(all(s),lb) - lb));

    chmin(res, abs(x - ra) + abs(-*lower_bound(all(mt),-ra) - ra));
    chmin(res, abs(x - ra) + abs(*lower_bound(all(t),ra) - ra));
    
    chmin(res, abs(x - rb) + abs(-*lower_bound(all(ms),-rb) - rb));
    chmin(res, abs(x - rb) + abs(*lower_bound(all(s),rb) - rb));

    cout << res << endl;
  }
}

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
using namespace std;



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

    int a[4];
    for(int i = 0 ; i < 4; i++) a[i] = str.at(i) - '0';
    string op[2];
    op[0] = '-';
    op[1] = '+';

    for(int i = 0; i < 2; i++)
    {   int sum = a[0];
        if(i) sum += a[1];
        else sum -= a[1];
        for(int j = 0; j < 2; j++)
        {
            int sum1 = sum;
            if(j) sum1 += a[2];
            else sum1 -= a[2];
            for(int k = 0; k < 2; k++)
            {
                int sum2 = sum1;
                if(k) sum2 += a[3];
                else sum2 -= a[3];
                //cout << sum2 << endl;
                if(sum2 == 7)
                {
                    cout << a[0] << op[i] << a[1] << op[j] << a[2] << op[k] << a[3] << "=" << 7 << endl;
                    return 0;
                }
            }
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
//#define PI 3.1415926535
using namespace std;
void solve()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    int temp=s.length();
    if(temp>k)
    {
        for(int i=0;i<k;++i)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    else
    {
        cout << s << endl;
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    /*int t;
    cin >> t;
    while(t--)
    {
         solve();  
    }
   */ solve();
    return 0;
}





Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n,cnt[100005]{};
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        for(int j = -1;j<=1;j++){
            if(a+j<0)continue;
            cnt[a+j]++;
        }
    }
    int ans = 0;
    REP(i,100000){
        ans = max(ans,cnt[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//我是菜鸡
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto p:st)
#define debug(q,x) cout<<q<<x<<endl
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const int MOD = 1e9 + 7;
const double ext = 1e-6;
int a[maxn];
void deprint() {
	//ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
int main() {
	//ifstream cin("E:\\acm dream\\in.txt");5
	//ofstream cout("E:\\acm dream\\out.txt");
	//srand((unsigned)time(nullptr));
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	while (cin >> n) {
		_for(i, 0, n) cin >> a[i];
		sort(a, a + n);
		cout << a[n / 2] - a[n / 2 - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAXN=1e5+10;

int A[MAXN];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0, x;i<n;i++) {
		scanf("%d", &A[i]);
	}
	sort(A, A+n);

	int lbidx = lower_bound(A, A+n-1, A[n-1]/2)-A;
	int c1 = A[lbidx];

	if(lbidx>0) lbidx--;
	int c2 = A[lbidx];
	
	int diff1 = min(abs(c1-A[n-1]/2), abs(c1 - (A[n-1]+1)/2));
	int diff2 = min(abs(c2-A[n-1]/2), abs(c2 - (A[n-1]+1)/2));
	
	int ans1 = A[n-1];
	int ans2 = A[0];
	if(diff1<diff2) {
		ans2 = c1;
	}
	else {
		ans2 = c2;
	}
	printf("%d %d\n", ans1, ans2);
	return 0;
}



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

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

	int res = 0;
	int n;
	string s;
	int cntA = 0;
	int cntB = 0;
	int cntAB = 0;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> s;
		for(int j=0;j<s.length()-1;j++)
		{
			if(s.substr(j,2)=="AB")
			{
				res++;
			}
		}
		
		if(s[0]=='B' && s[s.length()-1]=='A')
		{
			cntAB++;
		}
		else if(s[0]=='B')
		{
			cntB++;
		}
		else if(s[s.length()-1]=='A')
		{
			cntA++;
		}		
	}

	//cout << res << ' ' << cntA << ' ' << cntB << '\n';
	if(cntAB > 0)
	{
		if(cntA > 0 && cntB > 0)
		{
			cntA--;
			cntB--;
			res += (cntAB +1);
		}
		else if(cntA > 0)
		{
			cntA--;
			res += (cntAB);
		}
		else if(cntB > 0)
		{
			cntB--;
			res += (cntAB);
		}
		else
		{
			res += (cntAB-1);
		}

	}
	res += min(cntA,cntB);
	
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 3620
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pow(2, i, M) + i*pow(2,i-1,M))*pow(2,n-i-1,M)
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Measured memory_bytes: 26024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
int n,m,c[50],val[50][50],x,a[120];
LL ans=1e18;
int main(){
	while(~scanf("%d%d%d",&n,&m,&x)){
		for(int i=1;i<=n;i++){
			cin>>c[i];
			for(int j=1;j<=m;j++)cin>>val[i][j];
		}
		ans=1e18;
		int mx=(1<<n)-1;
		for(int i=0;i<=mx;i++){
			memset(a,0,sizeof(a));
			LL tmp=0;
			for(int j=0;j<n;j++){
				if((1<<j)&i){
					tmp+=c[j+1];
					for(int k=1;k<=m;k++)
						a[k]+=val[j+1][k];
				}
			}
			for(int j=1;j<=m;j++)if(a[j]<x)tmp=1e18;
			ans=min(ans,tmp);
		}
		if(ans==1e18)puts("-1");
		else cout<<ans<<endl;		
	}

}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
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 << "Bob" << endl;
    else if (A == B) cout << "Draw" << endl;
    else cout << "Alice" << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void solve(){
	int n;
	rd(n);
	vector<pint>a;
	FOR(i,n){
		int u,v;
		rd(u,v);
		a.pb({u,v});
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i].ft==a[i].se)cnt++;
		else cnt=0;
		if(cnt==3){
			pp("Yes");
			return ;
		}
	}
	pp("No");
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=998244353;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}
signed main(){
    llin(n);
    llin(m);
    vector<pair<pair<ll,ll>,ll>> lrc(m);
    FOR(i,0,m-1){
        cin >>lrc[i].fi.fi>>lrc[i].fi.se>>lrc[i].se;
    }
    SORT(lrc);
    N = 1;
    while (N < n) N *= 2;
    value = vector<ll>(2 * N - 1, INF);
    ll u=0;
    update(0,0);
    FOR(i,0,m-1){
        u=query(lrc[i].fi.fi-1,lrc[i].fi.se,0,0,N);
        if(value[lrc[i].fi.se+N-2]>u+lrc[i].se){
            update(lrc[i].fi.se-1,u+lrc[i].se);
        }
    }
    sal((value[n+N-2]==INF?-1:value[n+N-2]))
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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;
    int k;
    cin >> s >> k;
    int n = s.size();
    set<string> st;
    rep(i,n){
        string t = "";
        rep(j,k){
            if(i+j >= n) break;
            t += s[i+j];
            st.insert(t);
        }
    }
    int p = 1;
    string ans;
    for(auto q : st){
        if(p++ == k){
            ans = q;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int coin1[501][501]={};//coin[H][W];(y,x)
int coin2[501][501]={};
int c=0;
void Rprint(int y,int x){

    cout <<y <<" "<<x<<" "<<y<<" "<<x+1<<endl;
}

void Uprint(int y,int x){

    cout <<y<<" "<<x<<" "<<y+1<<" "<<x<<endl;
}

void search2 (int y ,int x,int H, int W){
    //迷路の外側か壁なら何もしない
    if ( coin2[y][x]%2==0)return;
    
    else if(x==W &&y==H)return;

    else if(x==W){
        coin2[y+1][x]++;
        Uprint(y,x);
    }
    else{
        coin2[y][x+1]++;
        Rprint(y,x);
    }
}

void search1 (int y ,int x,int H, int W){
    if(x==W &&y==H){
        cout <<c<<endl;
    }
    
    //偶数なら何もしない
    else if ( coin1[y][x]%2==0)return;
    

    else if(x==W){
        coin1[y+1][x]++;
        c++;
    }
    else{
        coin1[y][x+1]++;
        c++;
    }
}


int main(){
int H,W;
cin >>H>>W;

for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        cin >>coin1[i][l];
        coin2[i][l]=coin1[i][l];
    }
}

//左下から初めて右上に追い込んでいく
for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        search1(i,l,H,W);
    }
}
for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        search2(i,l,H,W);
    }
}


 return 0;
}


Measured memory_bytes: 4096
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int a,b,c,d,e,f;

int main()
{
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  pii risan = mp(-1,INF);
  FORN(i,0,30) FORN(j,0,30) FORN(k,0,3000) FORN(l,0,3000)
  {
    int x = 100 * i * a + 100 * j * b;
    int y = k * c + l * d;
    if (x + y > f) {
      break;
    }
    if (y * 100 <= e * x && x + y <= f)
    {
      if ((LL)y * risan.se > (LL)(y + x) * risan.fi)
        risan = mp(y,y+x);
    }
  }
  printf("%d %d\n",risan.se,risan.fi);
  return 0;
}










Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,a[N],sz[N],cnt[N];
ll ans[N];
vector<int>e[N];
void add(int x,int y) {e[x].push_back(y);}

ll f(ll n) {return n*(n+1)/2;}

void dfs(int x,int F) {
	int c=a[x];
	ll tot=cnt[c],last;
	sz[x]=1;
	for(auto y:e[x]) if(y^F) {
		last=cnt[c];
		dfs(y,x);
		ans[c]+=f(sz[y]-(cnt[c]-last));
		sz[x]+=sz[y];
	}
	cnt[c]=tot+sz[x];
}

int main() {
	qr(n);
	for(int i=1;i<=n;i++) qr(a[i]);
	for(int i=1,x,y;i<n;i++) 
		qr(x),qr(y),add(x,y),add(y,x);
	dfs(1,0); ll t=f(n);
	for(int i=1;i<=n;i++) pr2(t-(ans[i]+f(n-cnt[i])));
	return 0;
}



Measured memory_bytes: 37180
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    string N; cin >> N;
    int A, B, C, D;
    A = N[0] - '0';
    B = N[1] - '0';
    C = N[2] - '0';
    D = N[3] - '0';

    for( int i = 0; i < 2; i++ )
    {
        for( int j = 0; j < 2; j++ )
        {
            for( int k = 0; k < 2; k++ )
            {
                int res = A;
                if( i == 0 )
                    res += B;
                else
                    res -= B;

                if( j == 0 )
                    res += C;
                else
                    res -= C;

                if( k == 0 )
                    res += D;
                else
                    res -= D;

                if( res == 7 )
                {
                    cout <<
                        A << (i==0?'+':'-') <<
                        B << (j==0?'+':'-') <<
                        C << (k==0?'+':'-') <<
                        D << "=7" << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  ll a,b;
  cin >> a>> b;
  ll ans = 2*b-a;

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


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

#define ll long long
#define N 200005
#define inf 1000000000

int to;
int n;
ll k;
int a[N];

ll cmp(ll val) {
	int p=to+1;
	ll cnt=0;
	for(int i=to;i>=1 && p<=n;i--) {
		while(val<0 && p<=n && abs((ll)a[i]*a[p])<abs(val)) p++;
		cnt+=max(0,n-p+1);
	}
	return cnt;
}

ll in(int l,int r,ll val) {
	int p=r;
	ll cnt=0;
	for(int i=l;i<p;i++) {
		while(p>0 && (ll)a[i]*a[p]>val) p--;
		cnt+=max(0,p-i);
	}
	return cnt;
}

ll cnt(ll val) {
	return in(1,to,val)+in(to+1,n,val)+cmp(val);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(to=1;to<=n;to++)
		if(a[to]>=0) break;
	reverse(a+1,a+to);
	to--;
	
	ll L=-(ll)inf*inf,R=-L;
	while(L<=R) {
		ll M=(L+R)>>1;
		if(cnt(M)>=k) R=M-1;
		else L=M+1;
	}
	cout<<L<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll mod=ll(1e9+7);



int main()
{
	IOS;
   int n,y;
   cin>>n>>y;
   y/=1000;


   for(int i=0;i<=n;i++) for(int j=0;i+j<=n;j++){
      if(10*i+5*j+n-i-j==y){
         cout<<i<<' '<<j<<' '<<n-i-j<<'\n';
         return 0;
      }
   }
   cout<<"-1 -1 -1\n";

	return 0;
}


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

int main( void )
{
    int x[4];
    while ( cin >> x[0] >> x[1] >> x[2] >> x[3] && x[0] && x[1] && x[2] && x[3] )
    {
        sort( x, x+4 );
        bool end = false;
        do {
            for ( int i = 0; i < 3 && end == false; i++ ) for ( int j = 0; j < 3 && end == false; j++ ) for ( int k = 0; k < 3 && end == false; k++ )
            {
                int answer = x[0];
                if ( i == 0 ) answer += x[1];
                if ( i == 1 ) answer -= x[1];
                if ( i == 2 ) answer *= x[1];
                if ( j == 0 ) answer += x[2];
                if ( j == 1 ) answer -= x[2];
                if ( j == 2 ) answer *= x[2];
                if ( k == 0 ) answer += x[3];
                if ( k == 1 ) answer -= x[3];
                if ( k == 2 ) answer *= x[3];

                if ( answer == 10 )
                {
                    char op[3];
                    if ( i == 0 ) op[0] = '+';
                    if ( i == 1 ) op[0] = '-';
                    if ( i == 2 ) op[0] = '*';
                    if ( j == 0 ) op[1] = '+';
                    if ( j == 1 ) op[1] = '-';
                    if ( j == 2 ) op[1] = '*';
                    if ( k == 0 ) op[2] = '+';
                    if ( k == 1 ) op[2] = '-';
                    if ( k == 2 ) op[2] = '*';
                    cout << "(((" << x[0] << " " << op[0] << " " << x[1] << ") " << op[1] << " " << x[2] << ") " << op[2] << " " << x[3] << ")" << endl;
                    end = true;
                    break;
                }

                int answer1 = 0, answer2 = 0;
                if ( i == 0 ) answer1 = x[0] + x[1];
                if ( i == 1 ) answer1 = x[0] - x[1];
                if ( i == 2 ) answer1 = x[0] * x[1];
                if ( j == 0 ) answer2 = x[2] + x[3];
                if ( j == 1 ) answer2 = x[2] - x[3];
                if ( j == 2 ) answer2 = x[2] * x[3];
                if ( k == 0 ) answer = answer1 + answer2;
                if ( k == 1 ) answer = answer1 - answer2;
                if ( k == 2 ) answer = answer1 * answer2;

                if ( answer == 10 )
                {
                    char op[3];
                    if ( i == 0 ) op[0] = '+';
                    if ( i == 1 ) op[0] = '-';
                    if ( i == 2 ) op[0] = '*';
                    if ( j == 0 ) op[1] = '+';
                    if ( j == 1 ) op[1] = '-';
                    if ( j == 2 ) op[1] = '*';
                    if ( k == 0 ) op[2] = '+';
                    if ( k == 1 ) op[2] = '-';
                    if ( k == 2 ) op[2] = '*';
                    cout << "((" << x[0] << " " << op[0] << " " << x[1] << ") " << op[2] << " (" << x[2] << " " << op[1] << " " << x[3] << "))" << endl;
                    end = true;
                    break;
                }
            }
        } while ( next_permutation( x, x+4 ) && end == false );

        if ( end == false ) cout << 0 << endl;
    }

    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> viNum(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &viNum[i]);
    }
    sort(viNum.begin(), viNum.end());
  
    if(viNum[n-1] <= 0){//全負
        int nAns = viNum[n-1];
        for(int i = 0; i < n-1; i++){
            nAns -= viNum[i];
        }
        printf("%d\n", nAns);
        int nTmp = viNum[n-1];
        for(int i = 0; i < n-1; i++){
            printf("%d %d\n", nTmp, viNum[i]);
            nTmp -= viNum[i];
        }
    } else if(viNum[0] >= 0){//全正
        int nAns = -viNum[0];
        for(int i = 0; i < n-1; i++){
            nAns += viNum[i+1];
        }
        printf("%d\n", nAns);
        int nTmp = viNum[0];
        for(int i = 0; i < n-2; i++){
            printf("%d %d\n", nTmp, viNum[i+1]);
            nTmp -= viNum[i+1];
        }
        printf("%d %d\n", viNum[n-1], nTmp);
    } else {//正も負もあり
        int nAns = abs(viNum[0]);
        for(int i = 0; i < n-1; i++){
            nAns += abs(viNum[i+1]);
        }
        printf("%d\n", nAns);
        int k = 0;
        while(k < n-1){
            k++;
            if(viNum[k] > 0){
                k--;
                break;
            }
        }
        int nTmp = viNum[k];
        for(int i = k + 1; i < n-1; i++){
            printf("%d %d\n", nTmp, viNum[i]);
            nTmp -= viNum[i];
        }
        printf("%d %d\n", viNum[n-1], nTmp);
        nTmp = viNum[n-1] - nTmp;
        for(int i = 0; i < k; i++){
            printf("%d %d\n", nTmp, viNum[i]);
            nTmp -= viNum[i];
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;

//Juan Pablo Betancourt Maldonado

int n, k;
const int nx = 1e5+5;
ll ac[nx][2];
ll dp[105][nx];
ll go(ll i, ll w){
	if(w>k) return -oo;
	if(i == n) return 0;
	if(dp[i][w] != -1) return dp[i][w];
	ll& ans = dp[i][w];
	ans = max(ans, go(i+1,w));
	if(w+ac[i][0]<=k) ans = max(ans, go(i+1,w+ac[i][0])+ac[i][1]);
	return ans;
}
int main(){
	
	cin>>n>>k;
	memset(dp, -1, sizeof dp);
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1];
	cout<<go(0,0)<<"\n";
}

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

int main() {
    ll a, b;
    ll x, r, temp;
    
    cin >> a >> b;
    
    x = a * b;
    
    if(a < b){
        temp = a;
        a = b;
        b = temp;
    }
    
    r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    
    cout << x/b << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

struct bridge {
  int start, end;
  bool operator<(const bridge& rhs) const {
    return start < rhs.start;
  }
};

int main() { _
  int n, m; cin >> n >> m;
  vector<bridge> bs(m);
  for (int i = 0; i < m; i++) {
    cin >> bs[i].start >> bs[i].end;
  }
  sort(bs.begin(), bs.end());
  int count = 1, minend = bs[0].end;
  int a = 1;
  while (true) {
    while (bs[a].start < minend) minend = min(minend, bs[a++].end);
    if (a >= m) break;
    count++;
    minend = bs[a].end;
  }
  cout << count << endl;
  return 0;
}

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


int main(void) {
        char str[256];
        int i, len;
        scanf("%s", str);
        len = strlen(str);
        for(i=0;i<len;i++) {
                printf("%c", str[len-i-1]);
        }
        printf("\n");

        return 0;
}

Measured memory_bytes: 524
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, q = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    for i in range(n-1):
        a, b = list(map(int, input().rstrip('\n').split()))
        d[a-1] += [b-1]
        d[b-1] += [a-1]
    ls = [0] * n
    for i in range(q):
        p, x = list(map(int, input().rstrip('\n').split()))
        ls[p-1] += x
    ql = collections.deque([0])
    fq = collections.defaultdict(int)
    fq[0]
    while True:
        if len(ql) != 0:
            p = ql.popleft()
            for v in d[p]:
                if v not in fq:
                    ls[v] += ls[p]
                    ql.appendleft(v)
                    fq[p]
        else:
            print(*ls)
            exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 123864
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	vector<string> a;
	int i;
	string h,k;
	cin>>k;
	for(i=0;i<k.length();i++)
	{
		if(k[i]=='0')
		{
			h.push_back('0');
		};
		if(k[i]=='1')
		{
			h.push_back('1');
		};
		if(k[i]=='B')
		{	if(h.length()!=0)
			h.erase(h.end() - 1);
		};
	};
	cout<<h<<endl;
	return 0;			
}

Measured memory_bytes: 256
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy                 \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define Accepted 0
typedef long long ll;
typedef vector<int> vi;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
void Open()
{
#ifndef ONLINE_JUDGE 
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
const int mod = ll(1e9 + 7), N = 2000 + 5;
//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
string s, t;
int mem[3011][3011];
int solve(int i = 0, int j = 0) {
	if (i == s.size() || j == t.size())return 0;
	int& ret = mem[i][j];
	if (~ret)return ret;
	ret = 0;
	if (s[i] == t[j])return ret=solve(i + 1, j + 1) + 1;
	ret = solve(i + 1, j);
	ret = max(ret, solve(i, j + 1));
	return ret;
}
void build(int i = 0, int j = 0) {
	if (i == s.size() || j == t.size())return;
	int ret = mem[i][j];
	if (s[i] == t[j]&&ret == solve(i + 1, j + 1) + 1) {
		cout << s[i];
		return build(i + 1, j + 1);
	}
	if (ret == solve(i + 1, j)) {
		return  build(i + 1, j);
	}
	if (ret == solve(i, j + 1)) {
	return 	build(i, j + 1);
	}
}
int main()
{
	Ma7moud_7amdy;
	Open_Sesame;
	cin >> s >> t;
	clr(mem, -1);
	solve();
	build();
}


Measured memory_bytes: 39300
N=int(input())
b=[0]+list(map(int,input().split()))

l=[]
f=True
for i in range(1,N+1):
    if not f:
        break
    for j in range(N+1-i,0,-1):
        if b[j]==j:
            l.append(b.pop(j))
            break
        if j==1:
            f=False

if f:
    for k in l[::-1]:
        print(k)
else:
    print(-1)

Measured memory_bytes: 38512