akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int N, M; cin >> N >> M;
	vector<int> s(M), c(M); rep(i, 0, M)cin >> s[i] >> c[i];
	if (N == 1) {
		if (M == 0)cout << 0 << endl;
		else {
			bool flag = true;
			rep(i, 0, M) {
				rep(j, 0, M) {
					if (c[i] != c[j])flag = false;
				}
			}
			cout << (flag ? c[0] : -1) << endl;
		}
	}
	else {
		vector<int> d(N, -1);
		int ans;
		bool flag1 = true, flag2 = true;
		rep(i, 0, M) {
			if (d[s[i] - 1] == -1 || d[s[i] - 1] == c[i])d[s[i] - 1] = c[i];
			else flag1 = false;
			if (s[i] == 1 && c[i] == 0)flag2 = false;
		}
		if (flag1 && flag2) {
			ans = max(1, d[0]);
			rep(i, 1, N) {
				ans *= 10;
				ans += max(0, d[i]);
			}
			cout << ans << endl;
		}
		else cout << -1 << endl;
	}

	return 0;
}


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

int main()
{
    int N, S;
    cin>>N>>S;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    long long M = 998244353;
    long long ans = 0;
    vector<long long> T(S);
    T[0] = 1;
    for (int i=0; i<N; i++)
    {
        T[0] = i+1;
        for (int j=S-1; j>=0; j--)
        {
            if (j+A[i]==S)
            {
                ans += T[j]*(N-i);
                ans %= M;
            }
            if (j+A[i]<S)
            {
                T[j+A[i]] += T[j];
                T[j+A[i]] %= M;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
char s[200111];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans=0,cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='S')
		{
			cnt++;
		}
		else
		{
			if(cnt>0)cnt--;
			else ans++;
		}
	}
	cout<<ans+cnt<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx, dy = ty - sy;

  REP(i, dx) cout << "R";
  REP(i, dy) cout << "U";
  REP(i, dx) cout << "L";
  REP(i, dy) cout << "D";
  cout << "D";
  REP(i, dx + 1) cout << "R";
  REP(i, dy + 1) cout << "U";
  cout << "LU";
  REP(i, dx + 1) cout << "L";
  REP(i, dy + 1) cout << "D";
  cout << "R";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<n)
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision(n)
using namespace std;
using PII = pair<int, int>;
using VP = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using ll = long long;
const int INF = 1e9;

bool comp(tuple<string, int, int> &a, tuple<string, int, int> &b)
{
    if (get<0>(a) != get<0>(b)) return get<0>(a) < get<0>(b);
    else return get<1>(a) > get<1>(b);
}

int main()
{
    int N;
    cin >> N;
    vector<tuple<string, int, int>> list(N);
    REP(i, N)
    {
        cin >> get<0>(list.at(i)) >> get<1>(list.at(i));
        get<2>(list.at(i)) = i+1;
    }
    sort(ALL(list), comp);
    REPx(x, list) cout << get<2>(x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

const int MAX_N = (1e+7)+10;
vec nCm(MAX_N+1,0);
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
void makefact(ll n){//MODは素数かつnより大きい
    ll ans = 1;
    fact.at(0) = ans;
    fact_inv.at(0) = ans;
    reps(i,1,n+1){
        (ans *= i)%=MOD;
        fact.at(i) = ans;
        fact_inv.at(i) = fastpow(ans,MOD-2);
    }
    return;
}
void makenCm(ll n){
    rep(i,n+1){
        ll ans = fact.at(n);
        (((ans*=fact_inv.at(n-i))%=MOD)*=fact_inv.at(i))%=MOD;
        nCm.at(i) = ans;
    }
    return;
}

ll ncm(ll n, ll m){
    ll res = fact[n];
    (res *= fact_inv[n - m])%=MOD;
    (res *= fact_inv[m])%=MOD;
    return res;
}

int main() {
    cin>>N>>M;
    makefact(5e+6);
    ll ans = ncm(N + M * 3 - 1, M * 3), temp = 0;
    rep(i, M){
        ll tt = ncm(N + i - 2, i);
        (temp += tt)%=MOD;
    }
    (temp *= N)%=MOD;
    (ans += MOD - temp)%=MOD;
    temp = 0;
    for(ll k = M * 2 - 2; k >= 0 && k >= M * 3 - N; k -= 2){//kは奇数個割り振った後の余り
        ll ball = k / 2, ball2 = M * 3 - k;
        ll tt = ncm(N + ball - 1, ball);
        (tt *= ncm(N, ball2))%=MOD;
        (temp += tt)%=MOD;
    }
    (ans += MOD - temp)%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 234752
a,b,c= map(int,input().rstrip().split())
d,e,f= map(int,input().rstrip().split())
g,h,i= map(int,input().rstrip().split())

mylist=[a,b,c,d,e,f,g,h,i]
num = int(input())

for i in range(num):
    x = int(input())
    k=0
    for j in mylist:
      if j==x:
        mylist[k]=0
      k+=1

x=0
def bingo(a,b,c):
  global x
  if mylist[a]==0 and mylist[b]==0 and mylist[c]==0:
    x=1
      
      
bingo(0,1,2)
bingo(3,4,5)
bingo(6,7,8)
bingo(0,3,6)
bingo(1,4,7)
bingo(2,5,8)
bingo(0,4,8)
bingo(2,4,6)


if x==1:
  print("Yes")
else:
  print("No")
  



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define f first
#define s second
using namespace std;
int t[8][8][8][8][8][8][8][8];
int dx[]={1,-1,4,-4};
void plu(string x,int p){
  t[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]][x[7]]=p;
}
bool ret(string x){
  return t[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]][x[7]];
}
int get(int x[8]){
  return t[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]][x[7]];
}
int main(){
  string v,a,x;
  r(i,8)v+=i;
  queue<pair<string,int> >q;
  plu(v,0);
  q.push(mk(v,0));
  while(!q.empty()){
    pair<string,int>p=q.front();q.pop();
    x=p.f;
    plu(p.f,p.s);
    r(i,8)if(!x[i])r(j,4){
      if(j==0&&i==3)continue;
      if(j==1&&i==4)continue;
      int y=i+dx[j];
      if(y>=0&&y<8){
      a=x;
      swap(a[i],a[y]);
      if(!ret(a)){
        q.push(mk(a,p.s+1));
        plu(a,p.s+1);
      }
      }
    }
  }
  int qq[8];
  while(cin>>qq[0]){
    r(i,7)cin>>qq[i+1];
    cout<<get(qq)<<endl;
  }
}

Measured memory_bytes: 26640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str[40];

void solve(){
	rep(i,n) cin >> str[i];
	rep(i,n){
		int cnt[5] = {5,7,5,7,7};
		for(int j = i; j < n; j++){
			rep(k,5){
				if(cnt[k] != 0){
					cnt[k] -= str[j].size();
					break;
				}
			}
		}
		bool ok = true;
		rep(j,5) if(cnt[j] != 0) ok = false;
		if(ok){
			cout << i+1 << endl;
			break;
		}
	}
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}

Measured memory_bytes: 1208
//In the name of God
#include <bits/stdc++.h>
using namespace std;

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

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second

ll n, dp[maxn][2], a[maxn], x[2], d[2];

int main(){
    fast_io;

    cin >> n >> x[0] >> x[1];
    a[0] = -inf;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[1][0] = 1;
    dp[1][1] = 1;
    for(ll i = 2; i <= n; i++){
        for(ll j = 0; j < 2; j++){
            if(a[i] - a[i - 1] >= x[j]){
                dp[i][j] = (dp[i - 1][j] + dp[i - 1][1 - j]) % mod;
            }
            else{
                ll y = upper_bound(a, a + i, a[i] - x[j]) - a;
                if(d[1 - j] < y){
                    dp[i][j] = dp[y][1 - j];
                }
            }
        }
        if(a[i] - a[i - 1] < x[0]){
            d[0] = i - 1;
        }
        if(a[i] - a[i - 1] < x[1]){
            d[1] = i - 1;
        }
    }
    cout << (dp[n][0] + dp[n][1]) % mod;

    return 0;
}


Measured memory_bytes: 5976
#include <bits/stdc++.h>
 
 
#define ll long long int  
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
 
 
using namespace std;


int mod = (int)1e9 + 7;

long long mMod(long long a, 
                            long long b) 
{ 
    long long res = 0; // Initialize result 
  
    // Update a if it is more than 
    // or equal to mod 
    a %= mod; 
  
    while (b) 
    { 
        // If b is odd, add a with result 
        if (b & 1) 
            res = (res + a) % mod; 
  
        // Here we assume that doing 2*a 
        // doesn't cause overflow 
        a = (2 * a) % mod; 
  
        b >>= 1; // b = b / 2 
    } 
  
    return res; 
}

void util(){
	
	int n;cin>>n;

	long long a[n];

	rep(n)
		cin>>a[i];

	long long ans = 0;


	long long sum = 0;

	for(int i =0;i<n;i++){
		sum  = sum + a[i];
	}


	for(int i=0;i<n-1;i++){
		
		sum -= a[i];

		ans = (ans + mMod(a[i],sum))%mod;

		
	}

	cout<<ans<<endl;

}


int main()
{
	/* code */

	
		util();
	

	return 0;
}

Measured memory_bytes: 5128
//C
#include"bits/stdc++.h"
using namespace std;
#define MOD 1000000007

long long int ppow(long long int i, long long int j) {
	long long int res = 1LL;
	while (j) {
		if ((j & 1LL)) {
			res *= i;
			if (res >= MOD) {
				res %= MOD;
			}
		}
		j >>= 1;
		i *= i;
		if (i >= MOD) {
			i %= MOD;
		}
	}
	return res;
}
long long int gcd(long long int a, long long int b) {
	if (a > b) {
		swap(a, b);
	}
	while (a) {
		swap(a, b);
		a %= b;
	}
	return b;
}
long long int lcm(long long int a, long long int b) {
	return a / gcd(a, b)*b;
}
int h;
int w;
char buf[502];
vector<string> v;
int belong[500 * 500];
inline int root(int b) {
	if (belong[b] == -1)return b;
	return belong[b] = root(belong[b]);
}
long long int siz[500 * 500];
long long int black[500 * 500];
void merge(int a, int b) {
	a = root(a);
	b = root(b);
	if (a == b)return;
	siz[b] += siz[a];
	black[b] += black[a];
	belong[a] = b;
	return;
}
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };
int main() {
	memset(belong, -1, sizeof(belong));
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		scanf("%s", buf);
		v.push_back(buf);
	}
	for (int i = 0; i < h*w; i++)siz[i] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (v[i][j] == '#') {
				black[i*w + j]++;
			}
		}
	}
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			for (int k = 0; k < 4; k++) {
				int x = i + dx[k];
				int y = j + dy[k];
				if (x >= 0 && y >= 0 && x < h&&y < w) {
					if (v[i][j] != v[x][y]) {
						merge(x*w + y, i*w + j);
					}
				}
			}
		}
	}
	long long int ans = 0;
	for (int i = 0; i < h*w; i++) {
		if (root(i) == i) {
			ans += black[i] * (siz[i] - black[i]);
			//ans += black[i] * (black[i] - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    ll s = 0;
    ll a_min = 1000000007;
    int m_cnt = 0;
    rep(i, n){
        ll a;
        cin >> a;
        s += abs(a);
        a_min = min(a_min, abs(a));
        if(a < 0) m_cnt++;
    }
    if(m_cnt % 2 == 0){
        cout << s << endl;
    } else {
        cout << s - 2 * a_min << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
long long Pow(long long base,long long x){
    if (x == 0) return 1;
    if (x%2 == 1) return (base*Pow(base,x-1))%MOD;
    long long y = Pow(base, x/2);
    return y*y%MOD;
}

int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        a[i] = i+1;
    }
    do {
        for(int i = 0; i < n; i++){
            cout << a[i];
            if (i == n-1) cout << endl;
            else cout << ' ';
        } 
    } while (next_permutation(a,a+n));
    return 0;
}
  




Measured memory_bytes: 3112
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e6+4;
const ll MOD=1e9+7;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
ll fac[N<<1]={1,1};
ll inv[N]={1,1};
int n,m;
char s[N];
inline ll fpow(ll a,int b) {
	ll ret=1;
	while (b) {
		if (b&1) ret=ret*a%MOD;
		b>>=1,a=a*a%MOD;
	}
	return ret;
}
inline ll C(int x,int y) {
	ll ans=fac[x];
	ans=ans*inv[y]%MOD;
	ans=ans*inv[x-y]%MOD;
	return ans;
}
int main() {
//	freopen("in.txt","r",stdin);
	for (register int i=1;i<(N<<1);++i) fac[i]=fac[i-1]*i%MOD;
	inv[N-1]=fpow(fac[N-1],MOD-2);
	for(int i=N-2;~i;--i)
	   inv[i]=inv[i+1]*(i+1)%MOD;
	n=read();
	scanf("%s",s);
	m=strlen(s);
	ll ans=0;
	for (register int i=0;i<=n;++i) {
		ll c=fpow(26,i)*fpow(25,n-i)%MOD;
		(ans+=c*C(n+m-i-1,m-1)%MOD)%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 28224
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> cost = new ArrayList<>();
		List<Integer> input = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			input.add(sc.nextInt());
		}
		cost.add(0);
		cost.add(Math.abs(input.get(0) - input.get(1)));
		for (int i = 2; i < n; i++) {
			int cost1 = Math.abs(input.get(i - 1) - input.get(i)) + cost.get(i - 1);
			int cost2 = Math.abs(input.get(i - 2) - input.get(i)) + cost.get(i - 2);
			cost.add(Math.min(cost1, cost2));
		}
		System.out.println(cost.get(n - 1));
	}
}


Measured memory_bytes: 56860
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
using namespace std;
 
template <typename T, class Compare = less<T> >
struct sliding_window {
    deque<pair<int, T> > data;
    function<bool (T const &, T const &)> compare;
    sliding_window(Compare const & a_compare = Compare()) : compare(a_compare) {}
    T front() { return data.front().second; }  // O(1), minimum
    void push_back(int i, T a) { while (not data.empty() and compare(a, data.back().second)) data.pop_back(); data.emplace_back(i, a); }  // O(1) amortized.
    void pop_front(int i) { if (data.front().first == i) data.pop_front(); }
    void push_front(int i, T a) { if (data.empty() or not compare(data.front().second, a)) data.emplace_front(i, a); }
};
 
constexpr int inf = 1e9 + 7;
int main() {
    // input
    int n, k; cin >> n >> k;
    string s, t; cin >> s >> t;
    // solve
    vector<int> delta(n + 1);
    REP (i, n) {
        delta[i + 1] = delta[i] + (i == 0 or t[i - 1] != t[i]);
    }
    vector<int> dp(n + 1, inf);
    sliding_window<int> sw_b, sw_w;
    dp[0] = 0;
    sw_b.push_back(0, 2 * dp[0] - delta[0] + (t[0] == 'B'));
    sw_w.push_back(0, 2 * dp[0] - delta[0] + (t[0] == 'W'));
    REP3 (r, 1, n + 1) {
        if (r - k - 1 >= 0) {
            sw_b.pop_front(r - k - 1);
            sw_w.pop_front(r - k - 1);
        }
        dp[r] = (s[r - 1] == t[r - 1]) ?
            dp[r - 1] :
            ((t[r - 1] == 'W' ? sw_b : sw_w).front() + delta[r]) / 2 + 1;
        if (r < n) {
            sw_b.push_back(r, 2 * dp[r] - delta[r] + (t[r] == 'B'));
            sw_w.push_back(r, 2 * dp[r] - delta[r] + (t[r] == 'W'));
        }
    }
    // output
    cout << dp[n] << endl;
    return 0;
}
 

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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

set<int> st;

int N, k, A[MAXN], ans = 0;
bool flag;

vi enum_div(int n)//nの約数を列挙
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

void solve(){
    vi div1 = enum_div(A[0]);
    vi div2 = enum_div(A[1]);

    for(auto i: div1){
        st.insert(i);
    }

    for(auto i: div2){
        st.insert(i);
    }

    for(auto i: st){
        // cout << i << endl;
        k = 0;
        flag = true;

        rep(j, N){
            if(A[j] % i != 0)
                k++;
            if(k > 1){
                flag = false;
                break;
            }
        }
        if(flag)
            ans = max(ans, i);
    }
    cout << ans << endl;
}


int main(){
    cin >> N;

    rep(i, N){
        cin >> A[i];
    }

    solve();
}


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

using namespace std;

string s, a, b;
int rev;

void add_front(char c) {
    if (rev) {
        b += c;
    } else {
        a += c;
    }
}

void add_back(char c) {
    if (rev) {
        a += c;
    } else {
        b += c;
    }
}

int main() {
    cin >> s;

    int q;
    cin >> q;

    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            rev ^= 1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1)
                add_front(c);
            else
                add_back(c);
        }
    }

    if (rev) {
        reverse(b.begin(), b.end());
        reverse(s.begin(), s.end());
        cout << b + s + a;
    } else {
        reverse(a.begin(), a.end());
        cout << a + s + b;
    }
}


Measured memory_bytes: 1348
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

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

	if (B%A == 0) {
		printf("%d", A + B);
	}
	else {
		printf("%d", B-A);
	}




}

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

const long long INF = 1e18;

long long l;
pair<long long, long long> ans[305][305], sec[305][305];
vector<pair<int, long long>> adj[305];

void solve(int root){

    ans[root][root] = make_pair(0, l);

    priority_queue<vector<long long>> pq;
    pq.push({0, l, root});

    while(!pq.empty()){
        vector<long long> st = pq.top(); pq.pop();
        long long nref, nleft, refu = -st[0], left = st[1];
        int node = st[2];
        for(auto nx : adj[node]){
            nref = refu; nleft = left;
            if(nx.second > nleft){
                ++nref; nleft = l;
            }
            nleft -= nx.second;
            if(make_pair(nref, -nleft) < ans[root][nx.first]){
                sec[root][nx.first] = ans[root][nx.first];
                ans[root][nx.first] = make_pair(nref, -nleft);
                pq.push({-nref, nleft, nx.first});
            } else if(make_pair(nref, -nleft) < sec[root][nx.first]){
                sec[root][nx.first] = make_pair(nref, -nleft);
                pq.push({-nref, nleft, nx.first});
            }
        }
    }

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m, q; cin >> n >> m >> l;

    for(int i = 0; i <= 304; ++i)
        for(int j = 0; j <= 304; ++j)
            ans[i][j] = sec[i][j] = make_pair(INF, INF);

    long long c;

    for(int a, b, i = 0; i < m; ++i){
        cin >> a >> b >> c;
        if(c > l) continue;
        adj[a].push_back(make_pair(b, c));
        adj[b].push_back(make_pair(a, c));
    }

    for(int i = 0; i <= n; ++i)
        solve(i);

    cin >> q;

    for(int s, t, i = 0; i < q; ++i){
        cin >> s >> t;
        if(ans[s][t].first == INF){
            cout << "-1\n"; continue;
        }
        cout << ans[s][t].first << "\n";
    }

    return 0;

}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,tw;
ll dp[105][100005];
vector<ll> a,w;
ll INF = 1e12;
ll rec(int i,int s) {
    // printf("%d %d\n",i,s);
    if(s<0) return -INF; 
    if(i == n) return 0;
    if(dp[i][s]!=-1) return dp[i][s];
    return dp[i][s] = max(rec(i+1,s),a[i] + rec(i+1,s-w[i]));
}

int main() {
    memset(dp,-1,sizeof(dp));
    cin>>n>>tw;
    a.resize(n);
    w.resize(n);
    for(int i =0;i<n;i++) {
        cin>>w[i]>>a[i];
    }
    cout<<rec(0,tw)<<"\n";
}

Measured memory_bytes: 85588
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ns()

n = list(n)

if '7' in n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
N = int(input())

if N % 10 == 3:
  print("bon")
  
elif N % 10 == 0:
  print("pon")
  
elif N % 10 == 1:
  print("pon")

elif N % 10 == 6:
  print("pon")
  
elif N % 10 == 8:
  print("pon")
  
else:
  print("hon")
    

Measured memory_bytes: 61760
/* ****revpro**** */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

ll dp[4][1000];
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		rep(i,0,n){
			char x;
			cin>>x;
			int t=x-'0';
			rep(j,0,100) dp[3][10*j+t]=dp[3][10*j+t]|dp[2][j];
			rep(j,0,10) dp[2][10*j+t]=dp[2][10*j+t]|dp[1][j];
			dp[1][t]=1; 
		}
		ll cnt=0;
		rep(i,0,1000) cnt+=dp[3][i];
		cout<<cnt;
	}
	return 0;
}

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

int main(){
  int N,M; cin >> N >> M;
  int A[N], sum = 0,c = 0;
  double judge = (double)1/(double)(4 * M);
  //cout << "judge = " << judge << endl;

  rep(i,N){
    cin >> A[i];
    sum += A[i];
  }
  judge = sum * judge;
  //cout << "judge = " << judge << endl;
  rep(i,N){
    if(judge <= A[i] && c != M){
      c++;
    }
  }
  if(c != M) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
using pint=pair<ll,ll>;

int main(){

    ll n;
    cin >> n;
    vector<ll> data(n);
    rep(i,n) cin >> data.at(i);

    vector<ll> odd_num(101010,0),even_num(101010,0);
    rep(i,n){
        if(i%2==0) odd_num[data.at(i)]++;
        else even_num[data.at(i)]++;
    }

    vector<pint> odd,even;
    rep(i,101010){
        odd.push_back(pint(odd_num[i],i));
        even.push_back(pint(even_num[i],i));
       
    }

    sort(odd.begin(),odd.end(),greater<pint>());
    sort(even.begin(),even.end(),greater<pint>());

    if(odd.at(0).second!=even.at(0).second){
        cout << n-(odd.at(0).first)-(even.at(0).first) << endl;
    }
    else{
        cout << n-max((odd.at(0).first)+(even.at(1).first),(even.at(0).first)+(odd.at(1).first)) << endl;
    }
    
 
}

Measured memory_bytes: 5988
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
#define mp make_pair

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=2e5+10;

int main(){
	int N,K;
	cin>>N>>K;
	int mx=((N-1)*(N-2))/2;
	if(K>mx)cout<<-1;
	else{
		vector<P> ans;
		rep1(i,N-1)ans.push_back(mp(i, N));
		int rm=mx-K;
		rep1(i,N-1)rep1(j,N-1)if(i<j)if(rm>0){
			ans.push_back(mp(i,j));
			rm--;
		}
		
		cout<<sz(ans)<<endl;
		rep(i,sz(ans)){
			cout<<ans[i].first<<" "<<ans[i].second<<endl;
		}
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int MN = 100010;

int color[MN];
int from[MN], to[MN];
vector<int> g[MN];

void dfs(int u, int par, int prv) {
	int c = 1;
	for (int e : g[u]) {
		int v = from[e] + to[e] - u;
		if (v == par) continue;
		if (c == prv) c++;
		dfs(v, u, c);
		color[e] = c++;
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> from[i] >> to[i];
		from[i]--; to[i]--;
		g[from[i]].push_back(i);
		g[to[i]].push_back(i);
	}
	dfs(0, -1, -1);
	int k = *max_element(color, color + n - 1);
	cout << k << endl;
	for (int i = 0; i < n - 1; i++)
		cout << color[i] << endl;
	return 0;
}


Measured memory_bytes: 9728
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        long n = in.l();
        long s = in.l();
        int m = (int)Math.sqrt(n);

        long ans = Long.MAX_VALUE;
        for (int b = 2; b <= m; b++) {
            long t = 0;
            long a = n;

            while (a > 0) {
                t += a % b;
                a /= b;
            }

            if (s == t) {
                ans = b;
                break;
            }
        }

        if (ans == Long.MAX_VALUE) {
            ans = -1;
            if (n == s) {
                ans = s + 1;
            } else if (s < n) {
                long d = n - s;
                for (int i = (int)Math.min(s, m); i >= 1 ; i--) {
                    if (d % i == 0) {
                        long j = s - i;
                        long b = d / i + 1;
                        if (Math.max(m, j) < b && d % i == 0) {
                            ans = b;
                            break;
                        }
                    }
                }
            }
        }

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32872
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	n, a, b, c, d := oneInt(), oneInt(), oneInt(), oneInt(), oneInt()
	str := oneStr()

	ans := calc(n, a, b, c, d, str)

	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func calc(n, a, b, c, d int, str string) bool {
	// 人を飛び越える必要がある
	needJump := false
	if c > d {
		needJump = true
	}

	canJump := false

	var before rune
	cntSpace := 0
	for i, r := range str {
		switch r {
		case '.':
			cntSpace++
			//if cntSpace >= 3 {
			//	fmt.Println(i)
			//}
			if cntSpace >= 3 && b <= i && i <= min(c, d) {
				canJump = true
			}
		case '#':

			cntSpace = 0

			if before == '#' {
				if (max(a, c) < i && (max(b, d) < i || i+1 < min(b, d))) || (i+1 < min(a, c) && (i+1 < min(b, d) || max(b, d) < i)) {

				} else {
					return false
				}
			}

		}
		before = r
	}

	if needJump && canJump {
		return true
	}

	if !needJump {
		return true
	}

	return false
}

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

func oneStr() string {
	sc.Scan()
	return sc.Text()
}

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

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

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

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

bool loop_s(string s){
  REP(i,(s.size()+1)/2){
    if(s[i] != s[s.size()-1-i]) return false;
  }
  return true;
}

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

  string res = "No";
  if(loop_s(s)
  && loop_s(s.substr(0,(s.size()-1)/2))
  && loop_s(s.substr((s.size()+1)/2))
  ){
    res = "Yes";
  }

  cout << res << "\n";
  return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

string a,b;
bool get_input(){
    cin >> a;
    if(a == ".") return false;
    cin >> b;
    return true;
}

string pre_do(string &s,vector<string> &vs){
    string ret;
    int sz = s.size();
    int quot = 0;

    string ss;
    _for(i,0,sz){
        if(quot == 0 && s[i] != '"'){
            ret.push_back(s[i]);
        }
        else if(quot == 0 && s[i] == '"'){
            quot++;
            ret.PB(' ');
        }
        else if(quot == 1 && s[i] == '"'){
            quot = 0;
            vs.PB(ss);
            ss.clear();
            ret.PB(' ');
        }
        else if(quot == 1 && s[i] != '"'){
            ss.PB(s[i]);
        }
    }

    return ret;

}

int main()
{
    while(get_input()){
        vector<string> A;
        vector<string> B;
        string s1 = pre_do(a,A);
        string s2 = pre_do(b,B);
        if(s1 != s2 || A.size() != B.size()){
            cout << "DIFFERENT" << endl;
        }
        else{
            int cnt = 0;
            _for(i,0,A.size()){
                if(A[i] != B[i]) cnt++;
            }

            if(cnt >= 2) cout << "DIFFERENT" << endl;
            else if(cnt == 1) cout << "CLOSE" << endl;
            else cout << "IDENTICAL" << endl;
        }

    }
    return 0;
}



Measured memory_bytes: 3220
#include<stdio.h>

int main(void)
{
	char s[11];
	char ans[11];
	int i,j;
	
	scanf("%s",s);
	
	for(i=0; i<11; i++){
		ans[i] = '\0';
	}
	
	i=0;
	j=0;
	while(1){
		
		if(s[i] == '0'){
			ans[j] = '0';
			j++;
		}else if(s[i] == '1'){
			ans[j] = '1';
			j++;
		}else if(s[i] == 'B'){
			ans[j] = '\0';
			j--;
			if( j <= 0){
				 j=0;
			}
		}else if(s[i] == '\0'){
			ans[j] = '\0';
			break;
		}
		i++;
		
	}
	
	for(i=0; i < j ;i++) printf("%c",ans[i]);
	
	printf("\n");
	
	return 0;
	
}

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

multiset<int> edge[100005],redge[100005];
vector<int> order;
int ans[100005];

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int a,b;
	for (int i = 0; i < n+m-1; ++i)
	{
		cin>>a>>b;
		edge[a].insert(b);
		redge[b].insert(a);
	}
	for (int i = 1; i <= n; ++i)
	{
		if (redge[i].size()==0)
		{
			redge[i].insert(0);
			edge[0].insert(i);
			break;
		}
	}
	queue<int> que;
	que.push(0);
	while (que.size()>0)
	{
		int now=que.front();que.pop();
		for (auto v:edge[now])
		{
			redge[v].erase(now);
			if (redge[v].size()==0)
			{
				que.push(v);
				ans[v]=now;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 20352
def yakusu(n):
        result = []
        for i in range(1,int(n**0.5)+1):
                if n % i == 0:
                        result.append(i)
                        if i != n // i:
                                result.append(n//i)
        result.sort()
        return result
yakusu = yakusu(int(input()))
m = len(yakusu)
if m % 2 ==0:
        print(yakusu[m//2-1]+yakusu[m//2+1-1]-2)
else:
        print((yakusu[m//2]-1)*2)

Measured memory_bytes: 3268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

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

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

using namespace std;

typedef long long int Int;

int main(void)
{
    string s;
    Int count = 0;
    cin>>s;

    for(int i = 0;i < s.size()-1;i++)
    {
	if(s[i] != s[i+1]) {
	    count++;
	}
    }

    cout<<count<<endl;

    return 0;
}


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

map<int,bool>check;

int main(){
  int n,m,ans=0;
  cin>>n;
  for(int i=0,a;i<n;i++){
    cin>>a;
    check[a]=true;
  }
  cin>>m;
  for(int i=0,a;i<m;i++){
    cin>>a;
    if(check[a])ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e7 + 5;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'

int p[MAXN], ok[MAXN];
void init(int n){
    for(int i = 2; i < n; i++){
        if(!ok[i]) p[++*p] = i;
        for(int j = 1; j <= *p; j++){
            if(i * p[j] >= n) break;
            ok[i*p[j]] = p[j];
            if(i % p[j] == 0) break;
        }
    }
}
void run(){
    int n; cin >> n; init(n + 1);
    ll ans = 0, tmp, cnt;
    int last, x;
    for(int i = 2; i <= n; i++){
        if(!ok[i]){ ans += i * 2; continue; }
        x = i, cnt = 1, last = 0, tmp = 1;
        while(ok[x]){
            if(ok[x] == last) cnt++;
            else if(last) tmp *= cnt + 1, cnt = 1;
            last = ok[x], x /= ok[x];
        }
        if(x > 1){
            if(x == last) tmp *= cnt + 2;
            else tmp *= (cnt + 1) * 2;
        }
        else tmp *= cnt + 1;
//        DEBUG(tmp);
        ans += tmp * i;
    }
    cout << ans + 1;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
//    ios::sync_with_stdio(false);

    run();
}


Measured memory_bytes: 45196
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

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

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

using namespace std;

class B {
	string s, t;
	int n;
public:
	B()
	{
		cin >> s >> t;
		n = SZ(s);
	}

	string rotate(const string& s, const int d)
	{
		string ret;
		ret.resize(n);

		REP(i, n)
		{
			if (i + d >= n)
			{
				ret[i + d - n] = s[i];
			}
			else
			{
				ret[i + d] = s[i];
			}
		}

		return ret;
	}
	void solve()
	{
		bool flag{ false };
		REP(d, n)
		{
			if (t == rotate(s, d))
			{
				flag = true;
				break;
			}
		}

		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())

    def sieve(n):
        prime=[]
        limit=n**0.5
        data=[i+1 for i in range(1,n)]
        while True:
            p=data[0]
            if limit<=p:
                return prime+data
            prime.append(p)
            data=[e for e in data if e%p!=0]
    
    primes=sieve(n+1)
    cnt=0
    for num in range(1,n+1,2):
        cnt_factor=1
        for p in primes:
            c=0
            while num%p==0:
                num//=p
                c+=1
            if c!=0:
                cnt_factor*=(c+1)
        if cnt_factor==8:
            cnt+=1
    print(cnt)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001 // n????????§???
#define VMAX 10000 // ??????????????°???C[i]????????§?????°

int main(){
	unsigned short *A, *B; // 2????????????????????´??°

	int C[VMAX+1];
	int n, i, j;
	scanf("%d",&n);

	A = (unsigned short *)malloc(sizeof(short) * n + 1); // short?????????????????°*n+1??????????????°??????????????????????????????
	B = (unsigned short *)malloc(sizeof(short) * n + 1);

	for(i=0;i<=VMAX;i++) C[i] = 0; //?????????????????¢??°????????????

	for(i=0;i<n;i++){
		scanf("%hu",&A[i+1]); // 1?????????????????????
		C[A[i+1]]++; // ??????????????°???????????£????????\?????°????????????????????´??°???????????????????????°??????
	}

	for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1]; // ??\?????°????????????i??\????????´??°???C[i]???????????????

	for(j=1;j<=n;j++){
		B[C[A[j]]] = A[j]; // ??\?????°???????????????A[j]???????°?????????´??°???C[A[j]]??????????????????????????§?????????????????????B[C[A[j]]]????????????A[j]?????\???
		C[A[j]]--; // A[j]??????????????????????????°???????????????
	}

	for(i=1;i<=n;i++){
		if(i>1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 10452
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){

int n,i;
double sum1=0,sum2=0,sum3,max=0,ans[4];

scanf("%d",&n);
double x[n],y[n];
for(i=0;i<n;i++)
     scanf("%lf",&x[i]);
for(i=0;i<n;i++)
 scanf("%lf",&y[i]);
for(i=0;i<n;i++){

    sum1+=abs(x[i]-y[i]);
    if(abs(x[i]-y[i])>max)
        max=abs(x[i]-y[i]);

    sum2+=pow(abs(x[i]-y[i]),2);
    sum3+=pow(abs(x[i]-y[i]),3);

}


printf("%lf\n",sum1);
printf("%lf\n",sqrt(sum2));
printf("%lf\n",cbrt(sum3));
printf("%lf\n",max);

}




Measured memory_bytes: 2100
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int x[100010];
int w[100010];
int y[100010];
int n,l,t;
int x1[100010];
int x2[100010];
int x3[100010];
int x4[100010];
int t1=0,t2=0,t3=0,t4=0;
void rd(int &s)
{
	int c;
	while((c=getchar())<'0'||c>'9');
	s=c-'0';
	while((c=getchar())>='0'&&c<='9')
		s=s*10+c-'0';
}
int main()
{
#ifdef DEBUG
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	scanf("%d%d%d",&n,&l,&t);
	int len=t%l;
	int i;
	int c=0;
	for(i=1;i<=n;i++)
	{
		rd(x[i]);
		rd(w[i]);
		if(w[i]==1)
		{
			c+=(t+x[i])/l;
			y[i]=(x[i]+len)%l;
			if(y[i]>=len)
				x3[++t3]=y[i];
			else
				x1[++t1]=y[i];
		}
		else
		{
			c-=(t-x[i]+l-1)/l;
			y[i]=(x[i]-len+l)%l;
			if(y[i]>=l-len)
				x4[++t4]=y[i];
			else
				x2[++t2]=y[i];
		}
		c%=n;
	}
	c=(c+n)%n;
	for(i=1;i<=t3;i++)
		x1[++t1]=x3[i];
	for(i=1;i<=t4;i++)
		x2[++t2]=x4[i];
	int cnt=0,j=1;
	i=1;
	while(i<=t1||j<=t2)
	{
		if(j>t2||(i<=t1&&x1[i]<=x2[j]))
			y[++cnt]=x1[i++];
		else
			y[++cnt]=x2[j++];
	}
	for(i=c+1;i<=n;i++)
		printf("%d\n",y[i]);
	for(i=1;i<=c;i++)
		printf("%d\n",y[i]);
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int flag=1;
	for(int i=0;i<s.size();++i)
	{
		if(s[i]!=t[i])
		{
			flag=0;
			break;
		}
	}
	if(flag)
	 cout<<"Yes"<<endl;
	else
	 cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3572