akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <set>

using namespace std;

int main(){

    int X,N;
    set<int> st;
    int p;
    int d;
    int min_d=500;
    int x;
    scanf("%d %d",&X,&N);
    for(int i=0;i!=N;++i){
        cin>>p;
        st.insert(p);
    }

    for(int i=-150;i<=250;++i){
        set<int>::iterator it=st.find(i);
        if(it==st.end()){
            d=abs(i-X);
            if(d<min_d){
                min_d=d;
                x=i;
            }
        }
    }

    cout<<x<<endl;
}

Measured memory_bytes: 3696
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
ans = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
def dfs(c, parent):
    for child in tree[c]:
        if child == parent:
            continue
        else:
            ans[child] += ans[c]
            dfs(child, c)
dfs(0, 0)
print(*ans)


Measured memory_bytes: 230960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second
#define Mod 1000000007


int main(){
    ll i,j;
    ll n;
    cin>>n;

    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];

    ll dp[n][n];

    for(i=0;i<n;i++){
        dp[i][i]=a[i];
    }
    for(j=1;j<n;j++){
        for(i=0;i+j<n;i++){
            dp[i][i+j]=max(a[i]-dp[i+1][i+j],a[i+j]-dp[i][i+j-1]);
        }

    }

    cout<<dp[0][n-1]<<endl;

}


Measured memory_bytes: 70400
/*
https://yamakasa.net/dainikai-zenkoku-touitu-procon-b/
勉強させて頂いた解説

整数列dの最大値を用いてloopさせたが、一部0を出力するケースで落ちるのでnで試す。
0以外でもダメなとこあるやん。
最初に0がこないとダメだよね！
整数列Dはi番目の頂点との距離を表しているため、0番目は当然距離0でなければならない。
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int MOD = 998244353;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n,ans=1;
    cin>>n;
    vector<ll>mp(n,0),d(n);
    rep(i,n){
        cin>>d[i];
        mp[d[i]]++;
    }
    //0が二つあったらおかしい
    if(mp[0]!=1||d[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    bool ok=true;
    rep(i,n){
        if(mp[i]==0){
            ok=false;
        }else{
            if(!ok){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    rep(i,n-1){
        //cout<<mp[i]<<"->"<<mp[i+1]<<endl;
        //上の頂点の数だけ選択肢があるため、それに下の頂点の数をかけることで木の数がわかる？
        //2のn乗の2の部分が上の頂点になっただけ。
        ans*=modpow(mp[i],mp[i+1]);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 4820
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int eves = n / 2, odds = n / 2 + n % 2;
	cout << eves * odds << '\n';
	return 0;
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string b[301];

int main() {
    ll N;
    cin >> N;
    rep(i, N) cin >> b[i];
    ll ans = 0;
    rep(A, N) {
        bool ok = true;
        rep(r, N) rep(c, N) {
            if (b[(r+A)%N][c] != b[(A+c)%N][r]) {
                //cout << b[(r+A)%N][c] << ", " << b[c][(r+A)%N] << endl;
                ok = false;
                break;
            }
        }
        if (ok) ans += N;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int memo[50] = {0,0,1};
int PD(int x);
int main(){
    int W,H;
    cin >> H;
    cin >> W;
    char flag[H+2][W+3];
    for(int i = 0;i < H;i++){
        cin >> flag[i];
    }
    int nuru = 0;
    int f = 0;
    int O = PD(H);
    int PP[O] = {0};
    int wp = 0,bp = H-2,rp = 0;
    for(int i = 0;i < W;i++){
        if(flag[0][i] != 'W'){
            nuru++;
        }
    }
    for(int i = 0;i < W;i++){
        if(flag[H-1][i] != 'R'){
            nuru++;
        }
    }
    for(int i =0;i < O;i++){
        for(int j = 0;j < H-2;j++){
            if(j < wp){
                for(int k = 0;k < W;k++){
                    if(flag[j+1][k] != 'W'){
                        //cout << j+1 << ',' << k << endl;
                        PP[i]++;
                    }
                }
            }
            else if(j < bp+wp){
                for(int k = 0;k < W;k++){
                    if(flag[j+1][k] != 'B'){
                        //cout << j+1 << ',' << k << endl;
                        PP[i]++;
                    }
                }
            }
            else if(j < rp+bp+wp){
                for(int k = 0;k < W;k++){
                    if(flag[j+1][k] != 'R'){
                        //cout << j+1 << ',' << k << endl;
                        PP[i]++;
                    }
                }
            }
        }
        bp--;
        rp++;
        if(bp == 0){
            wp++;
            bp = H-2-wp;
            rp = 0;
        }
    }
    int mini = 9999;
    /*for(int i = 0;i < O;i++){
        cout << PP[i] << ':' << endl;
    }*/
    for(int i = 0;i < O;i++){
        if(PP[i] < mini){
            mini = PP[i];
        }
    }
    cout << mini+nuru << endl;
    return 0;
}
int PD(int x){
    if(memo[x-1] != 0){
        return memo[x-1];
    }
    else{
        return memo[x-1] = PD(x-1) + (x-2);
    }
}
//2 3 4 5  6  7
//0 1 3 6 10 15

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
	const ll INF = 1e18;
	int Q;
	cin >> Q;
	vector<P> res;
	ll f = 0;
	priority_queue<ll> que1;
	priority_queue<ll, vector<ll>, greater<ll>> que2;
	que1.push(-INF);
	que2.push(INF);
	for (int q = 0; q < Q; ++q) {
		int op;
		cin >> op;
		if (op == 1) {
			ll a, b;
			cin >> a >> b;
			f += b;

			if (que1.top() <= a && a <= que2.top()) {
				que1.push(a);
				que2.push(a);
			} else if (a < que1.top()) {
				f += abs(que1.top() - a);
				que1.push(a);
				que1.push(a);
				que2.push(que1.top());
				que1.pop();
			} else if (que2.top() < a) {
				f += abs(que2.top() - a);
				que2.push(a);
				que2.push(a);
				que1.push(que2.top());
				que2.pop();
			}
		} else {
			res.push_back(P(que1.top(), f));
		}
	}

	for (int i = 0; i < res.size(); ++i) {
		cout << res[i].first << " " << res[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 6312
height, width = map(int, input().split())
 
if width == 1 or height == 1:
  result = 1
  
elif width%2 == 0:
    num_1 = width/2
    
    result = num_1 * height
    
else:
    num_1 = int(width/2) + 1
    
    if height%2 == 0:
        result = (num_1 + (num_1 - 1)) * height/2
    else:
        result = (num_1 + (num_1 - 1)) * int(height/2) + num_1
 
print(int(result))

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Xinyi Tao
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B0Or1SwapABC135 solver = new B0Or1SwapABC135();
        solver.solve(1, in, out);
        out.close();
    }

    static class B0Or1SwapABC135 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int c = 0;
            for (int i = 1; i <= n; i++) {
                if (in.nextInt() == i) c++;
            }
            out.println(c == n || c + 2 == n ? "YES" : "NO");

        }

    }
}



Measured memory_bytes: 23892
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(20);
    cout<<fixed;
    int n=0,k=0;double res=0.0;
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        double temp=1/double(n);
        int x=i;
        while(x<k)
        {
            x*=2;
            temp/=2;
        }
        res+=temp;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int n, m;
	while (cin >> n >> m, n, m){
		int asum = 0, bsum = 0;
		set<int> a, b;
		for (int i = 0; i < n; i++){
			int buff;
			cin >> buff;
			asum += buff;
			a.insert(buff);
		}
		for (int i = 0; i < m; i++){
			int buff;
			cin >> buff;
			bsum += buff;
			b.insert(buff);
		}

		int sa = asum - bsum;
		if (sa % 2 != 0) cout << -1 << endl;
		else{
			int result1 = 200, result2 = 200;
			sa = sa / 2;
			bool flag = false;
			set<int>::iterator it = a.begin();


			while (it != a.end())
			{
				if (b.find(*it - sa) != b.end()){
					flag = true;
					if (result1 + result2 > *it + *it - sa){
						result1 = *it;
						result2 = *it - sa;
					}
				}
				++it;
			}


			if (!flag) cout << -1 << endl;
			else cout << result1 << " " << result2 << endl;

		}
	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

Measured memory_bytes: 1196
n=int(input())
a_list=[0]
for i in range(n):
    a_list.append(int(input()))
S=sum(a_list)
dp=[]
dp_1=[]
mod=998244353
for i in range(n+1):
    sub_list=[0]*(S+1)
    dp.append(sub_list)
    sub_list=[0]*(S+1)
    dp_1.append(sub_list)
dp[0][0]=1
dp_1[0][0]=1
for i in range(1,n+1):
    for j in range(S+1):
        if j>=a_list[i]:
            dp[i][j]=(dp[i-1][j]*2+dp[i-1][j-a_list[i]])%mod
            dp_1[i][j]=(dp_1[i-1][j]+dp_1[i-1][j-a_list[i]])%mod
        else:
            dp[i][j]=dp[i-1][j]*2%mod
            dp_1[i][j]=dp_1[i-1][j]%mod
Sum=0
for i in range(S+1):
    if i>S/2:
        Sum=(Sum+dp[n][i]*3)%mod
    elif i==S/2:
        Sum=Sum+dp[n][i]*3-dp_1[n][i]*3
ans=(pow(3,n,mod)-Sum)%mod
print(ans)



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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  string s;

  cin >> s;
  cout << s;
  if (s[s.size() - 1] == 's')
    cout << "es";
  else
    cout << "s";
  cout << endl;
}


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

#define irep(i,n)  for(int i=0;i<(n);i++)
#define irepy(i,n) for(int i=1;i<=(n);i++)
#define jrep(j,n)  for(int j=0;i<(n);j++)
#define jrepy(j,n) for(int j=1;i<=(n);j++)

/*
林檎が A 個、林檎の欠片が P 個あります。

林檎 1 個は、砕くことで林檎の欠片 3 個になります。また、林檎の欠片 2 個を鍋で煮込むことで、アップルパイが 1 個作れます。

今ある材料で作れるアップルパイの最大数を求めてください。
*/
int main(){
  int a,p;
  cin>> a >> p;
  
  p+=a*3;
  
  int ans=p/2;

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    ll n, x;
    cin >> n >> x;

    ll ans = n;
    ll a = x, b = n - x;
    while (a > 0 and b > 0) {
        if (a >= b) {
            ll nn = a / b;
            if (a % b != 0) {
                ans += 2 * nn * b;
            }
            else {
                ans += (2 * nn - 1) * b;
            }
            a %= b;
        }
        ans += 2 * a;
        ll nb = a;
        ll na = b - a;
        a = na; b = nb;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/
void go(){
    int x,y,a,b;
    R(x,y,a,b);
    W((x-a)*(y-b));
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int a[N];
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = false;
	ans = 0;
	scanf("%d", &n);
	while (n >= 0){
		if (n % 4 == 0)v = true;
		n -= 7;
	}


	if(v)printf("Yes\n");
	else printf("No\n");


	return 0;
}


Measured memory_bytes: 128
n = int(input())
s = [input() for _ in range(n)]
s.sort()
# print(s)

ans = []
max = 0
tmp = 1

for i in range(1,n):
  if s[i] == s[i-1]:
    tmp += 1
  if s[i] != s[i-1]:
    if max == tmp:
      ans.append(s[i-1])
    if max < tmp:
      ans = [s[i-1]]
      max = tmp
    tmp = 1
###print(ans)
if max == tmp:
  ans.append(s[n-1])
if max < tmp:
  ans = [s[n-1]]
  
for i in ans:
  print(i)

Measured memory_bytes: 20672
#include<bits/stdc++.h>
     
#define int long long 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb emplace_back
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<typename T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<typename T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T> bool Min(T a, T b) { return a > b ? b : a; }
template<typename T> bool Max(T a, T b) { return a < b ? b : a; }
template<typename T> void de(T a ){
#ifdef LOCAL
	cout<<a<<" ";
#endif
}
const int INF = 2e5+1;


void solve(){
	string s;
	cin>>s;
	bool bani = true;
	int n = sz(s);
	for(int i=0;i<n;i++){
		if( (s[i]=='L' && (i%2==0)) || (s[i]=='R' && (i%2==1))){
			bani = false ;
			break;
		}
	}
	if(bani){
		cout<<"Yes"<<endl;
	}else {
		cout<<"No"<<endl;
	}
}
 
int32_t main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt","w",stdout);
#endif
        int q=1;
#ifdef LOCAL 
        cin>>q;
#endif
        while(q--){
            solve();
        }
               
#ifdef LOCAL
    cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
 
	return 0;
}	
 


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

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

	vector<int> v(3);
	cin>>v[0]>>v[1]>>v[2];
	sort(v.begin(), v.end());

	int res=1e9;
	do {
    	int ans=0;
    	ans+=abs(v[1]-v[0]);
    	ans+=abs(v[2]-v[1]);
    	res=min(res, ans);
  	} while ( std::next_permutation(v.begin(), v.end()));
  	cout<<res<<endl;
	return 0;
}




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


int main(){
  string s;
  cin >> s;
  int sz=s.size();
  vector<int> n(sz);
  rep(i,sz){
    n[i]= 26 - s[i] + 'a';
    n[i]%=26;
  } 

  int k;
  cin >> k;

  rep(i,sz-1){
    if(k>=n[i]){
      s[i] = 'a';
      k -= n[i];
    }
  }
  
  if (k>0){
    k%=26;
    if(k>'z'-s[sz-1]) s[sz-1] += k-26;
    else s[sz-1] += k;

  } 

  cout << s;

}


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

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

  	int res = 0;
    bool flag = false;
    for (int i = N.size() - 1; i > 0; i--) {
        if (N[i] != '9' && i > 0) {
            flag = true;
            res = i;
            break;
        }
    }

    int ans = 0;
    if (flag) {
        for (int j = res; j > 0; j--) {
                N[j] = '9';
            }
        N[0]--;
        for (int i = 0; i < N.size(); i++) {
            ans += N[i] - '0';
        }
        cout << ans << endl;
    }
    else {
        for (int i = 0; i < N.size(); i++) {
            ans += N[i] - '0';
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main() {
	string s;
	cin >> s;
	int x=-1, y;
	rep(i, s.size()) {
		if (x==-1&&s[i] == 'A')x = i;
		if (x != -1) {
			if (s[i] == 'Z')y = i;
		}
	}
	cout << y - x + 1 << endl;
	getchar(); getchar();
	return 0;
}

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

#define rep(i,n) for(int i{0};i<(int)n;++i)

signed main(){

  int h,w;
  scanf("%d %d",&h,&w);
  char s[30][30];
  scanf("%c",&s[0][0]);
  rep(i,h){
    rep(j,w){
      scanf("%c",&s[i][j]);
    }
    scanf("%c",&s[25][25]);
  }

  int ans = 0;
  rep(i,h)rep(j,w){
    if(s[i][j]=='#')continue;
    queue<tuple<int,int,int>> que;
    que.emplace(i,j,0);
    int dist[30][30];
    constexpr int inf = 1<<28;
    rep(k,h)rep(l,w)dist[k][l]=inf;
    while(!que.empty()){
      int y,x,c;
      tie(y,x,c) = que.front();
      que.pop();
      if(dist[y][x]>c){
        if(c>ans)ans=c;
        dist[y][x]=c;
        int ny{y},nx{x};
        ny--;
        if(ny!=-1&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        ny+=2;
        if(ny!=h&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        ny--;
        nx--;
        if(nx!=-1&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
        nx+=2;
        if(nx!=w&&s[ny][nx]!='#')que.emplace(ny,nx,c+1);
      }
    }
  }
  printf("%d",ans);

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    string s, t; 
    int ans=0;

    cin >> s;
    cin >> t;
    
    //cout << s << endl;
    //cout << t << endl;

    rep(i, 0, 3) {
        if(s[i] == t[i]) {
            ans++;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

int main()
{
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N,0);
  vector<vector<int>> A;

  for (int n=0; n<N; ++n) {
    A.push_back(vector<int>());
    cin >> C[n];
    for (int m=0; m<M; ++m) {
      int a;
      cin >> a;
      A.back().push_back(a);
    }
  }

  int min_cost = INT32_MAX;
  for (int comb=0; comb< (1<<N); ++comb) {

    int cost = 0;
    vector<int> x(M,0);

    for (int n=0; n<N; ++n) {
      if ((comb>>n)%2==0)
	continue;

      cost += C[n];

      for (int m=0; m<M; ++m) {
	x[m] += A[n][m];
      }
    }

    bool ok = true;

    for (int m=0; ok && m<M; ++m) {
      if (x[m] < X)
	ok = false;
    }

    if (ok)
      min_cost = min(cost, min_cost);
  }

  cout << (min_cost==INT32_MAX ? -1 : min_cost) << endl;

  return 0;
}


Measured memory_bytes: 3632
N = gets.to_i
X = gets.split.map(&:to_i)
X.sort!

ans = 10 ** 9

(X.min..X.max).each do |p|
    sum = 0
    X.each do |x|
        sum += (x - p) ** 2
    end

    ans = [sum, ans].min
end

puts ans

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

#define pb push_back
#define ll long long

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int ans = n*(n-1) + m*(m-1);
    cout << ans/2 << "\n";
    return 0;
}


Measured memory_bytes: 256
# ABC 137 E    E. Coins Respawn

import sys
input=sys.stdin.readline  #危険！基本オフにしろ！

n,m,p=map(int,input().split())

d={}
for s in range(m):
    a,b,c=map(int,input().split())
    if a in d:
        d[a].append((b,c))
    else:
        d[a]=[(b,c)]

#print(d)


def BELLMANFORD(point,d,p):
    cost       = [-float("inf")]*(n+1)  #infじゃないと閉路検出がうまくいかない
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p

    negative=[0]*(n+1)                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定 negativeの1は閉路に入っている部分を表す
        for now,lis in d.items():
            for nex,c in lis:
                if negative[now]==1:
                    negative[nex]=1
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
                    negative[now]=1
 
    return cost,negative

def main():
    x,y=(BELLMANFORD(1,d,p))
    
    if y[n]==1:
        print(-1)
    else:
        print(max(x[n],0))

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 50344
def solve():
    n, k = read()
    result = think(n, k)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, k):
    return k * (k - 1) ** (n - 1)


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
    
        using namespace std;
        #define ll long long
        #define ld long double
        #define vll vector<ll>
        #define mll map<ll,ll>
        #define pll pair<ll,ll>
        #define ff first
        #define ss second
        #define pb push_back
        #define deb(x) cout<<#x<<" : "<<x<<endl;
        #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
        #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
        #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
        #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
       
       
        const int mod=998244353;
        const int N=1e6+5; 
        const ll inf=1e18+5;
       
        bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                          const pair<pair<ll,ll>,ll> &b) 
            { 
                return (a.second > b.second); 
            } 
            ll powermod(ll x, ll y, ll p)
            {
                ll res = 1;
                x = x % p;
                while (y > 0)
                {
                    if (y & 1) res = (res*x) % p;
                    y = y>>1;
                    x = (x*x) % p;
                }
                return res;
            }
           
            bool isprime(int n) 
            { 
                if (n <= 1)  return false; 
                if (n <= 3)  return true; 
                if (n%2 == 0 || n%3 == 0) return false; 
                for (int i=5; i*i<=n; i=i+6) 
                    if (n%i == 0 || n%(i+2) == 0) 
                       return false; 
               return true; 
            }
           
            
        int main()
        {
            FAST;
            ll n;
            cin>>n;
            ll ans=1000*(n/500);
            
            n%=500;
            ans+=5*(n/5);
            cout<<ans;
               
            return 0;
        }

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for(ll b = K+1; b <= N; b++) {
        ans += N/b * (b-K);
        if (N%b != 0) {
            if (K == 0)
                ans += max(0LL, N%b - K);
            else
                ans += max(0LL, N%b - K + 1);
        }
    }
    print(ans);
    return 0;
}

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

using namespace std;

const int N = 500017;
const int MOD = 1000 * 1000 + 3;

int q;
long long F[MOD];

bool read() {
    if (!(cin >> q))
        return false;

    return true;
}

long long binpow(long long a, long long b, long long mod) {
    long long res = 1;

    for (; b > 0; b /= 2, a = a * a % mod)
        if (b & 1)
            res = res * a % mod;

    return res;
}

long long rev(long long a, long long mod) {
    return binpow(a, mod - 2, mod);
}

void solve() {
    F[0] = 1;

    for (int i = 1; i < MOD; ++i)
        F[i] = (long long) i * F[i - 1] % MOD;

    while (q --> 0) {
        int a, d, n;
        cin >> a >> d >> n;

        if (d == 0) {
            cout << binpow(a, n, MOD) << endl;
            continue;
        }

        a = a * rev(d, MOD) % MOD;

        if (a + n - 1 < MOD)
            cout << binpow(d, n, MOD) * F[a + n - 1] % MOD * rev(F[a - 1], MOD) % MOD;
        else
            cout << 0;

        cout << endl;
    }
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=2015;
const int NN=1000001;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    int a[N]={0};
    int s=0;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        s+=a[i];
    }
    sort(a+1,a+n+1);
    for (int i=n;i>=n-m+1;i--){

        //cout << a[i] << " " << s << " " << m*4*a[i] << E;
        if (m*4*a[i]<s){
            cout << "No" << E;
            r0;
        }

    }
    cout << "Yes" << E;
    r0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func gcd(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return gcd(a%b, b)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func nextByte() byte {
	sc.Scan()
	s := sc.Bytes()
	return s[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	N := nextInt()
	ans := 0
	var A [100005]int
	var Buckets [100005]int
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		if A[i] > N {
			ans++
		} else {
			Buckets[A[i]]++
		}
	}
	for i := 1; i <= 100000; i++ {
		if Buckets[i] < i {
			ans += Buckets[i]
		} else {
			ans += (Buckets[i] - i)
		}
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 4236
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def placingMarbles(input_str):
    vals = input_str.split(" ")
    r = int(vals[0])
    D = int(vals[1])
    x_i = int(vals[2])

    for i in range(10):
        x_i = xinext(r, x_i, D)
        print(x_i)

def xinext(r, xi, D):
    return r * xi - D

if __name__ == "__main__":
    placingMarbles(input()) 


Measured memory_bytes: 2940
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def dfs(x,y,s,c):
    global tmpp
    if not(0<=x<W and 0<=y<H):
        return
    elif tmpp[y][x] != s:
        return
    else:
        tmpp[y][x] = c
        dfs(x+1,y,s,c)
        dfs(x-1,y,s,c)
        dfs(x,y+1,s,c)
        dfs(x,y-1,s,c)

def calc(x,y):
    global tmpp
    if not(0<=x<W and 0<=y<H):
        return 0
    elif tmpp[y][x] != C:
        return 0
    else:
        tmpp[y][x] = -1
        return calc(x+1,y) + calc(x-1,y) + calc(x,y+1) + calc(x,y-1) + 1



while True:
    H,W,C = inpl()
    if H == 0:
        break
    pp = [inpl() for _ in range(H)]
    ans = 0

    for arg in itertools.product(range(1,7),repeat=4):
        colors = list(arg) + [C]
        tmpp = [p[:] for p in pp]
        for c in colors:
            if tmpp[0][0] == c:
                continue
            else:
                dfs(0,0,tmpp[0][0],c)

        ans = max(calc(0,0),ans)

    print(ans)



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


int main() {
  int ab, bc, ca;
  cin >> ab >>bc >> ca;
  int s = ab*bc/2;
  cout << s << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
constexpr int PMAX = 2000000;

bool isPrime[PMAX];

int main() {
	for (int i = 2; i < PMAX; ++i) isPrime[i] = true;
	for (int i = 2; i < PMAX; ++i) {
		if (!isPrime[i]) continue;
		for (int j = 2 * i; j < PMAX; j += i) isPrime[j] = false;
	}
	ll n; scanf("%lld", &n);	
	map<ll, int> fac;
	ll cn = n;
	for (int i = 2; i < PMAX; ++i) {
		while (cn % i == 0) {
			fac[i]++;
			cn /= i;
		}
	}
	if (cn > 1) fac[cn] = 1;
	int ans = 0;
	for (auto p_e : fac) {
//		printf("%lld %d\n", p_e.first, p_e.second);
		int totals = 0, curExp = 0;
		while (totals <= p_e.second) {
			totals += ++curExp;
//			printf("tot %d cur %d\n", totals, curExp);
		}
		ans += curExp - 1;
	}
	printf("%d\n", ans);
	return 0;
}


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	string s,t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0;i<sz(s);i++){
		if(s[i]!=t[i])cnt++;
	}
	cout<<cnt;
}





Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <functional>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279
#endif

#define int long long

#define mp make_pair
#define mt make_tuple
#define fr first
#define sc second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>

#define debug(x) cerr << #x << " = " << x << ", line = " << __LINE__ << endl

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef tuple<long long, long long, long long> tlll;
typedef tuple<int, int, int> tiii;
typedef tuple<int, int, int, int> tiiii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;



int32_t main()
{
#ifdef chikibambony
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >> b[j];
    }
    reverse(all(b));
    int c = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            c = a[i];
            break;
        }
    }
    int l = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] == c) {
            l = i;
            break;
        }
    }
    int r = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == c && b[i] == c) {
            r = i;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }

    if (l <= r) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    for (int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
        assert(b[i] != a[i]);
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <map>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <bitset>
using namespace std;

#define ll long long
#define N 200005

int type[N];
int a[N],b[N];

ll cc[N],sum[N];

void update(ll *pen,int ind,ll val) {
  while(ind<N) {
    pen[ind] += val;
    ind += ind&(-ind);
  }
}

ll val[N];
ll query(ll *pen,int ind) {
  ll ret = 0;
  while(ind>0) {
    ret += pen[ind];
    ind = ind&(ind-1);
  }
  return ret;
}
void solve() {
  int Q;scanf("%d ", &Q);
  map<int,int> Hash;
  for(int i=0;i<Q;++i) {
    scanf("%d ", &type[i]);
    if(type[i]==1) {
      scanf("%d %d ", &a[i],&b[i]);
      Hash[a[i]];
    }
  }
  int pos=0;
  for(map<int,int>::iterator it = Hash.begin();it!= Hash.end();++it) {
    it->second = ++pos;
    val[pos] = it->first;
  }
  long long sumOfB = 0;
  int numTypeOne = 0;
  set<int> s;

  for(int i=0;i<Q;++i) {
    if(type[i]==1) {
      sumOfB += b[i];
      int aId = Hash[a[i]];
      update(cc,aId,1);
      update(sum,aId,a[i]);
      s.insert(a[i]);
      ++numTypeOne;
    } else {
      int l = 1 , r= pos,mid;
      while(l<r) {
        mid = (l+r)/2;
        if(query(cc,mid)*2>numTypeOne) {
          r = mid;
        } else {
          l = mid+1;
        }
      }
      ll R = 4e18;ll k=1e18;
      set<int>::iterator it = s.lower_bound(val[l]);
      if(it!=s.end()) {
        int numCount = 2;
        while(numCount>0 && it!= s.end()) {
          ll v = *it;
          int xx = Hash[v];
          ll numLow = query(cc,xx);
          ll sumLow = query(sum,xx);
          ll numHigh = numTypeOne-numLow, sumHigh = query(sum,N-1) - sumLow;
          ll tmp = numLow*v - sumLow + sumHigh - numHigh*v;
          if(R>=tmp) {
            if(R==tmp) {
              k = min(k,v);
            } else {
              R = tmp;
              k = v;
            }
          }
          --numCount;
          ++it;
        }
      }
      it = s.lower_bound(val[l]);
      if(it!=s.begin()) {
        --it;
        int numCount = 2;
        while(numCount>0 ) {
          ll v = *it;
          int xx = Hash[v];
          ll numLow = query(cc,xx);
          ll sumLow = query(sum,xx);
          ll numHigh = numTypeOne-numLow, sumHigh = query(sum,N-1) - sumLow;
          ll tmp = numLow*v - sumLow + sumHigh - numHigh*v;
          if(R>=tmp) {
            if(R==tmp) {
              k = min(k,v);
            } else {
              R = tmp;
              k = v;
            }
          }
          if(it==s.begin()) {
            break;
          }
          --numCount;
          --it;
        }
      }
      printf("%lld %lld\n",k, R + sumOfB);
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 18176
#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <unordered_map>
#include <map>
//#include <queue>
//#include <cstring>

//#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#define MOD		1000000007
#define ll		unsigned long long int
#define pll		pair<ll, ll>
#define pb		push_back
#define endl	"\n"
#define f 		first
#define s 		second
#define fastio 	ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v)  (v).begin(), (v).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

//ll power(ll x, ll y) { ll ans = 1; x; while (y) {if (y & 1)ans = (x * ans); x = (x * x); y >>= 1;} return ans;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};



void solve() {
    ll n, m, x;

    cin >> n >> x >> m;
    
    if(n == 1) {
        cout << x << endl;
        return;
    }

    map<ll, ll> mp;

    ll pref[m + 10];

    pref[0] = 0;

    ll i = 2;

    pref[1] = x;

    for(; i <= n; i++) {
        x *= x;
        x %= m;

        pref[i] = pref[i - 1] + x;
        //debug(x, pref[i]);
        if(mp[x]) {
            break;
        } else {
            mp[x] = i;
        }
    }

    ll ans = pref[mp[x]];

    if(i <= n) {
        ans = pref[mp[x] - 1];
        ll rem = n - mp[x] + 1;
        ll btw = i - mp[x];

        ans += ((rem/btw) * (pref[i - 1] - pref[mp[x] - 1]));

        ans += ((pref[mp[x] - 1 + (rem % btw)] - pref[mp[x] - 1]));
    }



    cout << ans << endl;

}

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


Measured memory_bytes: 7124
#include <iostream>
#include<math.h>
#include<algorithm>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	int cnt = 0;
	int max = 0;
	cin >> max;
	cnt++;

	for (int i = 1; i < N; i++){
		int h;
		cin >> h;
		if (h >= max){
			max = h;
			cnt++;
		}
	}

	cout << cnt << endl;
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<n;++i){
        bool flag = true;
        for(int j=0;j<3;++j){
            if(i+j >= n){
                flag = false;
                break;
            }
            if(s[i+j] != "ABC"[j]){
                flag = false;
                break;
            }
        }
        if(flag)ans++;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;


const int maxn = 1e5 + 5;
int num[maxn], x[maxn];

int main()
{
    int n, s;
    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; i ++)
    {
        scanf("%d%d",x+i,num+i);
    }
    int l=1,r=n;
    long long ans=0;
    long long sum=0;
    int nows;
    bool flag;
    if(num[1]>=num[n]){
        nows=x[n];sum+=num[r];
        flag=1;
    }
    else{
        nows=x[1];sum+=num[l];
        flag=0;
    }
    while(s<x[r]&&s>x[l]){
        //printf("%d %d %lld %lld\n",l,r,ans,sum);
        if(flag){
            if(num[l]>=sum){
                ans+=abs(nows-x[l]);
                flag=0;
                nows=x[l];
                sum+=num[l];
                r--;
            }
            else
                sum+=num[l++];
        }
        else{
            if(num[r]>sum){
                ans+=abs(x[r]-nows);
                flag=1;
                nows=x[r];
                sum+=num[r];
                l++;
            }
            else
                sum+=num[r--];
        }
    }
    //printf("%d %d %lld %lld\n",l,r,ans,sum);
    if(s>x[r]){
        ans+=abs(nows-x[l]) + abs(nows-s);
    }
    else ans+=abs(nows-s) + abs(nows-x[r]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s; cin >> s;
    string t; cin >> t;
	long long cur = -1;
	long long ans = 0;
	vector<vector<long long>> v(26);

    for (int i = 0; i < 2 * s.size(); i++) {
        v[s[i % s.size()] - 'a'].push_back(i);
    }
	for(char c : t) {
		auto it = upper_bound(begin(v[c - 'a']), end(v[c - 'a']), cur);
		if (it == v[c - 'a'].end()) {
			cout << -1 << endl;
			return 0;
		}
		ans += *it - cur;
		cur = *it % s.size();
	}
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2800