akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> links(n);
    for (auto i : irange(0L, m)) {
        int64_t s, t;
        cin >> s >> t;
        --s;
        --t;
        links[s].push_back(t);
    }

    vector<double> e(n), e2(n);
    for (auto s : irange(0L, n - 1) | reversed) {
        double se = 0, me = 0;
        for (auto t : links[s]) {
            se += e[t];
            me = max(me, e[t]);
        }
        e[s] = se / links[s].size() + 1;
        if (links[s].size() > 1) {
            e2[s] = e[s] - ((se - me) / (links[s].size() - 1) + 1);
        }
    }

    double ans = e[0];
    vector<double> p(n);
    p[0] = 1;
    for (auto s : irange(0L, n)) {
        ans = min(ans, e[0] - p[s] * e2[s]);

        for (auto t : links[s]) {
            p[t] += p[s] / links[s].size();
        }
    }

    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 2560
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    map<int,int> mp;
    rep(i, n - 1){
        int a;
        cin >> a;
        a--;
        mp[a]++;
    }

    rep(i, n){
        cout << mp[i] << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int t,x;
    cin>>t>>x;
    double ans = t/(double)x;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll d, n;
int main(void){
    // Your code here!
    cin >> d >> n;
    if (n < 100) cout << pow(100, d) * n << endl;
    else if (d < 2) cout << pow(100, d) * 101 << endl;
    else cout << 1010000 << endl;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
i = 0
j = 0
ans = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(h):
  a = input().split()
  for j in range(w):
    if a[j] == "snuke":
      print(ans[j]+str(i+1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<int>G[100001];
int dp[100001];
int chi(int v)
{
	if(dp[v]>=0)return dp[v];
	int ans=0;
	for(int i=0;i<G[v].size();i++)
	{
		ans=max(ans,chi(G[v][i]));
	}
	return dp[v]=ans+1;
}
int main() {
	int n,m;
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,chi(i));
	}
	cout<<ans-1;
	return 0;
}


Measured memory_bytes: 11508
n,q = map(int, input().split())
tuv=[]
for i in range(q):
  tuv.append(input())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
 
uf = UnionFind(n)

for i in range(q):
  t,u,v=tuv[i].split(" ")
  u=int(u)
  v=int(v)
  if t=="0":
    uf.union(u,v)
  else:
    if uf.same(u,v):
      print(1)
    else:
      print(0)
    

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;


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

  vector<char> s(4); rep(i,0,3) cin >> s[i];
  sort(s.begin(), s.end());
  if (s[0]==s[1] and s[2]==s[3] and s[1] != s[2]) END("Yes"); else END("No");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	int t;
	int n;
	int s,f;
	int i;
	int a=0,b;
	
	while(1){
		a=0;
		scanf("%d",&t);
		if(t==0) break;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			a=a+(f-s);
		}
			if(t<=a){
				printf("OK\n");
			}else{
				b=t-a;
				printf("%d\n",b);
		}
	}
	return 0;
}

Measured memory_bytes: 1040
// C - 2D Plane 2N Points
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
// #define allr(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N; cin>>N;
	vvi AB(N, vi(2));
	vvi CD(N, vi(2));
	rep(i, N) cin>>AB[i][0]>>AB[i][1];
	rep(i, N) cin>>CD[i][0]>>CD[i][1];

	sort(all(CD));
	// sort(allr(AB), [](vi a, vi b){ return a[1] < b[1]; });
	sort(all(AB), [](vi a, vi b){ return a[1] > b[1]; });

	vvi dim_b(N, vi());
	rep(b, N)
		rep(r, N)
			if(AB[r][0] < CD[b][0] && AB[r][1] < CD[b][1])
				dim_b[b].push_back(r);

	vi vis_r(N, false);
	rep(b, N)
		for(int r:dim_b[b])
			if(!vis_r[r]){ vis_r[r] = true; break; }

	int ans = 0;
	rep(i, N) ans += vis_r[i];
	cout<< ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define MOD 1000000007
#define NIL -1
using namespace std;
typedef long long ll;

int N;
vector<int> G[200200];
int color[200200];

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while (!S.empty()){
        int u = S.top();
        S.pop();
        rep(i, (int)G[u].size()){
            int v = G[u][i];
            if (color[v] == NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assigncolor(){
    int id = 1;
    rep(i, N){
        color[i] = NIL;
    }
    rep(u, N){
        if (color[u] == NIL){
            dfs(u, id++);
        }
    }
}


int main(){
    int M;
    cin >> N >> M;
    int A[M+1];
    int B[M+1];
    rep(i, M) cin >> A[i] >> B[i];

    rep(i, M){
        G[A[i]-1].push_back(B[i]-1);
        G[B[i]-1].push_back(A[i]-1);
    }

    assigncolor();

    vector<int> countgrp(N+1, 0);
    int ans = 0;

    rep(i, N){
        // cout << color[i] << endl;
        countgrp[color[i]] += 1;
        if (ans < countgrp[color[i]]){
            ans = countgrp[color[i]];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18032
#include<bits/stdc++.h>
// #include"myfile.h"

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


void solve() {
	int x;
	cin >> x;
	int tot = (x / 500) * 1000 + ((x % 500) / 5) * 5;
	cout << tot << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<int> ar(n);
    int ans = 0;
    rep(i,k){
        int a; cin >> a;
        rep(j,a){
            int b; cin >> b;
            ar[b-1]++;
        }
    }
    rep(i,n) if (ar[i] == 0) ans++;
    cout << ans << endl;
}

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

long long int N, a[26], m[26], i, c;
char s[114];

int main(){
    scanf("%s", s);
    N = strlen(s);
    fill(a, a + 26, -1);
    for(int i = 0; i < N; ++i){
        c = s[i] - 97;
        m[c] = max(m[c], i - a[c] - 1);
        a[c] = i;
    }
    for(int i = 0; i < 26; ++i){
        m[i] = max(m[i], N - a[i] - 1);
    }
    cout << *min_element(m, m + 26) << endl;
    return 0;
}


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

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

using namespace std;

int main(){
	string s1,s2,s3;
	int q,t=0; cin>>s1>>q;
	rep(_,q){
		int type; scanf("%d",&type); type--;
		if(type==0){
			t^=1;
		}
		else{
			char c; scanf("%d %c",&type,&c); type--;
			if(type==t){
				s2+=c;
			}
			else{
				s3+=c;
			}
		}
	}

	if(t==0){
		reverse(s2.begin(),s2.end());
		cout<<s2<<s1<<s3<<'\n';
	}
	else{
		reverse(s3.begin(),s3.end());
		reverse(s1.begin(),s1.end());
		cout<<s3<<s1<<s2<<'\n';
	}

	return 0;
}


Measured memory_bytes: 1088
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

use rand::prelude::*;

const CN: usize = 26;

fn calc(cv: &[isize], sv: &[Vec<isize>], tv: &[usize]) -> isize {
    let mut last = vec![0; CN];
    let mut res = 0;
    for i in 0..sv.len() {
        let t = tv[i];
        res += sv[i][t];
        last[t] = i + 1;
        for j in 0..CN {
            res -= cv[j] * (i + 1 - last[j]) as isize;
        }
    }
    res
}

fn gen_tv(rng: &mut rand::rngs::ThreadRng, d: usize) -> Vec<usize> {
    (0..d)
        .into_iter()
        .map(|_| rng.gen::<usize>() % CN)
        .collect::<Vec<_>>()
}

fn main() {
    input! {
        d: usize,
        cv: [isize; CN],
        sv: [[isize; CN]; d],
    };

    let mut rng = rand::thread_rng();
    let mut tv = gen_tv(&mut rng, d);
    let mut res = calc(&cv, &sv, &tv);
    for _ in 0..20000 {
        let tv2 = gen_tv(&mut rng, d);
        let p = calc(&cv, &sv, &tv2);
        if p > res {
            tv = tv2;
            res = p;
        }
    }
    for _ in 0..400000 {
        let di = rng.gen::<usize>() % d;
        let q = rng.gen::<usize>() % CN;
        let old = tv[di];
        tv[di] = q;
        let p = calc(&cv, &sv, &tv);
        if p > res {
            res = p;
        } else {
            tv[di] = old;
        }
    }
    println!("{}", tv.into_iter().map(|x| x + 1).join("\n"));
}


Measured memory_bytes: 2724
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
 
		
		for(int i=1;i<101;i++){
			if(i>a && i >b){
				break;
			}

			if(a%i ==0&&b%i ==0){
				list.add(i);
			}
		}
        // System.out.println(list);
		Collections.reverse(list);


        System.out.println(list.get(k-1));
 
	}
}


Measured memory_bytes: 23636
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-15 21:34:24
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
string s;
int L[200010];
set<int> S[200010][2];
bool ok[200010];

int main()
{
  cin >> N >> M >> s;
  for (auto i = 0; i < N; i++)
  {
    if (s[i] == 'A')
    {
      L[i] = 0;
    }
    else
    {
      L[i] = 1;
    }
  }
  for (auto i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    S[b][L[a]].insert(a);
    S[a][L[b]].insert(b);
  }
  fill(ok, ok + N, true);
  queue<int> Q;
  for (auto i = 0; i < N; i++)
  {
    // cerr << "S[" << i << "][0] = " << (int)S[i][0].empty() << endl;
    // cerr << "S[" << i << "][1] = " << (int)S[i][1].empty() << endl;
    if (S[i][0].empty() || S[i][1].empty())
    {
      Q.push(i);
    }
  }
  while (!Q.empty())
  {
    int now = Q.front();
    Q.pop();
    if (!ok[now])
    {
      continue;
    }
    ok[now] = false;
    for (auto k = 0; k < 2; k++)
    {
      if (S[now][k].empty())
      {
        continue;
      }
      for (auto x : S[now][k])
      {
        S[x][L[now]].erase(now);
        if (S[x][L[now]].empty())
        {
          Q.push(x);
        }
      }
    }
  }
  bool first[2] = {false, false};
  for (auto i = 0; i < N; i++)
  {
    if (ok[i])
    {
      first[L[i]] = true;
    }
  }
  if (first[0] && first[1])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (int i=0; i<n; i++)
    cin >> a.at(i);
  for (int i=0; i<m; i++)
    cin >> b.at(i);
  
  bool CAN = false;
  for (int i=0; i<n-m+1; i++) { //縦にずらす
    for (int j=0; j<n-m+1; j++) { //横にずらす
      bool can = true;
      for (int k=0; k<m; k++) { // 縦の探査
        for (int l=0; l<m; l++) { // 横の探査
          if (b.at(k).at(l) != a.at(i+k).at(j+l)) {
            can = false;
            break;
          }
        }
        if (!can) break;
      }
      if (can) {
        CAN = true;
        break;
      }
    }
    if (CAN) break;
  }
  if (CAN) cout << "Yes" << endl;
  else cout << "No" << endl;
}
      

Measured memory_bytes: 256
N,W=map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(110000)] for i in range(110)]
for i in range(1,N+1):
  for j in range(W+1):
    dp[i][j]=dp[i-1][j]
    if j-L[i-1][0]>=0:
      dp[i][j]=max(dp[i][j],dp[i-1][j-L[i-1][0]]+L[i-1][1])
ans=dp[N][W]
print(ans)

Measured memory_bytes: 203324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int sum=0; int q=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='c'){cout << "No" << endl;}
    else if(s[i]=='a'){
      if(sum<a+b){cout << "Yes" << endl; sum++;}
      else{cout << "No" << endl;}
    }
    else{
      if(sum<a+b && q<b){cout << "Yes" << endl; sum++; q++;}
      else{cout << "No" << endl;}
    }
  }
}

Measured memory_bytes: 896
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n, m;
	cin >> n;
	VI d(n);
	rep(i, n) cin >> d[i];
	cin >> m;
	VI t(m);

	rep(i, m) cin >> t[i];

	sort(all(d));
	sort(all(t));
	bool flag = true;

	int j = 0;
	rep(i, m) {
		while (j < n && d[j] < t[i]) j++;
		if (j == n || d[j] != t[i]) {
			flag = false;
			break;
		}
		j++;
	}

	cout << (flag ? "YES" : "NO") << endl;
}



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

	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

const int L = 1E6 + 10;

ll F[L], I[L];

ll MOD = 998244353;

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b % 2) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

void init() {
	F[0] = 1;
	for (int i = 1;i <= 1000000;i++) F[i] = (F[i - 1] * i) % MOD;
	I[1000000] = power(F[1000000], MOD - 2);
    for (int i = 1000000;i >= 1;i--) I[i - 1] = (I[i] * i) % MOD;
    return;
}

ll inv(ll x) {
	return (I[x] * F[x - 1]) % MOD;
}

ll nchoosek(ll x, ll y) {
	return (F[x] * ((I[y] * I[x - y]) % MOD)) % MOD;
}

ll cal(int a, int b, int A, int B) {
	if (a > A || b > B) return 0;
	ll sol = nchoosek(a + b, a) * nchoosek(A + B - a - b, A - a);
	sol %= MOD;
	sol *= power(nchoosek(A + B, A), MOD - 2);
	sol %= MOD;
	return sol;
}

ll solve(int N, int M) {
	// Type A: N, Type B: M.
	ll p = (N * inv(N + M)) % MOD; // specific position is A.
	ll res = 1; // Last element is A.
	ll crt = 1; // Num of A is strictly bigger than B
	ll eq = 0;
	for (int i = 1;i < N + M;i++) {
		// Update probability.
		int j = i - 1;
		if (j % 2 == 0) {
			ll now = crt;
			eq = cal(j / 2, j / 2 + 1, N - 1, M);
			now += MOD - (((eq * (j / 2 + 1)) % MOD) * inv(j + 1)) % MOD;
			now %= MOD;
			res += (eq * inv(2)) % MOD;
			res %= MOD;
			crt = now;
		}
		else {
			ll now = crt;
			if (eq > 0) {
				int a = j / 2;
				int b = j / 2 + 1;
				if (N - 1 > a) {
					eq *= (N - 1 - a);
					eq %= MOD;
					eq *= inv(N + M - 1 - a - b);
					eq %= MOD;
					now += eq;
					now %= MOD;
				}
			}
			crt = now;
		}
		res += crt;
		res %= MOD;
	}
	return (res * p) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    init();
    ll sol = solve(N, M);
    sol += solve(M, N);
    cout << sol % MOD << endl;
    return 0;
}

Measured memory_bytes: 15872
import java.util.*;
class Main
{
public static void main (String[] args)
{
Scanner sc =new Scanner(System.in);
int ans=0;
int n= sc.nextInt();
int[] a= new int[100];
Arrays.fill(a,0);
for(int i=0;i<n;i++)
a[sc.nextInt()-1]++;
for(int i=0;i<100;i++)
if(a[i]>0)
ans++;
System.out.println(ans);
}
}

Measured memory_bytes: 24148
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int color[200000] = {};
int visited[200000] = {};
vector<int> vertexs[200000];
int main() {
	int n, m, query;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	vector<tuple<int, int, int>> wow;
	cin >> query;
	REP(i, query) {
		int a, b, c;
		cin >> a >> b >> c;
		wow.push_back(make_tuple(a, b, c));
	}
	for (int i = query - 1;i >= 0;--i) {
		if (color[get<0>(wow[i])] == 0) color[get<0>(wow[i])] = get<2>(wow[i]);
		if (visited[get<0>(wow[i])] < get<1>(wow[i])) {
			//OKならば
			visited[get<0>(wow[i])] = get<1>(wow[i]);
			queue<pair<int, int>> nya;
			nya.push(make_pair(get<1>(wow[i]),get<0>(wow[i])));
			if (color[get<0>(wow[i])] == 0) color[get<0>(wow[i])] = get<2>(wow[i]);
			while (nya.empty() == false) {
				pair<int, int> now = nya.front();
				nya.pop();
				now.first--;
				for (int q = 0;q < vertexs[now.second].size();++q) {
					if (color[vertexs[now.second][q]] == 0) color[vertexs[now.second][q]] = get<2>(wow[i]);
					if (visited[vertexs[now.second][q]] < now.first) {
						visited[vertexs[now.second][q]] = now.first;
						nya.push(make_pair(now.first, vertexs[now.second][q]));
					}
				}
			}
		}
	}
	for (int i = 1;i <= n;++i) {
		cout << color[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12272
n,k = gets.split.map &:to_i
a = gets.split

h = Hash.new 0

a.each{|t|
  h[t]+=1
}

hh = h.sort{|(k1, v1), (k2, v2)| v1 <=> v2 }
del = [h.size-k, 0].max

a = 0
hh.each.with_index{|t,i|
  a += t[1] if i<del
}

p a

Measured memory_bytes: 47344
int main(){
    int H,W;
    int i=0;
    int j=0;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0)
        break;
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i%2==0)
                if(j%2!=0)
                printf(".");
                else
                printf("#");
                else
                if(j%2==0)
                printf(".");
                else
                printf("#");
            }
            
            printf("\n");
        }
        printf("\n");
    }
}

Measured memory_bytes: 1856
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))

Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, k,   y = 2, m,h,s ;
double a[MAXX], b[MAXX], c[MAXX];
long double f = 0, x, ans = 0;
vector<ll> adj[MAXX];
bool used[MAXX];
ll d[MAXX];
ll p[MAXX];
queue<ll> q;

signed main()
{
	FAST;
	cin >> n;
	for(ll i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a+n);
	f = a[0];
	for(ll i = 1; i < n; i++){
		f = (f+a[i])/2;
	}
	cout << fixed << setprecision(14) <<  f;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi a(N);
    rep(i,N) cin>>a[i];
    int zero=0,one=0,two=0;
    rep(i,N) {
        if(a[i]%4==0) two++;
        else if(a[i]%2==0) one++;
        else zero++;
    }
    if(one==0) {
        if(zero<=two+1) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else {
        if(zero<=two) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){
    char W[11],T[1000];
    int i,count=0;
    
    scanf("%s",W);
    while(scanf("%s",T),strcmp(T,"END_OF_TEXT")){
        for(i=0;T[i]!='\0';i++){
            T[i]=tolower(T[i]);
        }
        
        if(strcmp(W,T)==0) count+=1;
    }
    
    printf("%d\n",count);
    
    return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, c;
    cin >> n >> c;
    vector<vector<int>> d(c, vector<int>(c));
    vector<vector<int>> board(n, vector<int>(n));
    vector<vector<int>> S(3, vector<int>(c, 0));
    for(int i = 0; i < c; ++i){
        for(int j = 0; j < c; ++j)  cin >> d[i][j];
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> board[i][j];
            --board[i][j];
            ++S[(i + j) % 3][board[i][j]];
        }
    }
    int ans = INF;
    for(int x = 0; x < c; ++x){
        int addx = 0;
        for(int i = 0; i < c; ++i)  addx += S[0][i] * d[i][x];
        int sum = addx;
        for(int y = 0; y < c; ++y){
            if(y == x)  continue;
            int addy = 0;
            for(int i = 0; i < c; ++i)  addy += S[1][i] * d[i][y];
            sum += addy;
            for(int z = 0; z < c; ++z){
                if(z == x || z == y)    continue;
                int addz = 0;
                for(int i = 0; i < c; ++i)  addz += S[2][i] * d[i][z];
                sum += addz;
                chmin(ans, sum);
                sum -= addz;
            }
            sum -= addy;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    for(int i=1; i<=b; i++){
        int tmp = (i*a)%b;
        if(tmp == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
 
signed main(){
    string s, t;    cin >> s >> t;
    set <string> anstr;
    rep(i, s.size() - t.size() + 1){
        bool flag = true;
        rep(j, t.size()){
            if(s[i + j] == t[j] || s[i + j] == '?');
            else{
                flag = false;
                break;
            }
        }
        if(flag){
            string va = "";
            rep(j, s.size()){
                if(i == j){
                    va += t;
                    j += t.size() - 1;
                }
                else if(s[j] == '?')va += 'a';
                else va += s[j];
            }
            anstr.insert(va);
        }
    }
    cout << (anstr.size() == 0 ? "UNRESTORABLE" : *anstr.begin()) << endl;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

ans=0
for i in range(k):
    for j in range(k-i):
        a2=a*(2**i)
        b2=b*(2**j)
        c2=c*(2**(k-i-j))
        if a2<b2 and b2<c2:
            ans+=1
            break
        else:
            continue

if ans==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9076
n=int(input())
x=list(map(int,input().split()))
x.sort()
min = 10**15
su=0
for j in range(x[0],x[n-1]):
    for i in x:
        su=(i-j)**2+su  
    if min>su:
        min=su
    su = 0
if min==10**15:
    print(0)
else:
    print(min)

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

ll pn[51],bn[51];

ll solve(ll n,ll x){
	if(n==0)return x;
	else if(x<=1)return 0;
	else if(x<=1+bn[n-1])return solve(n-1,x-1);
	else if(x==bn[n-1]+2)return pn[n-1]+1;
	else if(x<=bn[n]-1)return pn[n-1]+1+solve(n-1,x-2-bn[n-1]);
	else return pn[n];
}

int main(){
	ll n,x;
	cin>>n>>x;
	pn[0]=1;bn[0]=1;
	for(int i=0;i<50;i++){
		pn[i+1]=1+2*pn[i];
		bn[i+1]=3+2*bn[i];
	}

	cout<<solve(n,x)<<endl;
	return 0;
}


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int a;
  cin >> a;
  int ans = 1;

  repi(i, 2, a + 1) {
    int p = i * i;
    for (int j = 2;; j++) {
      if (p > a) break;
      ans = max(ans, p);
      p *= i;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  if(n<=0 and x>=0){
    cout<<"Zero"<<endl;
  }
  else if(n>0 and x>0){
    cout<<"Positive"<<endl;
  }
  else{
    int count;
    count=abs(n-x)+1;
    if(count%2==0){
      cout<<"Positive"<<endl;
    }
    else{
      cout<<"Negative"<<endl;
    }
  }
}

Measured memory_bytes: 256
// Problem : F - Knapsack for All Subsets
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 

int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
      
        return (y%2 == 0)? p : (x * p) % m; 
    } 

int solve(){

    int n,s;cin>>n>>s;
    int a[n];
    inputarr(a,n);
    // int dp[2*s];
    vi dp(2*s+1,0);
    // memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<n;i++){
        vi temp(2*s+1,0);
        for(int j=0;j<s;j++){
        	if(a[i]+j>s) break;
            if(j==0){
                    temp[a[i]]=power(2,i,MM);
            }
            else
                temp[a[i]+j]+=dp[j];
            temp[a[i]+j]%=MM;
        }
        for(int j=1;j<=s;j++){
            dp[j]*=2;
            dp[j]+=temp[j];
            dp[j]%=MM;
        }
        // trace(dp[a[i]],temp[a[i]]);
    }
    cout<<dp[s];
    

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
    

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

int main() {
    int n, x;
    cin >> n >> x;
    int d = 0, ans = 1;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        d += l;
        if (d > x) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, m;
   while (cin >> n >> m, n) {
      vector<pair<int, int>> vp;
      int sum = 0;
      for (int i = 0; i < n; i++) {
         int d, p;
         cin >> d >> p;
         sum += p;
         vp.push_back(make_pair(p, d));
      }
      sort(vp.begin(), vp.end());
      reverse(vp.begin(), vp.end());
      int t = 0;
      for (int i = 0; i < n; i++) {
         while (vp[i].second != 0) {
            if (m > 0) {
               m--;
            } else {
               t += vp[i].first;
            }
            vp[i].second--;
         }
      }
      cout << t << endl;
   }

   return 0;
}


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

int main(){
	int n, l, sum=0;
	cin >> n >> l;
	int p[n];

	for(int i=0; i<n; i++){
		cin >> p[i];
	}

    for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(p[i] > p[j]){
				int number = p[i];
				p[i] = p[j];
				p[j] = number;
			}
		}
	}

    for(int i=0; i<l; i++){
    	sum += p[i];
    }

    cout << sum << endl;

	

	return 0;
}

Measured memory_bytes: 3620
import java.util.* ;
public class Main{
 public static void main(String []args){
 	Scanner sc = new Scanner(System.in) ;
    long  a = sc.nextInt() ; 
    long  b = sc.nextInt() ;
    System.out.println( (a*b)/gcd(a,b ) ) ;
    
 }
  static long gcd(long a , long b ) { 
   if (b == 0 ) 
     return a ;
    else
      return gcd(b , a%b ) ;
  }
  
}

Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String line = sc.nextLine();
        String[] lines = line.split(" ");

        int A = Integer.parseInt(lines[0]);
        int B = Integer.parseInt(lines[1]);

        System.out.println(A*B);
    }
}

Measured memory_bytes: 35724
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n,m;
int ta[20][20];
int p[20];
int main(){
  cin>>n>>m;
  rep(i,m){
    int k,s;
    cin>>k;
    rep(j,k){
      cin>>s;
      s--;
      ta[i][s]=1;
    }
  }
  rep(i,m)cin>>p[i];

  int ans=0;
  rep(i,1<<n){
    int cnt[11];
    rep(j,m)cnt[j]=0;

    int l=0;
    rep(j,n){
      if(i&(1<<j)){//スイッチjが押されている
        rep(k,m)if(ta[k][j])cnt[k]++;
      }
    }
    rep(j,m)if(cnt[j]%2==p[j])l++;
    if(l==m)ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0019

int main() {
	int d;
	cin >> d;
	long long int sum = 1;
	while (d > 1) sum *= d--;
	cout << sum << endl;
	return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<int>ans(n);
  for(int i=0;i<n;i++) ans[i]=0;
  char left='R';
  int num=1;
  int i=1;
  int x;
  while(i<n){
    if(left=='R'){
      if(s[i]==left) num++;
      else{
        ans[i]+=num/2;
        if(num%2==0) ans[i-1]+=num/2;
        else ans[i-1]+=num/2+1;
        if(i==n-1){
          ans[n-1]+=1;
        }
        left='L';
        num=1;
        x=i;
      }
    }
    else{
      if(s[i]==left){
        num++;
        if(i==n-1){
          ans[x-1]+=num/2;
          if(num%2==0) ans[x]+=num/2;
          else ans[x]+=num/2+1;
        }
      }
      else{
        ans[x-1]+=num/2;
        if(num%2==0) ans[x]+=num/2;
        else ans[x]+=num/2+1;
        left='R';
        num=1;
      }
    }
    i++;
  }
  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
}


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

int main(){
  int n,x=0,c=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<n;i++){
    if(s[i]=='I')
      x++;
    else
      x--;
    c = max(c,x);
  }
  cout << c << endl;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

int n;
// int graph[100100][100100];
vector<P>graph[100100];
int reach[100100];

void dfs(int x, int p){
	// cout << x << endl;
	// for(auto i: graph[x])cout << i.first << " " << i.second << endl;
	for(auto i: graph[x]){
		int dst = i.first;int weight = i.second;
		// cout << p << " "<< x << " " << dst << endl;
		if(dst==p)continue;
		reach[dst] = reach[x] + weight;
		dfs(dst, x);
	}
}

int main(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int v, u, w;
		cin >> u >> v >> w;
		u--;v--;
		graph[u].push_back(P(v,w));
		graph[v].push_back(P(u,w));
	}
	dfs(0,-1);

	for(int i = 0; i < n; i++){
		if(reach[i]%2 == 0)cout << "0" << endl;
		else cout << "1" << endl;
	}
	// for(int i = 0; i < n; i++)cout << reach[i] << " ";

	// cout <<  endl;
}

Measured memory_bytes: 9856
N = int(input())
A = list(map(int,input().split()))
dic = {}
cnt = 0
for i in range(N):
  if A[i] < 400:
    dic[0] = 1
  elif A[i] < 800:
    dic[1] = 1
  elif A[i] < 1200:
    dic[2] = 1
  elif A[i] < 1600:
    dic[3] = 1
  elif A[i] < 2000:
    dic[4] = 1
  elif A[i] < 2400:
    dic[5] = 1
  elif A[i] < 2800:
    dic[6] = 1
  elif A[i] < 3200:
    dic[7] = 1
  else:
    dic[8] = 1
    cnt += 1
if cnt > 0:
  if len(dic) == 1:
    print(1,cnt)
  else:
    print(len(dic) - 1,len(dic) + cnt - 1)
else:
  print(len(dic),len(dic))

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val N = nextLong()
    var n = Math.sqrt(N.toDouble()).toLong()
    while (N % n != 0L && n > 1) n -= 1
    if (n == 0L) println(N - 1)
    else {
        val m = N / n
        println((n - 1) + (m - 1))
    }
}
fun next() = readLine()!!
fun nextLong() = next().toLong()

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

int main()
{
  int N , K ,x ;
  x = 1 ;
  
  cin >> N >> K ;
  
  for(int i=0; i<N; i++)
  {
    if(x<K)
      x += x ;
    else
      x += K ;
  }
  
  cout << x << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

/*string itoaX(int a){
  string s;
  int c;
  int b=a;
  for(c=0;a>0;c++){a/=10; s[c]='\0';}
  for(int i=c-1;i>=0;i--){
    char te=b%10+'0';
    s[i]=te;
  }
  return s;
}*/

main(){
  
  while(1){

    char ans[25][100024];
    int n,m;
  
    scanf("%d",&n);

    if(n==0) break;

    scanf("%s",ans[0]);

   for(int i=1;i<=n;i++){
     m=strlen(ans[i-1]);
     strcpy(ans[i],"\0");
      int co=1;
      char temp=ans[i-1][0];
      for(int j=1;j<m;j++){
	if(temp==ans[i-1][j]) co++;
	else{
	  sprintf(ans[i],"%s%d",ans[i],co);
	  char as[2];
	  as[0]=ans[i-1][j-1];
	  as[1]='\0';
	  strcat(ans[i],as);
	  //	  sprintf(ans[i],"%s%c",ans[i],ans[i-1][j-1]);
	  //printf("%d + %c =  %s\n",co,ans[i-1][j-1],ans[i]);
	  co=1;
	  temp=ans[i-1][j];
	}
      }
      char as[2];
      as[0]=ans[i-1][m-1];
      as[1]='\0';
      sprintf(ans[i],"%s%d",ans[i],co);
      strcat(ans[i],as);

      //sprintf(ans[i],"%s%c",ans[i],ans[i-1][m-1]);
      //printf("%d + %c =  %s\n",co,ans[i-1][m-1],ans[i]);
    }
    
    //  for(i=1;i<=n;i++)
   printf("%s\n",ans[n]);
  }
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>

using namespace std;

int n;

int main(void)
{
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(i % 2 == 0) continue;
		int cnt = 0;
		for(int j = 1; j <= i; j++){
			if(i % j == 0) cnt++;
		}
		if(cnt == 8) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int i = min(a, b);
    while(1){
        if (a % i == 0 && b % i == 0) k--;
        if (k == 0) {
            cout << i << endl;
            break;
        }
        i--;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
st_con = [[i for i in map(int,input().split())] for j in range(N)]
rieki = [[i for i in map(int,input().split())] for j in range(N)]

ans = -10**9
for i in range(1,2**10):
    a = 0
    for j in range(N):
        count = 0 
        for h in range(10):
            if (i>>h) & st_con[j][h] and (i>>h) & 1:
                count += 1
        a += rieki[j][count]
    
    if ans < a : ans = a 
print("{}".format(ans))
                




Measured memory_bytes: 3064
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;


int main() {
	int N, M;
	cin >> N >> M;
	int a = 100 * (N - M) + 1900 * M;
	cout << a * pow(2, M) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i=0; i<(n); i++)
#define SZ(x) ((int)(x).size())

int main() {
	string s, t; cin >> s;
	REP(i, SZ(s)) {
		if (s[i] == '0')t += '0';
		if (s[i] == '1')t += '1';
		if (s[i] == 'B')if(!t.empty())t.pop_back();
	}
	cout << t << endl;
}

Measured memory_bytes: 256