akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const ll INF = (ll)(1e18);

int main(void){
  ll n;
  cin >> n;
  vector<ll> dp(n+1, INF);
  dp[0] = 0;
  REP(i, n){
    for(ll j = 1; i+j <= n; j *= 6){
      chmin(dp[i+j], dp[i]+1);
    }
    for(ll j = 1; i+j <= n; j *= 9){
      chmin(dp[i+j], dp[i]+1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1024
N=int(input())
X=list(map(int,input().split()))
l=len(X)
s=10**10
for i in range(min(X),max(X)+1):
    x=[]
    for j in range(l):
        x.append((X[j]-i)**2)
    if s>sum(x):
        s=sum(x)
print(s)

Measured memory_bytes: 9132
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
#define em emplace_back
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
#define Rosario ios::sync_with_stdio(0),cin.tie(0);
#define pll pair<ll,ll> 
//#define lb(x) (x&-x)

ll a,b;
int main(){//Rosario
    cin>>a>>b;
    cout<<a*b/__gcd(a,b)<<"\n";    
//    system("pause");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }eni(!=) cerr  << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
} sim dor(rge<c> d) { *this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
#define err(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll=long long;
using vi=vector<int>;



int main() {
//    ios::sync_with_stdio(false) , cin.tie(0);
    int n;
    scanf("%d", &n);
    int odd = ( n + 1) / 2;
    printf("%.7f", (double)odd / n);
   // cout << fixed << setprecision(7) << (double)odd / n << '\n';

    return 0;
}




Measured memory_bytes: 256
#include <cstdio>

int main(){
    int A,B;
    char op;
    scanf("%d %c %d",&A,&op,&B);
    if(op == '+'){
        printf("%d",A + B);
    }
    else{
        printf("%d",A - B);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m,i;
    scanf("%d%d",&n,&m);
    if(n<m){
        for(i=0;i<m;i++) printf("%d",n);
    }
    else{
        for(i=0;i<n;i++) printf("%d",m);
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t a,b,c,d; cin>>a>>b>>c>>d; --a;
	int64_t g=lcm(c,d);
	cout<<b-b/c-b/d+b/g-a+a/c+a/d-a/g<<"\n"s;
}


Measured memory_bytes: 3576
t = gets.to_i

t.times do
    n = gets.to_i
    a = gets.split.map(&:to_i)
    s = gets.chars

    dp = [0]
    (n-1).downto(0) do |i|
        if s[i] == ?0
            dp.each {|e| (x = a[i] ^ e) < a[i] and a[i] = x}

            if a[i] != 0
                dp.map!{|e| (x = e ^ a[i]) < e ? x : e}
                dp << a[i]
            end
        else
            a[i] = dp.inject(a[i]) {|r,v| (x = r ^ v) < r ? x : r}
            next if a[i] == 0
            p 1
            break
        end
    end and p 0
end

Measured memory_bytes: 14444
#include <bits/stdc++.h>//ビットの一番右端は０番目
using namespace std;//https://atcoder.jp/contests/abc054/tasks/abc054_c
int main(void){
//    bit |= (1<<i);// i番目のビットを立てる
//    bit &= ~(1<<j);// j番目のビットを消す
//    if (bit & (1<<k)){// k番目のビットが立っているか？
//    if (!(bit & (1<<k))){// k番目のビットが消えているか？
//    cout << bitset<8>(bit) << endl;
    int N,M;
    cin >> N >> M;
    vector<pair<int, int> > paths;
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        paths.push_back(make_pair(a,b));
    }
    
    stack<pair<int, int> >st;// キュー st を定義  <int , int> = < 位置pos 1～N , 状態state bitで表現 >
    st.push(make_pair(1,0));//スタート地点をstにプッシュ
    int count=0;
    while(st.empty()==false) {
        int pos=st.top().first;
        int state=st.top().second;
        st.pop(); // stackの一番上の要素を削除
        state |= (1<<(pos-1));// i番目(１以上）のビットを立てる
        for(int j=0;j<M;j++){
            int a=paths[j].first;
            int b=paths[j].second;
            if( (a==pos) && !(state & (1<<(b-1))) ){// b番目のビットが立っていないか？
                st.push(make_pair(b,state));//スタート地点をstにプッシュ
            }
            if( (b==pos) && !(state & (1<<(a-1))) ){// a番目のビットが立っていないか？
                st.push(make_pair(a,state));//スタート地点をstにプッシュ
            }
        }
        if(pow(2,N)-1==state){count++;}
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll dp[101][100001];
int main()
{
    FastIO
    int n,W,i,j;
    cin>>n>>W;
    vll v(n+1),w(n+1);
    for(i=1;i<n+1;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(i=0;i<n+1;i++)
    dp[i][0]=0;
    for(i=0;i<W+1;i++)
     dp[0][i]=0;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=W;j++)
        {
            if(w[i]<=j)
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            else
            dp[i][j]=dp[i-1][j];

        }

    }

    cout<<dp[n][W];


}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
char s[N];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    if(len==2&&s[1]==s[2]){ 
        printf("1 2\n");
        return 0;
    }
    int l=-1,r=-1;
    for(int i=1;i<len-1;i++){
        if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
            l=i,r=i+2;
         
        }
    }
    printf("%d %d\n",l,r);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
// #define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n];
    map<pint, int> mp;
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
        if (i < a[i]) {
            mp[{i, a[i]}]++;
        } else {
            mp[{a[i], i}]++;
        }
    }
    int ans = 0;
    for (auto p : mp) {
        if (p.second == 2) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 10252
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {

	auto S = readln.split[0];
	
	int ans1, ans2;
	foreach (i; 0 .. S.length) {
		if (i % 2 == 0) {
			S[i] == '0' ? ans1++ : ans2++;
		}
		else {
			S[i] == '0' ? ans2++ : ans1++;
		}
	}
	
	writeln(min(ans1, ans2));
}



Measured memory_bytes: 508
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N);
  int a = 0 , b = 0 , c = 0;
  rep(i,N){
    ini(x);
    if(x % 4 == 0) c++;
    else if(x % 2 == 0) b++;
    else a++;
  }
  out((a + (b != 0) <= c + 1) ? "Yes" : "No");
}

Measured memory_bytes: 256
a=[[1,3,5,7,8,10,12],[4,6,9,11],[2]]
x,y=gets.split.map(&:to_i)

ans=false

a.each{|l|
    if l.include?(x)&&l.include?(y)
        ans=true
    end
}

puts ans ? "Yes" : "No"

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    int N;cin>>N;
    vector<ll> A(N);//A[i]=jはiがj番目にあることをあらわす
    for(int i=0;i<N;i++){
        int a;cin>>a;
        a--;
        A[a]=i+1;
    }
    set<ll> S;
    ll ans=0;
    for(int i=0;i<N;i++){
        S.insert(A[i]);
        auto it=S.find(A[i]);
        bool flag1=false,flag2=false;
        auto s=it,t=it;
        if(it!=S.begin()){
            s--;
            flag1=true;
            //cout<<1<<" "<<i<<endl;
        }
        if(it!=--S.end()){
            t++;
            flag2=true;
            //cout<<2<<" "<<i<<endl;
        }
        if(flag1&&flag2){
            ans+=(i+1)*(A[i]-*s)*(*t-A[i]);
        }
        else if(flag1&&!flag2){
            ans+=(i+1)*(A[i]-*s)*(N-A[i]+1);
        }
        else if(!flag1&&flag2){
            ans+=(i+1)*(A[i])*(*t-A[i]);
        }
        else{
            ans+=(i+1)*A[i]*(N-A[i]+1);
        }
        //cout<<ans<<endl;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 11136
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))


typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

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



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

	lint n, m; cin >> n >> m;
	vector<lint>a, b, c, d;

	lint in1, in2;
	rep(i, n) {
		cin >> in1 >> in2;
		a.push_back(in1);
		b.push_back(in2);
	}
	rep(i, m) {
		cin >> in1 >> in2;
		c.push_back(in1);
		d.push_back(in2);
	}

	lint tmp = 0, mn, pos;
	rep(i, n) {
		mn = INT_MAX;
		rep(j, m) {
			tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (tmp < mn) {
				mn = tmp;
				pos = j + 1;
			}
		}
		co(pos);
	}
	
	gc();
}

Measured memory_bytes: 256
#include <stdio.h>

int n,k,cnt,p;

int main()
{
	scanf("%d %d",&n,&k);
	for (int i=1; i<=n; i++)
	{
		scanf("%d",&p);
		if (p>=k)
			cnt++;
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 128
def insertion_sort(A, N, g):
    cnt = 0
    for i in range(g,N):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
        # print(' '.join([str(s) for s in A]))
    return cnt

def shell_sort(A,N):
    j = 1
    m = 0
    cnt = 0
    G = []
    while j <= N:
        G.append(j)
        j = 3*j+1
        m += 1
    
    G = G[::-1]
    
    for g in G:
        cnt += insertion_sort(A, N, g)
    print(m)
    print(' '.join([str(g) for g in G]))
    print(cnt)
    print('\n'.join([str(s) for s in A]))

def solve():
    input_line = input()
    N = int(input_line)
    A = []
    for _ in range(N):
        A.append(int(input()))

    shell_sort(A, N)
    
solve()


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

const int nm = 2e5;
int n, k, a[nm];

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int inf = 0, sup = 1e9;
	while (sup - inf > 1) {
		int m = (inf + sup) / 2;
		int t = 0;
		for (int i = 0; i < n; ++i)
			t += (a[i] + m - 1) / m - 1;
		if (t <= k)
			sup = m;
		else
			inf = m;
	}
	cout << sup << endl;
}


Measured memory_bytes: 4364
//
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxnn 2000
ll n;
ll ry[maxnn][maxnn];
ll ru[maxnn];
ll d=0;
ll mark[maxnn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<n;j++)
	{
		scanf("%d",&ry[i][j]);
		ru[i]=1;
	}
	}
	while(1)
	{
		d++;
		for(int i=1;i<=n;i++)
{
		mark[i]=0;
}
		int tt=0;
		int tr=0;
		for(int i=1;i<=n;i++)
{
		if(ru[i]==n)	{continue;}
		if(mark[i]) {continue;}
		if(ry[ry[i][ru[i]]][ru[ry[i][ru[i]]]]!=i) 
	{
		tt++;
	} 
	else
	if(!mark[i]&&!mark[ry[i][ru[i]]])
	{
			ru[ry[i][ru[i]]]++;
			mark[i]=1;
			mark[ry[i][ru[i]]]=1;
			ru[i]++;
	}
}
	for(int i=1;i<=n;i++)
	if(ru[i]==n) tr++;
	if(tr==n) {cout<<d;return 0;}
	if(n-tr==tt) {cout<<-1;return 0;}
	}
} 

Measured memory_bytes: 16128
n,k = map(int, raw_input().split())
s = raw_input()
cd = 0
d = None
for l in s:
	if d != l:
		cd +=1
		d = l
score = 0
for u,v in zip(s,s[1:]):
	if u == v:
		score +=1

if cd > 2:
	t = min(k,((cd - 2)+1)/2)
	k -= t
	score += 2 * t 
	cd -= 2 * t
if cd == 2 and k:
	score +=1
	cd -= 1
print score

Measured memory_bytes: 46316
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int N, K;
    cin >> N >> K;
 
    vector<int> X1(N);
    vector<int> Y1(N);
    vector<int> D1(N);
    vector<int> X2(N);
    vector<int> Y2(N);
    vector<int> D2(N);
 
    for (int i = 0; i < N; i++){
        cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
    }
     
    //ソート用vector
    vector<int> X(2*N);
    vector<int> Y(2*N);
    vector<int> D(2*N);
    for (int i = 0; i < N; i++){
        X[2 * i]     = X1[i];
        X[2 * i + 1] = X2[i];
        Y[2 * i]     = Y1[i];
        Y[2 * i + 1] = Y2[i];
        D[2 * i]     = D1[i];
        D[2 * i + 1] = D2[i];
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    sort(D.begin(), D.end());
 
    long long ans = 0;
    int kasanari;
    for (int i = 0; i < 2*N-1; i++){ //X
        for (int j = 0; j < 2*N-1; j++){ //Y
            for (int k = 0; k < 2*N-1; k++){ //D
                kasanari = 0;
                for (int l = 0; l < N; l++){ //実際の直方体
                    if ((X1[l]<=X[i] && X[i+1] <= X2[l]) &&
                        (Y1[l]<=Y[j] && Y[j+1] <= Y2[l]) &&
                        (D1[l]<=D[k] && D[k+1] <= D2[l]))
                        kasanari++;
                }
                if (kasanari >= K){
                    ans += (long long)(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (D[k + 1] - D[k]);
                }
            }
        }
    }
 
    cout << ans << "\n";
 
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
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;
    }
}
 
// 二項係数計算
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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vector<vector<P>> G;
vl ans;
void dfs(int v, int p=-1, int c=-1){
  int k=1;
  for(auto nv:G[v]){
    int next=nv.first,id=nv.second;
    if(next==p)continue;
    if(k==c)k++;
    ans[id]=k;
    k++;
    dfs(next,v,ans[id]);
  }
}
    
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n;
  cin >> n;
  G.resize(n);
  ans.resize(n-1);
  
  vector<ll>cnt(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(P(b,i));
    G[b].push_back(P(a,i));
    cnt[a]++;
    cnt[b]++;
  }
  dfs(0);
  ll m=*max_element(cnt.begin(),cnt.end());
  cout << m << endl;
  rep(i,n-1)cout << ans[i] << endl;
  return 0;
                   
    
  
}


Measured memory_bytes: 22144
#include <iostream>

using namespace std;

int get(int K, int max)
{
    if (max <= (K + 1)/2) return 0;
    int parts = K - max + 1;
    return (K / parts) + (K % parts) - 1;
}

int main()
{
    int K, T;
    int max = 0;
    cin >> K >> T;
    for (int i = 0; i < T; ++i) {
        int a;
        cin >> a;
        if (a > max) max = a;
    }
    cout << get(K, max) << endl;
    return 0;
}

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

int main()
{
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xs;
  vector<int> ys;
  for (auto i = 0; i < n; i++) {
    int t;
    cin >> t;
    xs.push_back(t);
  }
  for (auto j = 0; j < m; j++) {
    int t;
    cin >> t;
    ys.push_back(t);
  }
  sort(begin(xs), end(xs), greater<>());
  sort(begin(ys), end(ys));
  if (x < ys[0] && xs[0] < y && xs[0] < ys[0]) {
    cout << "No War";
  } else {
    cout << "War";
  }
  cout << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<cmath>
using namespace std;
#define mod 1000000007
#define MOD(x) ((x)%mod)
long long n,m;
long long ans(long long x)
{
	long long a=1;
	for(long long i=1;i<=x;i++)
		a=MOD(a*i);
	return a;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	if(abs(n-m)>=2)
	{
		printf("0");
	}
	else if(abs(n-m)==1)
	{
		printf("%lld",MOD(ans(n)*ans(m)));
	}
	else
	{
		printf("%lld",MOD(ans(n)*ans(m)*2));
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ar[10000];
    int i,s;
    while(cin>>ar)
    {
        s=strlen(ar);
        for(i=0;i<s;i++)
        {
            cout<<ar[i];

            if(i==3)
            {
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°??????n?????????
		int n = sc.nextInt();

		//
		long sum = sc.nextInt();
		int min = (int)sum;
		int max = (int)sum;
		//??°?????????
		for(int i = 1; i < n; i++){

			int a = sc.nextInt();

			if(max < a){
				max = a;
			}else if(a < min){
				min = a;
			}
			sum += a;
		}
		System.out.println(min + " " + max + " "+ sum);
	}
}

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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

struct struk
{
    int t, x;
    char c;
};

vector<struk> kom;
char res[10000010];

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

    string s;
    cin >> s;
    int q;
    cin >> q;
    int duz = s.size();
    for(int i = 0; i < q; i++)
    {
        int p, k;
        cin >> p;
        if(p == 1) kom.pb({p, 0, 'a'});
        else
        {
            duz++;
            cin >> k;
            char ch;
            cin >> ch;
            kom.pb({p,k,ch});
        }
    }

    int r = 0;
    int pokS = 0;
    int pokE = duz - 1;
    for(int i = kom.size()-1; i >= 0; i--)
    {
        if(kom[i].t == 1) r++;
        else
        {
            if(kom[i].x == 1)
            {
                if(r % 2 == 0) res[pokS++] = kom[i].c;
                else res[pokE--] = kom[i].c;
            }
            else
            {
                if(r % 2 != 0) res[pokS++] = kom[i].c;
                else res[pokE--] = kom[i].c;
            }
        }
    }
    int ind = 0;
    for(int i = 0; i < duz; i++)
    {
        if(res[i] < 'a' || res[i] > 'z') {ind = i; break;}
    }
    for(int i = 0; i < ind; i++) cout << res[i];
    if(r % 2 == 0)cout << s;
    else
    {
        for(int i = s.size()-1; i >= 0; i--) cout << s[i];
    }
    if(ind > 0) {for(int i = ind+s.size(); i < duz; i++) cout << res[i];}
    else
    {
        for(int i = s.size(); i < duz; i++) cout << res[i];
    }
    return 0;
}


Measured memory_bytes: 4804
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;

void print_vector(vector<int> vec){
    for (int item : vec){
        cout << item << flush;
    }
    cout << endl << flush;
}

void print_mat(vector<vector<int>> mat){
    for (vector<int> vec : mat){
        print_vector(vec);
    }
}

void Main(){
    bool test=false;
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> lines(h);
    for (int i=0; i<h; i++){
        cin >> lines[i];
    }

    vector<vector<int>> s(h, vector<int>(w));
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (lines[i][j]=='1') s[i][j] = 1;
            else s[i][j] = 0;
        }
    }
    int best_total = 1 << 30;

    for (int cnt=0; cnt<(1 << (h-1)); cnt++){
        vector<vector<int>> index;
        vector<int> tmp_index;
        int size = 1;
        for (int i=0;i<(h-1);i++){
            tmp_index.push_back(i);
            int cut = (cnt >> i) & 1;
            if (cut){
                size += 1;
                vector<int> tmp(tmp_index);
                index.push_back(tmp);
                tmp_index.clear();
            }
        }
        tmp_index.push_back(h-1);
        index.push_back(tmp_index);
        vector<vector<int>> ss(size, vector<int>(w,0));
        for (int ii=0; ii<size; ii++){
            for (int i=0; i<w; i++){
                ss[ii][i] = 0;
                for (int j : index[ii]){
                    ss[ii][i] += s[j][i];
                }
            }
        }
        if (test) {
            print_mat(index);
            print_mat(ss);
        }
        
        int total = size-1;
        int count = 0;
        bool end = false;
        vector<int> tmp(size, 0);
        for (int i=0; i<w; i++){
            // auto op = [](int a){ return a>k; };
            for (int j=0; j<size; j++){
                tmp[j] += ss[j][i];
            }

            bool flg = false;
            for (int item : tmp){
                if (item>k){
                    flg = true;
                    break;
                }
            }
            if (end) break;
            if (flg){
                total += 1;
                count = 0;
                for (int j=0; j<size; j++){
                    tmp[j] = ss[j][i];
                    if (tmp[j]>k){
                        end = true;
                    }
                }
            }
            if (end) break;
        }

        if (end) continue;        

        if (total < best_total){
            best_total = total;
            // vector<int> result = used;
        }
        if (test) cout << total << endl << endl <<flush;
    }
    cout << best_total;
}

int main(void){
    // std::cin.tie(nullptr);
	// std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 384
//Don't give up too easy bhai
#pragma GCC optimize("-O3")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define double long double
#define inf 1e18

typedef pair<int,int> pii;
 
#define forall(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define vi vector<int>
#define vd vector<double>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define br cout<<"\n"
#define whatis(x) cerr << "var "<<#x << " ==> " << x<<"\n"
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define T int __t;cin>>__t;while(__t--)

void solve()
{
    
}

signed main()
{
    fast;

    int ans=0,n;
    cin>>n;
    int a[n];
    forall(i,0,n) cin>>a[i];

    for(int i=0;i<n;i+=2) if(a[i]&1) ans++;
    cout<<ans;

    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n; cin>>n;
  int b[n-1]={};
  rep(i,n-1){
    cin>>b[i];
  }
  
  if(n==2) cout<<2*b[0]<<endl;
  else if(n==3) cout<<b[0]+b[1]+min(b[0],b[1])<<endl;
  else{
    ll ans=0;
    ans=b[0]+b[n-2];
    rep(i,n-2){
      ans+=min(b[i],b[i+1]);
    }
    cout<<ans<<endl;
  }
}
  



Measured memory_bytes: 256
from itertools import permutations
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

min_time = float('inf')
for combo in permutations([a,b,c,d,e], r=5):
    t = 0
    for val in combo:
        if t % 10 != 0:
            t = ((t // 10)+1)*10
        t+=val
    if t < min_time:
        min_time = t
print(min_time)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        long m = sc.nextLong();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            b[i] = a[i] / 2;
        }
        long lcm = lcm(b);
        for(int i = 0 ; i < a.length ; ++i){
            if(lcm % a[i] == 0){
                System.out.println(0);
                return ;
            }
        }
        if (lcm == 0) System.out.println(0);
        else System.out.println((m / lcm + 1) / 2);
    }

    private static long lcm(long[] a) {
        long res = 1;
        for (long num : a) {
            res = res * num / gcd(res, num);
        }
        return res;
    }

    private static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 62376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W, H, x, y, r;
  cin>>W>>H>>x>>y>>r;
  if(x-r>=0&&x+r<=W && y-r>=0&&y+r<=H){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
 
  return 0;
}


Measured memory_bytes: 3116
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        long result = n;
        if (n % k == 0) {
            result = 0;
        } else {
            while (result != 0) {
                long diff = Math.abs(result - k);
                if (k < diff) {
                    diff = diff % k;
                }
                if (result <= diff) {
                    break;
                }
                result = diff;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string s, ans = ""; cin >> s;
    for (int i = 0; i < s.length(); i++) {
       if (s[i] == '0') ans += '0';
       if (s[i] == '1') ans += '1';
       if (s[i] == 'B' && ans.length() > 0) ans.pop_back();
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     int t,x,y;
    cin>>t >> x >> y;
    cout << min(x,y) <<" ";
    if (t<x+y) cout << x+y-t;
else cout<< 0; 
    return 0;
}


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

typedef long long ll;

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

    int n; cin>>n;
    vector<ll> num(n);
    for (int i=0; i<n; ++i) {
      cin >> num[i];
    }
    int left=0;
    ll cur=0, res=0;
    for (int i=0; i<n; ++i) {
      while (num[i]&cur) {
        cur^=num[left];
        left++;
      }
      res+=i-left+1;
      cur^=num[i];
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
long long n,m,k,sum,p,q,power[10000];
int main(){
	while(true){
		cin>>n>>m>>k;if(!n){break;}
		power[0]=1;
		for(int i=1;i<=n;i++){power[i]=power[i-1]*m;}
		sum=0;
		for(int i=0;i<power[n];i++){
			p=0;
			for(int j=0;j<n;j++){
				q=(i/power[j])%m+1;
				p+=q;
			}
			sum+=max(1LL,p-k);
		}
		cout<<fixed<<setprecision(15)<<1.0*sum/power[n]<<endl;
	}
}

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

int main()
{
    int w,h,k,c=0;
    char s[55][55]={0};
    scanf("%d%d",&h,&w);
    int i,j;
    for(i=1;i<=h;++i)
    {
        getchar();
        for(j=1;j<=w;++j)
            scanf("%c",&s[i][j]);
    }
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
        {
            k=0;
            if(s[i][j]=='.')
            {
                if(s[i][j-1]=='#')k++;
                if(s[i][j+1]=='#')k++;
                if(s[i-1][j-1]=='#')k++;
                if(s[i-1][j+1]=='#')k++;
                if(s[i-1][j]=='#')k++;
                if(s[i+1][j-1]=='#')k++;
                if(s[i+1][j+1]=='#')k++;
                if(s[i+1][j]=='#')k++;
                if(k==0)s[i][j]='0';
                if(k==1)s[i][j]='1';
                if(k==2)s[i][j]='2';
                if(k==3)s[i][j]='3';
                if(k==4)s[i][j]='4';
                if(k==5)s[i][j]='5';
                if(k==6)s[i][j]='6';
                if(k==7)s[i][j]='7';
                if(k==8)s[i][j]='8';
            }
        }
    }
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
            printf("%c",s[i][j]);
        printf("\n");

    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;


int main(void){
  int a, b;
  cin >> a >> b;
  if(b > a){
    swap(a, b);
  }
  while(a && b){
    int t = a;
    a = b;
    b = t % b;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  vec count(3);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    if(a[i]%4==0) {
      count[2]++;
    }
    else if(a[i]%2==0) {
      count[1]++;
    }
    else {
      count[0]++;
    }
  }
  if(count[0]<=count[2]||(count[0]==count[2]+1&&count[1]==0)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		// 列と行intN,intMを取得
		int intN = scanner.nextInt();
		int intM = scanner.nextInt();

		int[][] intAij = new int[intN][intM];
		// intAijの入力
		for (int intI = 0; intI < intN; intI++) {
			for (int intJ = 0; intJ < intM; intJ++) {
				// intAijに入力した数値を与える
				intAij[intI][intJ] = scanner.nextInt();

			}
		}

		int[] intBj = new int[intM];
		// intBjの入力
		for (int intK = 0; intK < intM; intK++) {
			// intBj配列の作成
			intBj[intK] = scanner.nextInt();
		}

		// intN回解intCiを出力
		for (int intX = 0; intX < intN; intX++) {
			// 解intCiの定義と初期化
			int intCi = 0;
			for (int intY = 0; intY < intM; intY++) {
				// intCiの計算
				intCi += intAij[intX][intY] * intBj[intY];
			}
			// intCiの出力
			System.out.println(intCi);
		}
	}
}



Measured memory_bytes: 40492
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a,b,t;
  cin >> a >> b >> t;
  int time = a;
  int ans = 0;
  while(time < t+1){
    ans += b;
    time += a;
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define all(v) (v).begin(),(v).end()
 
#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb fflush(stdout)

const int mod = 1e9 + 7;

const int max_n = 1e5+5;

int fac[max_n];
int ifac[max_n];

int powmod(int a, int n) {
	if (n == 0) return 1;
	int sq = powmod(a, n / 2);
	sq = (sq * 1LL * sq) % mod;
	if (n % 2 == 0) return sq;
	return (sq * 1LL * a) % mod;
}

int newton(int a, int b) {
	if (b > a) return 0;
	int ans = (fac[a] * 1LL * ifac[b])%mod;
	return (ans * 1LL * ifac[a-b]) % mod;
}

VI pos[max_n];

int main () {
	make(n);
	makev(v, n+1);
	fac[0] = 1;
	ifac[0] = 1;
	FOR(i,1,n+2) {
		fac[i] = (fac[i-1] * 1LL * i) % mod;
		ifac[i] = powmod(fac[i], mod - 2);
	}
	FOR(i,0,n+1) {
		pos[v[i]].pb(i);
	}
	int k, l;
	FOR(i,1,n+1) {
		if (pos[i].size() == 2) {
			k = pos[i][0] + 1;
			l = pos[i][1];
		}
	}
	FOR(i,1,n+2) {
		int ans = newton(n, i);
		if (i > 0) {
			int loc = newton(n, i-1) - newton(n-l+k-1, i-1);
			if (loc < 0) loc += mod;
			if (loc >= mod) loc -= mod;
			ans = ans + loc;
			if (ans >= mod) ans -= mod;
			printf("%d\n", ans);
		}
	}
}


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

using namespace std;

#define REP(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF = 1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}
// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s ;
    int n = s.length();
    vector<int> v(n,0);
    rep ( i,n){
        if(s[i]==*"L"){
            //L
            if(i>0&&s[i-1]==*"R") {
                int leftR;
                if(s.substr(0, i).rfind("LR")<INF) {
                    leftR=i-s.substr(0, i).rfind("LR")-1;
                } else {
                    leftR=i;
                }
                v[i]= v[i]+int (leftR/2);
                v[i-1]= v[i-1]+int ((leftR+1)/2);
            }
        }else{
            //R
            if(i<n&&s[i+1]==*"L"){
                int rightL;
                if(s.substr(i+1,n-i).find("LR")< INF){
                     rightL = s.substr(i+1,n-i).find("LR")+1;
                }else{
                     rightL = n-i-1;
                }
                v[i]= v[i]+int (rightL/2);
                v[i+1]= v[i+1]+int ((rightL+1)/2);
            }
        }
    }
    rep(i,n){
        cout << v[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 1104
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n;
    cin >> n;
    if(n>=30)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 3636
// 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
struct Edge{
    int to;
    ll cost;
    Edge(int to, ll cost):to(to), cost(cost){}
};
using EdgeList = vector<vector<Edge>>;
using Vatex = int;
constexpr ll INFL = 1LL << 60;
// ???????????????????????????????????´???????´?????????§??????
// ret[i] == INF??????i????????°?????????
// O(VE)
vector<ll> bellmanford(const EdgeList &G, int start) {
    int N = G.size();
    vector<ll> dist(N, INFL);
    dist[start] = 0;
    rep(cnt, N) {
        bool updated = false;
        rep(i, N){ 
            for(Edge e : G[i]) {
                if(dist[i] < INFL and dist[e.to] > dist[i] + e.cost) {
                    dist[e.to] = dist[i] + e.cost;
                    updated = true;
                    if( cnt == N - 1 ) return {};
                }
            }
        }
        if(not updated) break;
    }
    return dist;
}
int main() {
    int N, M, R; cin >> N >> M >> R;
    EdgeList E(N);
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        E[a].push_back(Edge(b, c));
    }
    auto dist = bellmanford(E, R);
    if(dist.size() == 0) cout << "NEGATIVE CYCLE" << endl;
    else for(ll d : dist) cout << (d < INFL ? to_string(d) : "INF") << endl;
    return 0;
}

Measured memory_bytes: 3324
n = gets.to_i

c = {}
num = 0

(1..n).each do |i|
  h, t = i.to_s[0].to_i, i.to_s[-1].to_i

  if c[h].nil?
    c[h] = {}
    c[h][t] = 1
  elsif !c[h].nil? && c[h][t].nil?
    c[h][t] = 1
  else
    c[h][t] += 1
  end
end

(0..9).each do |i|
  (0..9).each do |j|
    if !c[i].nil? && !c[j].nil?
      if !c[i][j].nil? && !c[j][i].nil?
        num += c[i][j] * c[j][i]
      end
    end
  end
end
p num

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, h, sum = 0;
    cin >> h >> n;

    for (int i=0; i<n; i++){
        int aux;
        cin >> aux;
        sum += aux;
    }


    if (sum >= h)  cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
    for(ll i=0;i<5;i++){
        ll tmp;
        cin >> tmp;
        if(tmp==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();

		String S = sc.next();

		int[] kukan = new int[2*Q];
		for(int i = 0 ; i < 2*Q ; i++){
			kukan[i] = sc.nextInt()-1;
		}
		sc.close();

		int[] AC = new int[N];


		int count = 0;
		for(int i = 0 ; i < N-1 ; i++){
			if(S.substring(i, i+1).equals("A") && S.substring(i+1, i+2).equals("C")){
				count++;
			}
			AC[i+1] = count;
		}

/*
		for(int i = 0 ; i < N ; i++){
			System.out.println(AC[i]);
		}
*/
		for(int i = 0 ; i < 2*Q ; i+=2){
				System.out.println(AC[kukan[i+1]] - AC[kukan[i]]);
		}



	}
}

Measured memory_bytes: 88260
#include <iostream>
#include <string>

using namespace std;

class Stack
{
private:
	int operand[100];
	int size;

public:
	Stack()
	: size(0) {
		for(auto&& e : operand) {
			e = 0;
		}
	}

	void push(int x) {
		operand[size++] = x;
	}

	int pop() {
		return operand[--size];
	}
};

int main() {
	ios::sync_with_stdio(false);

	string input;
	Stack stack;

	while(cin >> input) {
		if('+' == input.front()) {
			int a = stack.pop();
			int b = stack.pop();
			stack.push(b + a);
		} else if('-' == input.front()) {
			int a = stack.pop();
			int b = stack.pop();
			stack.push(b - a);
		} else if('*' == input.front()) {
			int a = stack.pop();
			int b = stack.pop();
			stack.push(b * a);
		} else {
			stack.push(stoi(input));
		}
	}
	cout << stack.pop() << endl;

	return 0;
}


Measured memory_bytes: 3204
import java.util.Scanner;

//Aizu Buried Treasure
public class Main{

	int INF = 1<<29;
	int w, h, f, m, o;
	int[][] a;
	int[][][] dp, mem;
	
	int get(int H, int S, int p, int rest){
		if(rest<=1||p<0||w<=p)return INF;
		if(mem[S][p][rest]!=INF)return mem[S][p][rest];
		int res = INF;
		if(p-1>=0){
			int np = p-1, ns = S|(1<<np), nr = rest-1, c = 0;
			if(((S>>np)&1)==0){
				if(a[H][np]>0)nr = Math.min(m, nr+a[H][np]);
				else c+=-a[H][np];
			}
			res = Math.min(res, c+get(H, ns, np, nr));
		}
		if(p+1<w){
			int np = p+1, ns = S|(1<<np), nr = rest-1, c = 0;
			if(((S>>np)&1)==0){
				if(a[H][np]>0)nr = Math.min(m, nr+a[H][np]);
				else c+=-a[H][np];
			}
			res = Math.min(res, c+get(H, ns, np, nr));
		}
		int np = p, ns = 1<<p, nr = rest-1, c = 0;
		if(a[H+1][np]>0)nr = Math.min(m, nr+a[H+1][np]);
		else c+=-a[H+1][np];
		res = Math.min(res, c+dp[ns][p][nr]);
		return mem[S][p][rest] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 1<<29;
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			f = sc.nextInt(); m = sc.nextInt(); o = sc.nextInt();
			a = new int[h][w];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)a[i][j]=sc.nextInt();
			dp = new int[1<<w][w][m+1];
			for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=0;k<=m;k++)dp[i][j][k]=INF;
			for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=1;k<=m;k++)dp[i][j][k]=0;
			for(int H=h-2;H>=0;H--){
				mem = new int[1<<w][w][m+1];
				for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=0;k<=m;k++)mem[i][j][k]=INF;
				for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=0;k<=m;k++)get(H, i|(1<<j), j, k);
				dp = mem;
			}
			int res = INF;
			for(int j=0;j<w;j++)if(o-1>0){
				if(a[0][j]>0)res = Math.min(res, dp[1<<j][j][Math.min(m, o-1+a[0][j])]);
				else res = Math.min(res, -a[0][j]+dp[1<<j][j][o-1]);
			}
			System.out.println(f<res?"NA":res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0