akhauriyash/Code-Regression huggingface dataset:
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, T;
    scan(N, T);
    auto t = aryread();
    long l = 0;
    long ans;
    foreach (i; 0 .. N)
    {
        ans += min(T, t[i] + T - l);
        l = t[i] + T;
        // writeln(l);
    }
    writeln(ans);
}


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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

string s;
ll ans;

void dfs(int d, int u){
	if(d == s.length()-1) {
		ll t = s[0] - '0';
		for(int i = 0; i < s.length()-1; i++){
			if(u & (1 << i)){
				ans += t;
				t = s[i+1] - '0';
			}else{
				t *= 10;
				t += s[i+1] - '0';
			}
		}
		ans += t;
		return;
	}

	int b = (1 << d);
	dfs(d+1, u);
	dfs(d+1, u+b);
}

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

	cin >> s;
	ans = 0;
	dfs(0, 0);

	cout << ans << endl;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<ll> cnt(N);
  for (ll i = 0; i < M; i++) {
    ll a, b; cin >> a >> b; a--; b--;
    cnt[a]++;
    cnt[b]++;
  }
  for (ll i = 0; i < N; i++) {
    if (cnt[i] % 2 == 1) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";


  return 0;
}



Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define ff first
#define ss second
#define vi vector<int>
#define pb emplace_back
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<ll,ll>>
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i=0 ; i<n ; ++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;
 
using namespace std;

int main(){
	fast
	long long int n;
	cin >> n;
	long long int cur = 100;
	int cnt=0;
	while(1){
		if(cur>=n)break;
		cur+=cur/100;
		cnt++;
	}
 cout << cnt;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define Vector point
using namespace std;
inline int read()
{
	int x=0,fl=1;char st=getchar();
	while(st<'0'||st>'9'){ if(st=='-')fl=-1; st=getchar();}
	while(st>='0'&&st<='9') x=x*10+st-'0',st=getchar();
	return x*fl;
}
const int N=2005,mod=1e9+7;
int n,k;
ll f[N<<1][N],fac[N*N],invfac[N*N];
inline ll ksm(int x,int y)
{
	ll res=1;
	while(y)
	{
		if(y&1) res=res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
inline ll C(int x,int y)
{
	if(y==0) return 1ll;
	return fac[x]*invfac[x-y]%mod*invfac[y]%mod;
}
int main()
{
	n=read();k=read();
	if(k==1)
	{
		puts("1");
		return 0;
	}
	fac[0]=1;invfac[0]=1;
	for(int i=1;i<=n*k;i++)
		fac[i]=(ll)fac[i-1]*i%mod,invfac[i]=ksm(fac[i],mod-2);
	f[0][0]=1;
	for(int i=1;i<=2*n;i++)
		for(int j=0;j<=min(n,i);j++)
		{
			if(j) f[i][j]=(f[i][j]+f[i-1][j-1])%mod;
			if(j+1<=i-1)
			{
				int numc=(i-1-j-1)/2;
				f[i][j]=(f[i][j]+f[i-1][j+1]*(n-numc)%mod*C(n*k-i-numc*(k-2),k-2)%mod)%mod;
			}
		}
	printf("%lld",f[n<<1][0]);
	return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back

typedef long long LL;
typedef  pair<int,int > PII;

const double PI = acos(-1.0);
//const int INF = 1000 * 1000 * 1000 + 1;
const LL INF = 1e15 + 7;
const int MAS =4e5; //5;
const int MOD = 998244353;
const double EPS = 1e-8;


typedef vector<int > VI;
typedef vector<LL> VL;



VL t;
VL lazy;

void update(int v, int tl, int tr  ,int l ,int r,LL val )
{
     if (lazy[v]!=0)
     {
         t[v]+=lazy[v];
         if(tl !=tr)
         {
             lazy[v * 2 ] +=lazy[v];
             lazy[v * 2 + 1] +=lazy[v];
         }
         lazy[v] = 0;
     }
      if ( l<=tl && r >=tr)
      {
          t[v] += val;
          if(tl !=tr)
          {
              lazy[v * 2] +=val;
              lazy[v * 2 +1] +=val;
          }
          return ; 
      }
    if ( tr < l || tl > r)return ;
    int tm  = (tl + tr)/2;
     update(v * 2 , tl , tm , l ,r ,val);
     update(v * 2 + 1, tm  +1 ,tr, l ,r ,val);
     t[v] = min(t[v* 2],t[v * 2 +1]);
}
LL  mn (int v ,int tl ,int tr ,int l ,int r )
{
     if (lazy[v] !=0)
     {
         t[v] +=lazy[v];
         if(tl !=tr)
         {
             lazy[v * 2] +=lazy[v];
             lazy[v * 2 + 1] +=lazy[v];
         }
         lazy[v] = 0;
     }
     if (tl > r || tr < l )
     {
         return INF;
     }
     if(l <=tl && r >=tr)
     {
         return t[v];
     }
     int tm = (tl + tr)/ 2;
     return min(mn(v * 2 ,tl ,tm, l ,r ),mn (v* 2 +1 ,tm + 1, tr, l ,r )) ;
}


int main() {
    //freopen("sum.in","r",stdin);
    //freopen("sum.out","w",stdout);

    IOS;
     int n,m ;
     cin >> n  >> m ;
     LL sum = 0 ;
     vector<vector<pair<int,int >>> ev(n + 5);
     rep(i,m)
     {
         int l ,r ,val;
         cin >> l >> r >> val;
         ev[r].PB({l,val});
         sum+=val;
     }
     LL ans =0 ;
  //   return 0 ;
       t.resize(4 * (n + 5 )  ,INF);
       lazy.resize(4 * (n +5 ) );
     //  return 0;
       update(1, 0, n, 0 , 0 ,-INF);
    // cout <<  mn( 1, 0 , n -1 , 0 , n-1 ) << endl;
    // return 0 ;
     FOR(i,1,n +2)
     {
         for(pair<LL,LL> p : ev[i-1])
         {
             update(1,0,n,0,p.first - 1 ,p.second);
         }
         LL best = mn(1, 0 , n , 0 , n );
      //   cout << i << " " << best  << " " ;
         if( i == n + 1)
         {
             ans = best;
         }
         update(1,0,n,i,i,best - INF);
       //  cout <<  mn (1, 0 , n , 0 ,n ) << endl;
     }
    // cout << ans << endl;
    cout << sum - ans;
}

Measured memory_bytes: 23680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N, K;
ll S;

int main () {
  cin >> N >> K >> S;

  vector<ll> ans;

  if (S == 1) {
    Rep(i, K) {
      ans.push_back(1);
    }
    Rep(i, N-K) {
      ans.push_back(2);
    }
  } else {
    Rep(i, K) {
      ans.push_back(S);
    }
    Rep(i, N-K) {
      ans.push_back(S-1);
    }
  }

  printv(ans);
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
// using ll = long long;
// using vl = vector<ll>;
// using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

// #define D_MAX 100

int main(){
	int N,D,X; cin>>N>>D>>X;
	vi days(D+1);
	rpz(i,N){
		int a; cin>>a;
		rpz(j,D){
			int day = j*a + 1;
			if(day > D) break;
			days[day]++;
		}
	}
	int ans = 0;
	rpz(i,D+1){
		ans += days[i];
	}
	ote(ans+X);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    string n;cin >> n;
    int x = 0;
    rep(i,n.size()){
        int c = n[i]-'0';
        x+=c;
    }
    if(x%9==0) cout <<"Yes" <<endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 3708
#include <iostream>

using namespace std;
int tot,n,i,j,a[205];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;i++)
    {
        j=i;
        while(j<=n&&a[i]==a[j]) j++;
        j--;
        tot+=(j-i+1)/2;
        i=j;
    }
    cout<<tot;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


string s;

vector<pii> u;
void calc(int& i) {
    if(i == s.size()) return;
    assert(s[i] == '(');
    int l = i;
    ++i;
    while(s[i] == '(') calc(i);
    assert(s[i] == ')');
    u.push_back(make_pair(l, i));
    ++i;
    // cout << l << " " << i << endl;
}

int main(){
    int n;
    cin >> n;
    vector<pii> v(n);
    rep(i, n) {
        int j;
        cin >> j;
        --j;
        v[i] = make_pair(j, i);
    }
    sort(all(v));
    priority_queue<int,vector<int>,greater<int> > q;
    int cur = 0;
    rep(i, n) {
        s += '(';
        q.push(v[i].se);
        while(q.top() == cur) {
            q.pop();
            ++cur;
            s+=')';
        }
    }
    int id = 0;
    while(id < s.size()) calc(id);

    dumpV(u);

    {
        map<int, int> mp;
        for(auto&& p : u) mp[p.se] = 1;
        int cnt = 0;
        for(auto&& p : mp) p.se = cnt++;
        for(auto&& p : u) p.se = mp[p.se];
    }
    {
        map<int, int> mp;
        for(auto&& p : u) mp[p.fi] = 1;
        int cnt = 0;
        for(auto&& p : mp) p.se = cnt++;
        for(auto&& p : u) p.fi = mp[p.fi];
    }
    sort(all(u));
    if(v == u) cout << s <<endl;
    else cout << ":(" << endl;

    dump(s);
    dumpV(v);
    dumpV(u);
    return 0;
}


Measured memory_bytes: 13132
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> P;
constexpr ll mod = 1000000007;
int main() {
	char s[100000];
	cin >> s;
	ll i , ch = 0;
	for (i = 0; i < strlen(s); i++) {
		if ((s[i] == '1' && i % 2 == 1) || (s[i] == '0' && i % 2 == 0)){}
		else
			ch++;
	}
	if (ch * 2 >= i)
		cout << i - ch;
	else
		cout << ch;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)
#define INF 1000000010

int main() {
  string s;
  cin>>s;
  if(s.at(0)==s.at(s.size()-1)){
    if(s.size()%2==1){
      cout<<"Second"<<endl;
    }else cout<<"First"<<endl;
  }else{
    if(s.size()%2==1){
      cout<<"First"<<endl;
    }else cout<<"Second"<<endl;
  }
return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int d4x[4] = {0,1,0,-1};
int d4y[4] = {1,0,-1,0};

int main(){
	int H,W;
	cin>>H>>W;
	char maze[55][55];
	int ans[55][55];
	int b_cnt = 0;
	REP(i,H)REP(j,W){
		cin>>maze[i][j];
		if(maze[i][j] == '#')++b_cnt;
		ans[i][j] = -1;
	}
	queue<ip> Q;
	Q.push(make_pair(1, 1));
	ans[1][1] = 0;
	while(!Q.empty()){
		int y = Q.front().first, x = Q.front().second;
		Q.pop();
		rep(i,4){
			int dy = y+d4y[i], dx = x+d4x[i];
			if(1<=dy && dy<=H && 1<=dx && dx<=W && maze[dy][dx] == '.' && ans[dy][dx] == -1){
				ans[dy][dx] = ans[y][x] + 1;
				Q.push(make_pair(dy, dx));
			}
		}
	}
	int res = ans[H][W];
	if(res==-1){
		cout<<res<<endl;
		return 0;
	}
	cout<<H*W-res-1-b_cnt<<endl;
	return 0;
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

string str;
const int N = 1000005;

int dp[N][2];

int call(int pos,int tp)
{
    if(pos == str.size()){
        if(tp == 0)return 0;
        else return 1e9;
    }
    if(dp[pos][tp] != -1)return dp[pos][tp];
    int ret = 1e9;
    int d = str[pos] - '0';
//    cout << "entering: " << pos << " " << tp << endl;
    if(tp == 0){
        ret = min(ret,d + call(pos + 1,tp));
        if(d < 9)ret = min(ret,d + 1 + call(pos + 1,1 - tp));
    }else{
        int f = 10 - d - 1;
        ret = min(ret,f + call(pos + 1,tp));
        ret = min(ret,f + 1 + call(pos + 1,1 - tp));
    }
//    cout << pos << " " << tp << " " << ret << endl;
    return dp[pos][tp] = ret;
}

int main()
{
    FastRead
    MEM(dp,-1);
    cin >> str;
    REV(str);
    str += "0";
    REV(str);
    cout << call(0,0) << "\n";

}


Measured memory_bytes: 71708
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  long K;
  cin >> K;
  
  vl arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << arr[K-1] << endl;
  
  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 vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  ll MOD = 1000000007;
  ll n;
  cin >> n;
  ll sum = 0;
  vl a(n);
  rep(i,n){
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
  }
  ll ans = 0;
  rep(i,n){
    ll tasu = a[i] * (sum-a[i]);
    ans += tasu;
    ans %= MOD;
  }
  ans += MOD;
  cout << ans * modinv(2, MOD) % MOD << endl;
}


Measured memory_bytes: 4840
#include <stdio.h>

int main(void)
{
	char S[3], T[3];

	scanf("%s", S);
	scanf("%s", T);

	int i;
	int cnt = 0;

	for (i = 0; i < 3; i++) {
		if (S[i] == T[i])
			cnt++;
	}

	printf("%d", cnt);

	return 0;
}

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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007

int main() {
	int a, b, k;
	cin >> k >> a >> b;
	int m = a % k;
	if (m == 0) cout << "OK" << endl;
	else {
		if ((a / k) * k + k <= b) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  if (n % 111 == 0) {
    printf("%d", n);
  }
  else {
    int NextNum = n - (n % 111) + 111;
    printf("%d", NextNum);
  }
  
  return 0;
}

Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;

#pragma endregion

struct edge {
	int from, to, cost;
};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/
signed main(void) {
	st s;
	cin >> s;
	int one = 0, zero = 0;
	f(i, 0, size(s)) {
		if (s[i] == '0') {
			zero++;
		}
		if (s[i] == '1') {
			one++;
		}
	}
	cout << 2 * min(zero, one);
	return 0;
}

Measured memory_bytes: 512
import sys
import math
input = sys.stdin.readline

N, M = map(int, input().split())

def f(n):
    r = 1
    for i in range(1, n + 1):
        r = r * i % (10 ** 9 + 7)
        
    return r
    
if N == M:
    print(f(N) * f(M) * 2 % (10 ** 9 + 7))
elif abs(N - M) == 1:
    print(f(N) * f(M) % (10 ** 9 + 7))
else:
    print(0)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int h,w;
	int i,j;
	char map[101][101];
	int flg[101][101];
	
	scanf("%d %d",&h,&w);
	while(h!=0 && w!=0){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				flg[i][j]=0;
			}
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				scanf(" %c",&map[i][j]);
			}
		}
		i=0;
		j=0;
		while(1){
			if(map[i][j]=='.' || flg[i][j]==1){
				break;
			}
			else if(map[i][j]=='>'){
				flg[i][j]=1;
				j++;
			}
			else if(map[i][j]=='<'){
				flg[i][j]=1;
				j--;
			}
			else if(map[i][j]=='^'){
				flg[i][j]=1;
				i--;
			}
			else if(map[i][j]=='v'){
				flg[i][j]=1;
				i++;
			}
		}
		if(flg[i][j]==1){
			printf("LOOP\n");
		}
		else {
			printf("%d %d\n",j,i);
		}
		scanf("%d %d",&h,&w);
	}
	return 0;
}

Measured memory_bytes: 1092
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)4e5+100;
    const int inf=(int)1e9+100;
#define filename ""
    ll mod=(ll)1e9+7;
ll stup(ll x,ll m)
{
    ll o=1;
    while(m)
    {
        if (m&1)
        {
            o*=x;
            o%=mod;
        }
        x*=x;
        x%=mod;
        m>>=1;
    }
    re o;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n,i;
    cin>>n;
    vector<ll> a(n);
    fo(i,n)
    {
        cin>>a[i];
    }
    sort(all(a));
    ll ans=a[n-1]*stup(4,n-1)%mod*2%mod;
    fo(i,n-1)
    {
        ll x=n-i;
        ans+=stup(2,x-2)*(x+1)%mod*a[i]%mod*stup(2,x)%mod*stup(4,i)%mod;
        ans%=mod;
    }
    cout<<ans;
}


Measured memory_bytes: 1792
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def COM(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

mod = 10**9+7

X, Y = map(int,input().split())

a = X%2 #1の数
b = X//2 #2の数
for i in range(b+1):
    if a*2 + b*1 == Y:
        break
    a += 2
    b -= 1

if a*2 + b*1 != Y:
    print(0)
else:
    max = a+b+1
    fac = [0] * max
    finv = [0] * max
    inv = [0] * max
    COMinit()
    print(COM(a+b,a))


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

int A[30] = {0};

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++) {
    int K = 0;
    scanf("%d", &K);
    for (int j = 0; j < K; j++) {
      int l = 0;
      scanf("%d", &l);
      A[l - 1]++;
    }
  }

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

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [isize; n],
    }

    let b = *a.iter().max().unwrap();

    let mut c = 0;
    let mut dist = b + 1;
    for e in &a {
        let tmp = min((b / 2 - *e).abs(), (b / 2 + b % 2 - *e).abs());
        if tmp < dist && *e != b {
            dist = tmp;
            c = *e;
        }
    }

    println!("{} {}", b, c);
}


Measured memory_bytes: 3708
Scanf.scanf "%d %d\n" (fun n t->
  let rec loop i c=
    if i=n then c else
    let c = Scanf.scanf "%d %d\n" (fun c1 t1 ->
            if t1<=t && c1<=c then c1 else c
    ) in
    loop (i+1) c
  in
  let a = loop 0 500000 in
  if a=500000 then Printf.printf "TLE\n" else Printf.printf "%d\n" a

)


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<string>S(N);
  for(int i=0;i<N;i++)cin>>S[i];
  long ans=0;
  for(int i=0;i<N;i++){
    bool a=true;
    for(int j=0;j<N;j++)for(int k=0;k<N;k++){
      a*=(S[(j+i)%N][k]==S[(k+i)%N][j]);
    }
    if(a)ans+=N;
  }
  cout<<ans;
}

Measured memory_bytes: 384
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/23.
//  Copyright © 2019 yuya. All rights reserved.
//

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



int main()
{
    int i;
    
    int j;
    int k;
    int cnt;
    int flag  = 1;
    int N;
    int x,y,h;
    int x0,y0,h0;
    int xr=0,xl=100,ya=0,yb=100;
    cin >> N;
    vector<pair<pair<int,int>,int>> data(N);
    for(i=0;i<N;i++){
        cin >> x >> y >> h;
        if(flag && h!=0){
            x0 = x;
            y0 = y;
            h0 = h;
            flag = 0;
        }
        data[i] = pair<pair<int,int>,int> (pair<int,int>(x,y),h);
        xr = max(xr,x);
        xl = min(xl,x);
        ya = max(ya,y);
        yb = min(yb,y);
    }
    
    for(i=0;i<=100;i++){
        for(j=0;j<=100;j++){
            h = h0 + abs(i-x0) + abs(j-y0);
            cnt = 0;
            
            for(k=0;k<N;k++){
                if(data[k].second != max(0, h - abs(i-data[k].first.first) - abs(j-data[k].first.second)) ) {
                    break;
                } else {
                    cnt++;
                }
            }
            if(cnt == N) {
                cout << i << " " << j << " " << h << endl;
                return 0;
            }
        }
    }
    
    
    return 0;
}


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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

int main(void)
{
  ll h, n;
  cin >> h >> n;
  vector<ll> A(n);
  ll sum = 0;
  rep(i, n)
  {
    cin >> A[i];
    sum += A[i];
  }
  if (sum >= h)
  {
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    rep(i, 0, N){
        int x;
        cin >> x;
        if(x % 2 == 0){
            if (x % 3 != 0 && x % 5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) {
	  return gcd(b, a);
	}
  if (b == 0) {
	  return a;
	}
  return gcd(b, a % b);
}

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long l = c * d / gcd(c, d);
  a--;
  long long ans = b - b / c - b / d + b / l;
  ans -= a - a / c - a / d + a / l;
  cout << ans << endl;
  return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i,M) {
        int a, b; cin >> a >> b;
        a--, b--;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }

    vector<int> MS(N,-1); // MileStone
    queue<int> Q;
    Q.emplace(0);
    while (!Q.empty()) {
        int c = Q.front(); Q.pop();
        for (auto x : G[c]) {
            if (MS[x] == -1) {
                MS[x] = c;
                Q.emplace(x);
            }
        }
    }
    rep(i,N) if (MS[i] == -1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << MS[i] + 1 << endl;
    }
}


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

int main(){
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if( 0<=(x-r) && (x-r)<=(w-2*r) ){
		if( 0<=(y-r) && (y-r)<=(h-2*r) ){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) (a).begin(), (a).end()

ll Sqrt(ll x,ll st){
	ll ok = 0, ng = st + 2;
	while(ng - ok > 1){
		ll mi = (ok + ng)/2;
		if(x < mi * mi){
			ng = mi;
		}
		else{
			ok = mi;
		}
	}
	return ok;
}

ll solve(){
	ll a,b;
	cin >> a >> b;
	if (a > b){
		swap(a, b);
	}
	ll k = Sqrt(a * b - 1, b), ans = k * 2;
	if (a == b){
		return ans;
	}
	if (k * (k + 1) >= a * b){
		ans--;
	}
	ans--;
	return max((ll)0, ans);
}

int main(){
	int q;
	cin >> q;
	vector<ll> ans(q);
	rip(i,q,0){
		ans[i] = solve();
	}
	rip(i, q, 0){
		printf("%lld\n", ans[i]);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <numeric>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;


int main() {
	int n;
	cin >> n;
	VI v(n);
	REP(i, n) { cin >> v[i]; }

	map<int, int> m1;
	map<int, int> m2;

	REP(i, v.size()) {
		int t = v[i];
		if (i % 2 == 1) {
			if (m1.find(t) == m1.end()) {
				m1[t] = 1;
			} else {
				++m1[t];
			}
		} else {
			if (m2.find(t) == m2.end()) {
				m2[t] = 1;
			} else {
				++m2[t];
			}
		}
	}

	vector<PAIR> p1;
	vector<PAIR> p2;
	REPC(x, m1) {
		p1.emplace_back(x.first, x.second);
	}
	REPC(x, m2) {
		p2.emplace_back(x.first, x.second);
	}

	sort(ALL(p1), [](const auto& a,const auto& b) {
		return a.second > b.second;
	});
	sort(ALL(p2), [](const auto& a, const auto& b) {
		return a.second > b.second;
	});

	auto itr1 = p1.begin();
	auto itr2 = p2.begin();

	if ((*itr1).first == (*itr2).first) {
		if (p1.size() == 1 || p2.size() == 1) {
			if (p1.size() != 1) {
				cout << n / 2 + (*itr2).second << endl;
			} else if (p2.size() != 1) {
				cout << n / 2 + (*itr1).second << endl;
			} else {
				cout << n / 2 << endl;
			}
			return 0;
		}
		++itr1;
		int a = n - ((*itr1).second + (*itr2).second);
		--itr1; ++itr2;
		int b = n - ((*itr1).second + (*itr2).second);
		//cout << a << " " << b << endl;
		cout << ((a < b) ? a : b) << endl;
	} else {
		//cout << (*itr1).first << " " << (*itr2).first << endl;
		cout << n - ((*itr1).second + (*itr2).second) << endl;
	}

}

Measured memory_bytes: 6520
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb push_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e6+5;
char s[N];int n,k;
inline void print(R char *s){s[n]='\0',printf("%s\n",s);}
void solve(R int p){
	R int i=1;
	while(p--){
		R int op=(i<=n?((i-1)&1):((n-1)&1));
//		printf("%d %d %c\n",i,op,s[i]);
		if((s[i]=='A')^op){s[i]=(s[i]=='A'?'B':'A');continue;}
		s[i+n]='A',++i;
	}
	R int op=(i<=n?((i-1)&1):((n-1)&1));
//		printf("%d %d %c\n",i,op,s[i]);
	fp(k,i,i+n-2){
		if(op)s[k]=(s[k]=='A'?'B':'A');
		if(k+1>n)op^=1;
	}
	s[i+n-1]='A';
	print(s+i);
}
void ss(R int p){
	R int i=1;
	while(p--){
		R int op=(i<=n?((i-1)&1):((n-1)&1));
//		printf("%d %d %c\n",i,op,s[i]);
		if((s[i]=='A')^op){s[i]=(s[i]=='A'?'B':'A');continue;}
		s[i+n]='A',++i;
	}
	k-=p;
	if(n&1^1){
		fp(i,1,n)s[i]=((i&1)?'B':'A');
		print(s+1);
		return;
	}
	R int op=(i<=n?((i-1)&1):((n-1)&1));
	if(!((s[i]=='A')^op))--k;
	s[n]=(k&1?'A':'B');
	fp(i,1,n-1)s[i]=((i&1)?'A':'B');
	reverse(s+1,s+1+n);
	print(s+1);
}
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	if(k<=1e6)return solve(k),0;
//	assert(false);
	ss(1e6);
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200010;

struct Edge{ int to, next;} edge[N];
int head[N], num, p[N];
void add_edge(int a, int b) { edge[++ num] = (Edge){b, head[a]}, head[a] = num;}
int sg[N];
vector<int> h;
void dfs(int x)
{
	//printf("%d\n", x);
	RepG(i, x) dfs(v);
	RepG(i, x) h.push_back(sg[v]);
	h.push_back(1e9);
	sort(h.begin(), h.end());
	Rep0(i, h.size() - 1) if (h[i] != i) { sg[x] = i; break;}
	h.clear();
}

bool vis[N];
int main()
{
	int n, t;
	scanf("%d", &n);
	Rep(i, n) scanf("%d", &p[i]);
	
	t = 1;
	while (!vis[t]) vis[t] = true, t = p[t];
	//printf("%d\n", t);
	Rep(i, n) if (i != t) add_edge(p[i], i);
	
	dfs(t);
	
	if (sg[t] != sg[p[t]]) printf("POSSIBLE\n");
	else {
		int x = p[t];
		add_edge(p[t], t);
		int tmpt = sg[t];
		while (true) {
			RepG(i, x) h.push_back(sg[v]);
			h.push_back(1e9);
			sort(h.begin(), h.end());
			Rep0(i, h.size() - 1) if (h[i] != i) { sg[x] = i; break;}
			h.clear();
			if (x == t) break;
			x = p[x];
		}
		int tmp;
		RepG(i, x) h.push_back(p[t]);
		h.push_back(1e9);
		sort(h.begin(), h.end());
		Rep0(i, h.size() - 1) if (h[i] != i) { tmp = i; break;} 
		if (sg[t] == tmpt) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n, k;
	string s;
	cin >> n >> k >> s;
	int str = 1;
	vi per;

	if (s[0] == '0')per.push_back(0);
	rep(i, n - 1) {
		if (s[i] == s[i + 1])str++;
		else {
			per.push_back(str);
			str = 1;
		}
	}
	per.push_back(str);
	if (s[n - 1] == '0')per.push_back(0);

	int m = per.size();
	if (m == 1) {
		cout << per[0] << endl;
		return 0;
	}
	vi sum(m + 1);
	rep(i, m)sum[i + 1] = sum[i] + per[i];
	
	int ans = 1;
	rep(i, m / 2) {
		ans = max(ans, sum[min(2 * i + 2 * (k - 1) + 3, m)] - sum[2 * i]);
	}
	cout << ans << endl;

}

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

inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
} 

int n, m, temp, maxv=0;
int a[200001];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout); 
	
	cin >> n >> m;
	for(int i=1; i<=m; i++){
		cin >> a[i];	
	}
	sort(a+1, a+m+1);
	
	for(int i=1; i<m; i++){
		temp=a[i+1]-a[i];
		if(temp>maxv){
			maxv=temp;
		}
	}

	temp=n-a[m]+a[1];
	if(temp>maxv){
		maxv=temp;
	}
	
	cout << n-maxv;
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a <= b){
            for(int i = 0; i < b; i++){
                System.out.print(a);
            }
        }else if(a > b){
            for(int i = 0; i < a; i++){
                System.out.print(b);
            }
        }
    }
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n, m; cin >> n >> m;
        int x = 0, y = n;
        while (m--) {
                int a, b; cin >> a >> b;
                x = max(x, a);
                y = min(y, b);
        }

        cout << max(0, y - x + 1);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3620
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 2e5 + 3;
typedef bitset < maxN > bs;
bs T[26];
bs S[26];
int p[26];
bs nS[26];
int prv[26];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    map < int, int > mp;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        mp[x]++;
    }
    ll best = 0;
    int lst = 0;
    for (auto it : mp) {
        if (it.second >= 4) best = max(best, 1LL * it.first * it.first);
        if (it.second >= 2) {
            best = max(best, 1LL * it.first * lst);
            lst = max(lst, it.first);
        }
    }
    cout << best;
    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector <int> WA(n, 0);
    vector <bool> AC(n, false);

    int a = 0, b = 0;
    
    for(int i = 0; i < m; i++) {
        int x; cin >> x;
        string ans; cin >> ans;
        
        if(AC[x-1]) continue;

        if(ans == "AC") {
            AC[x-1] = true;
            a++;
            b += WA[x-1];
        }else{
            WA[x-1]++;
        }
    }

    cout << a << " " << b << endl;
    return 0;
}


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

#define int long long int

const int M = 998244353;

int power(int x, int y) {
    if(y == 0)
        return 1ll;
    if(y % 2)
        return x * power(x, y - 1);
    int t = power(x, y / 2);
    return t * t;
}

signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0) {
        c -= b;
        if(c <= 0) {
            cout << "Yes";
            break;
        }
        a -= d;
        if(a <= 0) {
            cout << "No";
            break;
        }
    }
}


Measured memory_bytes: 3636
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(i,n) for(long long i = 0;i < n;++i)
long long ans[200000] = {};
vector<int> sosuu;
int sosuu_grid[200000];
int main() {
#define int long long
	for (int i = 2; i <= 100000; ++i) {
		ans[i] += ans[i - 1];
		int geko = 1;
		for (int q = 2; q <= sqrt(i); ++q) {
			if (i % q == 0) {
				geko *= q;
				if (i / q != q) {
					geko *= i/q;
				}
				if (geko >= 2 * i) break;
			}
		}
		if (geko >= 2 * i) {
			ans[i]++;
		}
	}
	int query;
	cin >> query;
	REP(i, query) {
		int a;
		cin >> a;
		cout << ans[a] << endl;
	}
	return 0;
}


Measured memory_bytes: 3888
n,m = map(int, input().split())
h = list(map(int, input().split()))
gd = [1]*n
for i in range(m):
  a,b = map(int, input().split())
  if h[a-1] >= h[b-1]:
    gd[b-1] = 0
  if h[a-1] <= h[b-1]:
    gd[a-1] = 0
cnt = 0
for i in gd:
  cnt += i
print(cnt)

Measured memory_bytes: 19944
import sys
import bisect

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
INF = 10 ** 10
dp = [INF] * N
# マイナスの値にしてLongest Increasing Sequence
for _ in range(N):
    a = 10 ** 9 - ir()
    i = bisect.bisect_right(dp, a)
    dp[i] = a

index = bisect.bisect_left(dp, INF)
print(index)
# 04

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

using namespace std;

//#define FILE_IO

int N, C, K;
int v[100005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &C, &K);
    for(int i = 1; i <= N; i++)
        scanf("%d", &v[i]);
    sort(v + 1, v + N + 1);
    int ans = 0;
    for(int i = 1; i <= N; i++)
    {
        int t = v[i] + K;
        int dr = i + 1;
        while(dr - i + 1 <= C && dr <= N && v[dr] <= t)
            dr++;
        dr--;
        ans++;
        i = dr;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int h,n;
  cin >>h>>n;
  vector<int> a(n);
  int sum=0;
  for(int i=0; i<n; i++){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  if(sum<h) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

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

int main(){
  ll n; cin >> n;
  vector<string> m(0);
  vector<string> a(0);
  vector<string> r(0);
  vector<string> c(0);
  vector<string> h(0);
  for(int i = 0; i < n; i++){
    string k;
    cin >> k;
    if(k[0] == 'M'){m.push_back(k);}
    else if(k[0] == 'A'){a.push_back(k);}
    else if(k[0] == 'R'){r.push_back(k);}
    else if(k[0] == 'C'){c.push_back(k);}
    else if(k[0] == 'H'){h.push_back(k);}
  }
  ll mm = m.size();
  ll aa = a.size();
  ll rr = r.size();
  ll cc = c.size();
  ll hh = h.size();
  ll ans = mm * (aa * (rr + cc + hh)) + mm * (rr * (cc + hh) + cc * hh);
  ans += aa * rr * (cc + hh) + cc * hh * (aa + rr);

  cout << ans << endl;
}

Measured memory_bytes: 5748
N = gets.chop.to_i;
D = gets.chop.split.map(&:to_i)
M = gets.chop.to_i;
T = gets.chop.split.map(&:to_i)

if M > N
  puts "NO"
  exit
end

h = Hash.new

for i in D
  if h.has_key?(i)
    h.store(i, h.fetch(i) + 1)
  else
    h.store(i, 1)
  end
end

for i in T
  if h.has_key?(i) == false
    puts "NO"
    exit
  else
    if h.fetch(i) == 0
      puts "NO"
      exit
    else
      h.store(i, h.fetch(i) - 1)
    end
  end
end

puts "YES"

Measured memory_bytes: 45844