akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 998244353

ll modpow(ll x, ll y) {
	x %= MOD;
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		y >>= 1;
		x *= x;
		x %= MOD;
		ans %= MOD;
	}
	return ans;
}

ll moddiv(ll y) {
	return modpow(y, MOD - 2);
}

ll NC[3000007], NC1[3000007], NC2[3000007], R[4000007];

int main(){
	ll N, M;
	cin >> N >> M;
	
	for (int i = 4000006;i > 0;i--) {
		R[i] = moddiv(i);
	}
	
	NC[0] = 1;
	for (int i = 1;i <= N;i++) {
		NC[i] = NC[i - 1];
		NC[i] *= N - i + 1;NC[i] %= MOD;
		NC[i] *= R[i];NC[i] %= MOD;
		//cout << i << " " << NC[i] << endl;
		//NC[i]=nCi
	}

	NC2[0] = 1;
	for (int x = 1;x <= N - 2;x++) {
		NC2[0] *= 3 * M + x;
		NC2[0] %= MOD;
		NC2[0] *= R[x];
		NC2[0] %= MOD;
	}

	for (int i = 1;i <= 3 * M;i++) {
		NC2[i] = NC2[i - 1];
		NC2[i] *= 3 * M - i + 1;
		NC2[i] %= MOD;
		NC2[i] *= R[3 * M - i + N - 1];
		NC2[i] %= MOD;

		//cout << 3 * M - i + N - 2 << " " << N - 2 << " " << NC2[i] << endl;
		//NC2[i]=(3*M-i+N-2)C(N-2)
	}

	NC1[0] = 1;
	for (int i = 1;i <= 3 * M;i++) {
		NC1[i] = NC1[i - 1];
		NC1[i] *= N - 1 + i;
		NC1[i] %= MOD;
		NC1[i] *= R[i];
		NC1[i] %= MOD;
		//NC1[i]=(N-1+i)C(N-1)
	}
	ll ans = NC1[3 * M];

	//奇数がM個を超える
	ll hj = 0;
	for (int i = M + 2;i <= 3 * M && i <= N;i += 2) {
		//cout << NC[i] << " " << NC1[(3 * M - i) / 2] << endl;
		hj += NC[i] * NC1[(3 * M - i) / 2];
		hj %= MOD;
	}

	//maxが2Mを超える
	ll mo = 0;
	for (int i = 2 * M + 1;i <= 3 * M;i++) {
		mo += N * NC2[i];
		mo %= MOD;
	}
	//cout << ans << " " << hj << " " << mo << endl;
	ans -= hj + mo;
	ans %= MOD;if (ans < 0)ans += MOD;
	cout << ans << endl;
}

Measured memory_bytes: 65792
N = gets.to_i
as = []
(1..N).each do |i|
    as[i] = gets.to_i
end

visited = {}
visited[1] = true
i = 1
push = 0
loop do
    i = as[i]
    push += 1
    if i == 2
        puts push
        exit
    elsif visited[i]
        puts -1
        exit
    end
    visited[i] = true
end

Measured memory_bytes: 9032
import numpy as np
x, n = map(int, input().split())
p = list(map(int, input().split()))

def judge(p_,x_):
    p_d = list(set(sorted(map(lambda y: np.abs(x_-y),p_))))
    if p_d == []:
        return x_
    for delta in range(100):
        if (x_-delta not in p_):
            return x_-delta
        if (x+delta not in p_):
            return x_+delta
    return x_

print(judge(p,x))


Measured memory_bytes: 27044
//atcoder ARC? C
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007
using namespace std;
long long n,m,i,j,k,cf[200005],now,a[200005],ans=1,sum,p1,p2;
char s[200005];
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
int main(){
	n=read();
	scanf("%s",s+1);
	for(i=1;i<=2*n;i++)
		if(s[i]=='W'&&(now&1)==0||s[i]=='B'&&(now&1)==1){
			a[i]=2;
			now^=1;
			p1++;
		}
		else{
			a[i]=1;
			now^=1;
			p2++;
		}
	for(i=1;i<=2*n;i++){
		if(a[i]==1)
			sum++;
		else{
			ans=ans*sum%mo;
			sum--;
		}
	}
	if(p1!=p2){
		cout<<0<<endl;
		return 0;
	}
	for(i=1;i<=n;i++)
		ans=ans*i%mo;
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  ll ans = 0, temp = 0;
  rep0(i, N) {
    ll p; cin >> p;
    if (p == i + 1) {
      temp++;
    } else {
      ans += (temp + 1) / 2;
      temp = 0;
    }
  }
  ans += (temp + 1) / 2;

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m), sa(n+1, 0), sb(m+1, 0);
    rep(i, n) {
        cin >> a[i];
        sa[i+1] = sa[i] + a[i];
    }
    rep(i, m) {
        cin >> b[i];
        sb[i+1] = sb[i] + b[i];
    }
    sb.push_back(INF);


    int ans = 0;
    for(int i = 0; i <= n; ++i) {
        ll re = k - sa[i];
        if(re < 0) continue;
        int id = upper_bound(sb.begin(), sb.end(), re) - sb.begin();
        chmax(ans, i + id - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11164
#include <iostream>
#include <vector>

void solve() {
    int n;
    std::cin >> n;

    int ans = 0, min = n;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        if (min >= x) ++ans;
        min = std::min(min, x);
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
H = get_ints

now = H[0]
count = 0
max_count = 0

H[1..].each do |h|
  if now >= h
    count += 1
  else
    count = 0
  end
  max_count = count if count > max_count
  now = h
end

puts max_count


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

int main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    ll n, p; cin >> n >> p;

    ll ans = 1;
    if (n == 1) {
        cout << p << endl;
        return 0;
    } else if (p == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (ll i = 2; i*i <= p; i++) {
        ll count = 0;
        while (p % i == 0) {
            count++;
            if (count == n) {
                ans *= i;
                count = 0;
            }
            p/=i;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define ll long long
#define INF 0x3f3f3f3f
const int N=10005;
using namespace std;

ll a[N],b[N],suma=0,sumb=0;
int n;
ll dp[2][N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		suma+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		sumb+=b[i];
	}
	if(suma>sumb){
		puts("No");
		return 0;
	}
	if(suma==sumb){
		for(int i=1;i<=n;i++)
		if(a[i]!=b[i]){
			puts("No");
			return 0;
		}
		puts("Yes");
		return 0;
	}
	ll top=0,d=0;
	for(int i=1;i<=n;i++){
		if(a[i]==b[i]){
			continue;
		}
		if(a[i]<b[i]){
			ll x=b[i]-a[i];
			top+=x/2;
		}else if(a[i]>b[i]){
			ll x=a[i]-b[i];
			d+=x;
		}
	}
	if(top>=d) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
using LL = long long;

constexpr LL INF = 1L << 32;

LL G[101][101];

int main() {

    int V, E;
    cin >> V >> E;

    //
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (i == j) G[i][j] = 0;
            else G[i][j] = INF;
        }
    }

    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    //
    bool negative_cycle = false;

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (G[i][k] == INF) continue;
            for (int j = 0; j < V; j++) {
                if (G[k][j] == INF) continue;
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
                if (i == j && G[i][j] < 0) {
                    negative_cycle = true;
                    goto outer;
                }
            }
        }
    }
    outer:

    //
    if (negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++) {
            int k = 0;
            for (int j = 0; j < V; j++) {
                if (k++) cout << " ";
                cout << (G[i][j] != INF ? to_string(G[i][j]) : "INF");
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

int main()
{
    int N;
    int K;
    double ans=0;
    cin>>N>>K;
    if(N>=K) ans+=N-K+1;
    double ans2=0;
    FOR(i,1,min(K-1,N)){
        FOR(j,1,20){
            if(i*pow(2,j)>=K){
                ans2+=pow(2,20-j);
                break;
            }
            // cout<<ans2<<endl;
        }
    }
    // ans+=ans2/pow(2,20);
    // cout<<setprecision(15)<<ans<<endl;
    // ans+=ans2;
    // cout<<setprecision(15)<<ans<<endl;
    // ans/=N;
    ans=(double)ans/N+ans2/(pow(2,20)*N);
    cout<<setprecision(15)<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int K, X;
	cin >> K >> X;

	if (500*K>=X) cout << "Yes" << "\n";
	else cout << "No" << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n);
  vector<ll> b(m);

  REP(i, n) {
    ll ai;
    cin >> ai;
    a[i] = ai;
  }
  REP(i, m) {
    ll bi;
    cin >> bi;
    b[i] = bi;
  }

  vector<ll> acc_a(n);
  vector<ll> acc_b(m);

  acc_a[0] = a[0];
  acc_b[0] = b[0];

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

  for (int i = 1; i < m; i++) {
    acc_b[i] = acc_b[i - 1] + b[i];
  }


  ll ans = 0;

  auto itr = upper_bound(ALL(acc_b), k);
  ans = (ans, itr - acc_b.begin());

  REP(i, n) {
    ll tmp = i + 1;
    ll total = acc_a[i];
    ll remain = k - total;

    if(remain < 0){
        continue;
    }

    auto itr = upper_bound(ALL(acc_b), remain);

    tmp += (itr - acc_b.begin());

    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9532
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

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


int main()
{
	ll n, a[10005], b[10005], t = 0;

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

	for (ll i = 0; i < n; i++) {
		if (a[i] > b[i]) {
			t += (a[i] - b[i]) * 2;
		}
		else if (a[i] < b[i]) {
			if ((b[i] - a[i]) % 2 == 0) {
				t -= (b[i] - a[i]);
			}
			else {
				t -= (b[i] - a[i] - 1);
			}
		}
	}

	if (t > 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 384
N,M = map(int,input().split())
cake = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(8):
    sign = [0,0,0]
    for j in range(3):
        sign[j] = (i>>j & 1)
    cake_i = []
    for k in range(N):
        s = 0
        for j in range(3):
            s += cake[k][j]*(1-2*sign[j])
        cake_i.append(s)
    cake_i.sort(reverse = True)
    ans = max(ans,sum(cake_i[:M]))
    
print(ans)

Measured memory_bytes: 42224
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll d = 10000000000;
    cout << "? " << d << endl;
    string ans;
    cin >> ans;
    if (ans == "Y") {
        while (d > 0) {
            cout << "? " << d - 1 << endl;
            cin >> ans;
            if (ans == "N")
                break;
            d /= 10;
            if (d == 1)
                break;
        }
        cout << "! " << d << "\n";
    } else {
        while (true) {
            d /= 10;
            cout << "? " << d << endl;
            cin >> ans;
            if (ans == "Y")
                break;
        }
        ll ok      = d * 10;
        ll ng      = d;
        auto check = [&](ll m) {
            cout << "? " << m << endl;
            cin >> ans;
            return ans == "Y";
        };
        while (ng + 1 != ok) {
            ll mid = (ok + ng) / 2 * 10;
            if (check(mid))
                ok = mid / 10;
            else
                ng = mid / 10;
        }
        cout << "! " << ok << "\n";
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define int long long 

const int mod = 1e9+7;

signed main(void){ 
  
  int n,k; cin >> n >> k;
  int ans = 0;
  
  for(int x = k; x <= n+1; x++){ 
    int res = (n*x)%mod;
    res = (res-x*(x-1)+mod*mod) % mod;
    res = (res+1)%mod;
    
    ans = (ans+res)%mod;
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  long long q, h, s ,d;
  cin>>q>>h>>s>>d;
  long long n;
  cin>>n;
  long long qq = 8 * q;
  long long hh = 4 * h;
  long long ss = 2 * s;
  long long ans = 0;
  if (qq <= hh && qq <= ss && qq <= d) {
    ans = n * 4 * q;
  } else if (hh <= qq && hh <= ss && hh <= d) {
    ans = n * 2 * h;
  } else if (ss <= qq && ss <= hh && ss <= d) {
    ans = n * s;
  } else {
    ans = n / 2 * d;
    if (n % 2 == 1) {
      ans += min(qq / 2, min(hh / 2, ss / 2));
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

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

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll a,b,c,d,e,k,l,m,n,o=0,p,q,r,x,y,z,max1=0,ans=0;
    string s,t,u;
    cin>>a>>b;
    
    if(a>0&&b>0&&a<10&&b<10){
      cout<<a*b<<endl;   
    }
    else cout<<-1<<endl;
    
}






Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<vector<int>> cnts(2, vector<int>(n + 10, 0));

    for (int i = 0; i + 1 < n; ++i) {
        if (s.substr(i, 2) == "AC") {
            ++cnts[0][i + 1];
        }
    }

    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j + 1 < cnts[i].size(); ++j) {
            cnts[i][j + 1] += cnts[i][j];
        }
    }


    auto count = [&](int l, int r) {
        int res = 0;
        --r;
        res += cnts[0][r + 1] - cnts[0][l];
        // res += cnts[1][r + 1] - cnts[1][l];
        return res;
    };

    while (q-- > 0) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        cout << count(l, r) << "\n";
    }



    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  string s; cin >> s;
  int n = s.size();
  for(int i = n-2; i >= 2; i-=2) {
    string t = s.substr(0, i);
    int m = t.size();
    if(t.substr(0, m/2) == t.substr(m/2, m/2)) {
      cout << m << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(10 ** 9)

n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [set() for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].add(d)
  block[d].add(c)

ans = [0 for i in range(n)]

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    r[cnt].add(s)
    for i in ab[s]:
      dfs(i)

vis = [False for i in range(n)]
r = []
cnt = 0
for i in range(n):
  if vis[i] == False:
    r.append(set())
    dfs(i)
    cnt += 1

ans = [0 for i in range(n)]
for i in r:
  l = len(i)
  for j in i:
    ans[j] = l - len(ab[j]) - len(i&block[j]) - 1

print (*ans)

Measured memory_bytes: 98348
#include <bits/stdc++.h>
using namespace std;
vector<int> loc[26];

int main() {
	string s;
	cin>>s;
	int n=s.length();
	for (int i=0; i<n; i++) {
		loc[s[i]-'a'].push_back(i);
	}
	for (int i=0; i<26; i++) {
		loc[i].push_back(n);
	}
	int p[n][18];
	int trk[26];
	memset(trk,0,sizeof(trk));
	int cmax=0;
	for (int i=0; i<26; i++) cmax=max(cmax,loc[i][trk[i]]);
	for (int i=0; i<n; i++) {
		trk[s[i]-'a']++;
		cmax=max(cmax,loc[s[i]-'a'][trk[s[i]-'a']]);
		p[i][0]=cmax;
	}
	for (int i=1; i<18; i++) {
		for (int j=0; j<n; j++) {
			if (p[j][i-1]!=n) p[j][i]=p[p[j][i-1]][i-1];
			else p[j][i]=n;
		}
	}
	
	int curr=-1;
	int ansl=0;
	while (curr!=n) {
		int nw=-1;
		for (int i=0; i<26; i++) {
			nw=max(nw,*upper_bound(loc[i].begin(),loc[i].end(),curr));
		}
		curr=nw;
		ansl++;
	}
	//printf("%d %d\n", ansl, n);
	string comm; int st=-1;
	
	for (int k=0; k<ansl; k++) {
		int sml=26, nwst=-1;
		for (int j=25; j>=0; j--) {
			int npos=*upper_bound(loc[j].begin(),loc[j].end(),st);
			int tr=0;
			int nw=npos;
			if (nw!=n) {
				tr=1;
				for (int i=17; i>=0; i--) {
					//printf("%d!\n", p[nw][i]);
					if (p[nw][i]!=n) {
						tr+=1<<i;
						nw=p[nw][i];
					}
				}
			}
			//printf("%d %d %d\n", j, npos, tr);
			if (tr+k==ansl-1) {
				sml=j;
				nwst=npos;
			}
		}
		comm+='a'+sml;
		st=nwst;
	}
	cout<<comm<<endl;
}


Measured memory_bytes: 15492
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう,
signed main(){
    int n;int a[114514];
    cin>>n;rep(i,0,n)cin>>a[i];
    int c=2;
    int ans=1;int now=2;
    rep(i,1,n){
        if(a[i]>a[i-1])now=1;
        else if(a[i]<a[i-1])now=0;
        else continue;
        if(c==2)c=now;
        else if(c!=now){
            ans++;
            c=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

double memo[300][300][300];
ll n;

double hoge(ll a,ll b,ll c,ll d){
    //cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
    if(memo[a][b][c]!=0){
        return memo[a][b][c];
    }
    if(a==n){
        return 0;
    }
    double sum=(double)a/n;
    double bunbo=1-((double)a/n);
    if(b>=1)sum=sum+((double)b/n)*(hoge(a+1,b-1,c,d)+1);
    if(c>=1)sum=sum+((double)c/n)*(hoge(a,b+1,c-1,d)+1);
    if(d>=1)sum=sum+((double)d/n)*(hoge(a,b,c+1,d-1)+1);
    return memo[a][b][c]=(sum/bunbo);
}

int main(){fastio
    cin>>n;
    ll a[4];rep(i,0,3)a[i]=0;
    ll b;
    rep(i,0,n-1){
        cin>>b;
        a[b]++;
    }
    double ans=hoge(a[0],a[1],a[2],a[3]);
    cout<<setprecision(12)<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 211328
#include <iostream>

int N, M, Q;
int L[200010], R[200010];
int p[100010], q[100010];

int START[510][510];
int START_SUM[510][510];

using namespace std;

int main() {
   cin >> N >> M >> Q;
   for (int i=1;i<=M;i++) {
      cin >> L[i] >> R[i];
      START[L[i]][R[i]]++;
   }
   for (int i=1;i<=500;i++) {
      for (int j=1;j<=500;j++) {
	 START_SUM[i][j] = START_SUM[i-1][j] + START[i][j];
      }
   }
   for (int i=1;i<=Q;i++) {
      cin >> p[i] >> q[i];
      int val=0;
      for (int k=p[i];k<=q[i];k++) {
	 val+=(START_SUM[q[i]][k] - START_SUM[p[i]-1][k]);
      }
      cout << val << endl;
   }
   return 0;
}


Measured memory_bytes: 5248
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static string s = "";
    static string[] ss;
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static int[] arr;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        if (n == 0)
        {
            n = Int(rl());
        }
        arr = new int[n];
        if (num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        ss = rls();
        long a = long.Parse(ss[0]);
        long b = long.Parse(ss[1]);
        long k = long.Parse(ss[2]);

        if (a < k) b = Math.Max(0, b - (k - a));
        a = Math.Max(0, a - k);
        wl(a.ToString() + " " + b.ToString());
    }

}



Measured memory_bytes: 11092
#E問題
'''
完全グラフは距離が全て1のもの
最大の数はスターグラフで一つの頂点を中心に他の組が出ているもの(N-1)(N-2)/2

'''
N, K = map(int,input().split())
mx = (N-1)*(N-2)/2
graph = []
if mx < K:
    print(-1)
else:
    for i in range(N-1):
        star_graph = [i+1 , N]
        graph.append(star_graph)
    band_num = int(mx - K)
    edge = []
    for i in range(N-1):
        for j in range(i):
            edge.append([i+1,j+1])
    for i in range(band_num):
        graph.append(edge[i])
    M = len(graph)
    print(M)
    for i in range(len(graph)):
        print("{0} {1}".format(graph[i][0],graph[i][1]))
    
        
    


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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define pii pair < int, int >

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

multiset < ll > red, green;
vector < ll > r, g, cc;

bool comp(ll a, ll b)
{
    return a > b;
}

int main()
{
    ll i, j, k, l, m, n, o, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    ll x, y, a, b, c;

    cin >> x >> y >> a >> b >> c;

    for(i = 0; i < a; i++)
    {
        slld(input);
        r.push_back(input);
    }

    for(i = 0; i < b; i++)
    {
        slld(input);
        g.push_back(input);
    }

    for(i = 0; i < c; i++)
    {
        slld(input);
        cc.push_back(input);
    }

    sort(r.begin(),r.end(),comp);
    sort(g.begin(),g.end(),comp);
    sort(cc.begin(),cc.end(),comp);

    for(i = 0; i < x; i++)
        red.insert(r[i]);

    for(i = 0; i < y; i++)
        green.insert(g[i]);

//    bug;
    for(i = 0; i < c; i++)
    {
        set < ll > :: iterator it1, it2;

        it1 = red.begin();
        it2 = green.begin();


        if((*it1) < (*it2))
        {
//            bug;
            if((*it1) < cc[i])
            {
                red.erase(it1);
                red.insert(cc[i]);
            }
        }
        else
        {
            if((*it2) < cc[i])
            {
                green.erase(it2);
                green.insert(cc[i]);
            }
        }
    }

    ll sum = 0;

    for(set < ll > ::iterator it = red.begin(); it != red.end(); it++) sum += (*it);
    for(set < ll > ::iterator it = green.begin(); it != green.end(); it++) sum += (*it);

    cout << sum << endl;


}





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

int main(){
	int N,M;
	cin >> N >> M;
	int a[M],b[M];
	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i];
	}
	
	int R[N][N];
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			R[i][j]=0;
		}
	}
	
	for(int i=0;i<M;i++){
		R[a[i]-1][b[i]-1]++;
		R[b[i]-1][a[i]-1]++;
	}
	
	for(int i=0;i<N;i++){
		int count=0;
		for(int j=0;j<N;j++){
			count+=R[i][j];
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 256
S = input()

res = 0
t = '0'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_1 = res

res = 0
t = '1'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_2 = res

if res_1 >= res_2:
    print(res_2)
else:
    print(res_1)



Measured memory_bytes: 3188
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int buf;
			for(;;) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				if(x==0 && y==0) break;

				if(y<x) {
					buf = y;
					y = x;
					x = buf;
				}
				System.out.println(String.format("%d %d", x, y));
			}
		}
	}
}


Measured memory_bytes: 41540
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
	int n;
	int a[100]={};
	double ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans+=(double)1/a[i];
	}
	cout<<1/ans;
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(s: int):
    res = [0] * 1000001
    a = s
    i = 1
    while True:
        if res[a] == 1:
            break
        res[a] = 1
        if a % 2 == 0:
            a = a // 2
        else:
            a = 3 * a + 1
        i += 1
    return i


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12876
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[17][17],b[17][17];
int xx[17];
int num[17];
int n;
int check(int x){
    memset(num,0,sizeof(num));
    int ans=0;
    int cnt=1;
    while(x){
        if(x&1){
            num[cnt]=1;
            ++ans;
        }
        x/=2;
        ++cnt;
    }
    int flag=0;
    for(int i=1;i<=n;++i){
        if(num[i]){
            for(int j=1;j<=xx[i];++j){
                if(b[i][j]==1&&!num[a[i][j]])
                    flag=1;
                else if(b[i][j]==0&&num[a[i][j]])
                    flag=1;
            }
        }
    }
    if(!flag)
        return ans;
    return 0;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>xx[i];
        for(int j=1;j<=xx[i];++j){
            cin>>a[i][j]>>b[i][j];
        }
    }
    int lastans=0;
    for(int i=0;i<=(1<<n)-1;++i)
        lastans=max(lastans,check(i));
    cout<<lastans;
    return 0;
}

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

#define int long long
#define REP(i,s,n) for(int i=s;i<n;i++)
const long long LINF=1e18;
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n,k;cin>>n>>k;
  vector<int> v(n),w(n+1,0),se(n+1,0);
  REP(i,0,n)cin>>v[i];
  REP(i,0,n)w[i+1]=w[i]+v[i];
  REP(i,0,n)se[i+1]=se[i]+max(v[i],0LL);
  int ans=-LINF;
  REP(i,0,n-k+1)chmax(ans,se[i]-se[0]+se[n]-se[i+k]+max(w[i+k]-w[i],0LL));
  cout<<ans<<endl;
}


Measured memory_bytes: 5640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 1010
#define MAXM 2010
#define MOD 1000000007
using namespace std;
int diff[MAXM];
struct node{
	int u,v,len;
	node () {}
	node (int u1,int v1,int len1):u(u1),v(v1),len(len1) {}
	bool operator < (const node &x) const {
		return len<x.len;
	}
}line[MAXM];
bool used[MAXM];
long long x,sum;
int fa[MAXN],fal[MAXN],deep[MAXN];
vector<int> a[MAXN],w[MAXN];
int get_fa(int x){
	if(fa[x]==0)
		return x;
	fa[x]=get_fa(fa[x]);
	return fa[x];
}
void build(int x,int fa1){
	fa[x]=fa1;
	deep[x]=deep[fa1]+1;
	for(int i=0;i<a[x].size();i++){
		if(a[x][i]==fa1){
			fal[x]=w[x][i];
			continue;
		}
		build(a[x][i],x);
	}
}
int find_max(int u,int v){
	int maxv=0;
	if(deep[u]<deep[v])
		swap(u,v);
	while(deep[u]>deep[v]){
		maxv=max(maxv,fal[u]);
		u=fa[u];
	}
	while(u!=v){
		maxv=max(maxv,max(fal[u],fal[v]));
		u=fa[u];
		v=fa[v];
	}
	return maxv;
}
int n,m,u,v,val;
long long bits[MAXM];
void prepare(){
	bits[0]=1;
	for(int i=1;i<=m;i++)
		bits[i]=(bits[i-1]*2ll)%MOD;
}
int main(){
	SF("%d%d",&n,&m);
	prepare();
	SF("%lld",&x);
	for(int i=0;i<m;i++){
		SF("%d%d%d",&u,&v,&val);
		line[i]=node(u,v,val);
	}
	sort(line,line+m);
	for(int i=0;i<m;i++){
		int u=get_fa(line[i].u);
		int v=get_fa(line[i].v);
		if(u!=v){
			fa[u]=v;
			sum+=line[i].len;
			a[line[i].u].push_back(line[i].v);
			a[line[i].v].push_back(line[i].u);
			w[line[i].u].push_back(line[i].len);
			w[line[i].v].push_back(line[i].len);
			used[i]=1;
		}
	}
	x=x-sum;
	if(x<0){
		PF("0");
		return 0;
	}
	memset(fa,0,sizeof fa);
	build(1,0);
	int cnt=0;
	for(int i=0;i<m;i++)
		if(used[i]==0){
			int maxd=find_max(line[i].u,line[i].v);
			diff[++cnt]=line[i].len-maxd;
		}
	sort(diff+1,diff+1+cnt);
	long long res=0;
	if(x==0)
		res=(bits[m]-2ll*bits[m-n+1]+2ll*MOD)%MOD;
	for(int i=1;i<=cnt;i++)
		if(x==diff[i]){
			res+=2ll*bits[cnt-i];
			res%=MOD;
		}
	PF("%lld",res);
}

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

const int N=1000005;
int n,a,b,c,d[N],ans[N];
char s[N];

int main()
{
	scanf("%d%d%d%d",&n,&a,&b,&c);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if(s[0]=='A'&&s[1]=='B') d[i]=1;
		else if(s[0]=='B') d[i]=2; else d[i]=3;
	}
	for(int i=1;i<=n;i++)
	{
		if(d[i]==1&&a+b==0||d[i]==2&&b+c==0||d[i]==3&&a+c==0)
		{
			printf("No\n");
			return 0;
		}
		if(d[i]==1&&a==1&&b==1&&d[i+1]>1)
		{
			if(d[i+1]==2) ans[i]=2,a--,b++;
			if(d[i+1]==3) ans[i]=1,a++,b--;
		}
		else if(d[i]==1&&b>a) ans[i]=1,a++,b--;
		else if(d[i]==1) ans[i]=2,a--,b++;
		if(d[i]==2&&b==1&&c==1&&d[i+1]%2)
		{
			if(d[i+1]==1) ans[i]=2,b++,c--;
			if(d[i+1]==3) ans[i]=3,b--,c++;
		}
		else if(d[i]==2&&b<c) ans[i]=2,b++,c--;
		else if(d[i]==2) ans[i]=3,b--,c++;
		if(d[i]==3&&a==1&&c==1&&d[i+1]<3&&d[i+1])
		{
			if(d[i+1]==1) ans[i]=1,a++,c--;
			if(d[i+1]==2) ans[i]=3,a--,c++;
		}
		else if(d[i]==3&&a<c) ans[i]=1,a++,c--;
		else if(d[i]==3) ans[i]=3,a--,c++;
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++) printf("%c\n",(char('A'+ans[i]-1)));
}

Measured memory_bytes: 4624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MaxN = 50;
char a[MaxN + 5];
long long x, y;
double ans;

int main()
{
	scanf("%lld %lld", &x, &y);
	if(y == 1 || x%y == 0) printf("-1\n");
	else
	{
		for(int i = 2; i <= 1e9; i++)
		{
			ans = x * i;
			if((long long)ans % y == 0) continue;
			else break;
		}
		printf("%.0lf\n", ans);
	}
	return 0;
}

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

using namespace std;

int main()
{

	int N, s=0;

	cin >> N;

	long int a[N][2];

	for(int i=0;i!=N;i++)
	{
		cin >> a[i][0] >> a[i][1];
		s += a[i][1]-a[i][0]+1;
	}

	cout << s << endl;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let n: usize = get_one();
    if n == 2 { println!("{}", 1); return; }
    let ds = divisors(n);
    let mut ans = 0;
    for d in &ds[1..] {
        let mut m = n;
        while m % d == 0 {
            m = m / d;
        }
        if m % d == 1 { ans += 1; }
    }
    ans += divisors((n as i64 - 1) as usize)[1..].len();
    println!("{}", ans);
}

fn divisors(n: usize) -> Vec<usize> {
    let mut ds = Vec::new();
    for i in 1..n {
        if i * i > n { break; }
        if n % i == 0 {
            ds.push(i);
            let z = n / i;
            if z != i { ds.push(z); }
        }
    }
    return ds;
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


Measured memory_bytes: 2104
# -*- coding: utf-8 -*-
import sys

def main():
	S = input();

	yer = int(S[:4])
	mon = int(S[5:7])
	day = int(S[8:])

	if yer > 2019:
		print("TBD")
		sys.exit()
	if yer < 2019:
		print("Heisei")
		sys.exit()
	if mon > 4:
		print("TBD")
		sys.exit()
	if mon < 4:
		print("Heisei")
		sys.exit()
	if day <= 30:
		print("Heisei")
		sys.exit()
	print("TBD")

if __name__ == "__main__":
	main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    string s;
    bool a = false;
    cin >> s;
    for (int i = 0; i < 3; ++i) {
        if(s[i] == s[i+1]){
            a = true;
        }
    }

    if(a){
        cout << "Bad";
    }else{
        cout << "Good";
    }
    return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n,t;
vector<int> vec;

int main(){
  scanf("%d %d",&n,&t);
  REP(i,n){
    int a;
    scanf("%d",&a);
    vec.push_back(a);
  }
  sort(vec.begin(),vec.end());
  ll sum = 0;
  ll start= vec[0];
  ll end = vec[0]+t;
  for(int i = 1;i<vec.size();i++){
    if(end>=vec[i]){
      end = vec[i]+t;
    }else{
      sum += end - start;
      start = vec[i];
      end = vec[i] + t;
    }
  }
  sum += end - start;
  printf("%lld\n",sum);
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll m = n / i - 1;
            if (m > i) ans += m;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
'use strict'


function Main(input) {
  input = input.trim().split('\n')
  const array = input[0].split(' ').map(s => parseInt(s))

  const H = array[0]
  const N = array[1]
  const a = input[1].split(' ').map(s => parseInt(s))

  let total = H
  for(let i = 0; i < N; ++i) {
    total -= a[i]
  }

  if(total <= 0) {
    console.log('Yes')
  } else {
    console.log('No')
  }



}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16716
import bisect
n = int(input())
if n == 1:
    print(0)
else:
    #nの素因数分解(O(n**0.5)
    def prime_factor(n):
        ass = []
        for i in range(2,int(n**0.5)+1):
            while n % i==0:
                ass.append(i)
                n = n//i
        if n != 1:
            ass.append(n)
        return ass
    
    p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
    r = [0] * 25 #n!を因数分解した時の各素数の数
    
    #n!の因数分解
    for i in range(2,n+1):
        k = 0
        while i != 1:
            while i%p[k] == 0:
                i = i //p[k]
                r[k] += 1
            k += 1
    
    r.sort()
    c75 = bisect.bisect_left(r,74)
    c25 = bisect.bisect_left(r,24)
    c15 = bisect.bisect_left(r,14)
    c5 = bisect.bisect_left(r,4)
    c3 = bisect.bisect_left(r,2)
    res = (25-c75) + (25-c25)*(25-(c3+1)) +(25 -c15)*(25-(c5+1)) + (25-c5)*(25-(c5+1))*(25-(c3+2))//2
    print(res)

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

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int C[N];
  int V[N];

  for(int i=0; i<N; i++){
    cin >> V[i];
  }
  for(int i=0; i<N; i++){
    cin >> C[i];
  }

  int max = 0;
  for(int i=0; i<N; i++){
    if(V[i]>C[i]) max += V[i]-C[i];
  }

  cout << max;

  return 0;
}


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

int main(){
	int A,B;
	cin >> A >> B;
	
	int ans=0;
	for(int i=A;i<=B;i++){
		string s = to_string(i);
		string t = s;
		reverse(t.begin(),t.end());
		if(s==t) ans++;
	} 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int ice[10],n,i,u,j;
	while(1){
		scanf("%d",&n);
		if(n==0)break;//終了条件
		for(i=0;i<10;i++) 
			ice[i]=0;
		
		for(i=0;i<n;i++){
			scanf("%d",&u);
			ice[u]++;
		}
		for(i=0;i<10;i++){
			if(ice[i]==0) printf("-\n");
			else {
				for(j=0;j<ice[i]-1;j++)
					printf("*");

				printf("*\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1012
#include<stdio.h>
#define N 1000000
unsigned int TBL[N];
void tbl(){
	unsigned int a,b;
	for(a=1;a<=N;a++) TBL[a]=0;
	for(a=2;a<=N;a++){
		if(TBL[a]==0){
			for(b=2;a*b<=N;b++) TBL[a*b]=1;
		}
	}
}
int main(void){
	int i,n,kosu;
	tbl();
	while(scanf("%d",&n)!=EOF){
		kosu=0;
		for(i=2;i<=n;i++){
			if(TBL[i]==0) kosu++;
		}
		printf("%d\n",kosu);
	}
	return 0;
}

Measured memory_bytes: 4500
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
	  Scanner sc=new Scanner(System.in);
    String s=sc.nextLine();
   
    
    String t=sc.next();
	
    int dp[][]=new int[s.length()+1][t.length()+1];
   
    for(int i=1;i<=s.length();i++)
    {
      for(int j=1;j<=t.length();j++)
      {
        if(s.charAt(i-1)==t.charAt(j-1))
        {
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else
        {
          dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
        }
      }
      
    }
	String res="";
	int i=s.length(),j=t.length();
	while(i>0&&j>0)
	{
		if(s.charAt(i-1)==t.charAt(j-1))
		{
			res=s.charAt(i-1)+res;
			i--;j--;
		}
		else if(dp[i-1][j]>=dp[i][j-1])
		{
			i--;
		}
		else{
			j--;
	}  
	}
	System.out.println(res);
}
}

Measured memory_bytes: 86012