akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
int L = 1000000007;
using namespace std;
ll a[100050] = {};

int main()
{
	int N; cin >> N;
	vector<int> A(N + 2);
	A[0] = 0;
	A[N + 1] = 0;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		sum += abs(A[i] - A[i - 1]);
	}
	sum += abs(A[N]);

	for (int i = 1; i <= N; i++) {
		if ((A[i] - A[i - 1]) * (A[i + 1] - A[i]) < 0) cout << sum + abs(A[i + 1] - A[i - 1]) - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) << endl;
		else cout << sum << endl;
	}

	return 0;
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);

long long x, y;
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> x >> y;

	long long ans = 0;
	if(x == y){
		ans = 0;
		printf("%lld\n", ans);
		return 0;
	}
	if(x == (-1)*y){
		ans = 1;
		printf("%lld\n", ans);
		return 0;
	}
	if(x == 0){
		ans = abs(y);
		if(y < 0){
			ans++;
		}
		printf("%lld\n", ans);
		return 0;
	}

	if(x > 0){
		if(y >= x){
			ans = abs(x - y);
			printf("%lld\n", ans);
			return 0;
		}
		else{
			ans = abs(abs(x) - abs(y)) + 1;
			if(y > 0){
				ans++;
			}
			printf("%lld\n", ans);
			return 0;
		}
	}
	else if(x < 0){
		if(y <= x){
			ans = abs(abs(x) - abs(y)) + 2;
			printf("%lld\n", ans);
			return 0;
		}
		else{
			if(y < (-1)*x){
				ans = abs(abs(x) - abs(y));
				if(y > 0){
					ans++;
				}
				printf("%lld\n", ans);
				return 0;
			}
			else{
				ans = abs(abs(x) - abs(y)) + 1;
				printf("%lld\n", ans);
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3712
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
cnt = 0
for i in range(N)[::-1]:
    if (A[i][0] + cnt)%A[i][1] != 0:
        cnt += A[i][1] - (A[i][0] + cnt)%A[i][1]
print(cnt)

Measured memory_bytes: 27408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  ll n,w;
  cin>>n>>w;

  vector<ll> a(n+1);//重さ
  vector<ll> b(n+1);//価値
  rep(i,n){
    cin>>a[i+1]>>b[i+1];
  }

  vector<vector<ll>> ans(n+1,vector<ll>(150000,INF));
  ans[0][0]=0;
  rep(i,n){
    rep(j,100001){
      if(j+b[i]<120000) chmin(ans[i+1][j+b[i+1]],ans[i][j]+a[i+1]);
      chmin(ans[i+1][j],ans[i][j]);
    }
  }

  ll answer=0;
  for(ll i=0;i<=100000;i++){
    if(ans[n][i]<=w) chmax(answer,i);
  }

  cout << answer << endl;
}


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

int main() {
  int N, K, j;
  cin >> N >> K;

  int s = 1;
  
  int i = 0;
  
    for (j = 0; j < N; j++){
      s *= 2;
      i++;

      if (s >= K){
        break;
      }
    }

  for (j = 0; j < N - i; j++){
      s += K;
  }
  
  cout << s << endl;

}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    // 3個の整数の合計が21以下かどうかを判定
    if((a + b + c) <= 21) {
        cout << "win" << endl;
    } else {
        cout << "bust" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

struct edge {
  int u, v;
  ll cost[2];
};

struct vtx {
  ll dist[2] = {(ll)1e18, (ll)1e18};
  vector<edge> es;
};

void dijk(int key, vector<vtx> &vs, int start) {
  priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
  vs[start].dist[key] = 0;
  que.push({0, start});
  while(!que.empty()) {
    auto p = que.top();
    ll d = p.first;
    vtx &u = vs[p.second];
    que.pop();
    FOR(e, u.es) {
      vtx &v = vs[e.v];
      if(d + e.cost[key] < v.dist[key]) {
        v.dist[key] = d + e.cost[key];
        que.push({v.dist[key], e.v});
      }
    }
  }
}

constexpr ll account = 1e15;

int main() {
  ios::sync_with_stdio(false);
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector<vtx> vs(n+1);
  REP(i,0,m) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    vs[u].es.push_back({u, v, {a, b}});
    vs[v].es.push_back({v, u, {a, b}});
  }
  dijk(0, vs, s);
  dijk(1, vs, t);
  VL cost(n);
  cost[n-1] = vs[n].dist[0] + vs[n].dist[1];
  for(int i=n-2; i>=0; i--) {
    cost[i] = min(cost[i+1], vs[i+1].dist[0] + vs[i+1].dist[1]);
  }
  FOR(c,cost) {
    cout << account - c << endl;
  }
  
  return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll v[55];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> v[i];

    ll ans = 0;
    int h = min(n, k);
    for(int g = 0; g <= h; g++){
        for(int l = 0; l <= g; l++){
            vector<ll> tmp;
            rep(i, l) tmp.push_back(v[i]);
            rep(i, g - l) tmp.push_back(v[n - i - 1]);

            sort(tmp.begin(), tmp.end());
            ll s = 0;

            // rep(i, tmp.size()) cout << tmp[i] << " ";
            // cout << endl;

            rep(p, tmp.size()) s += tmp[p];
            int thr = min(k - g, (int)tmp.size());
            rep(q, thr) if(tmp[q] < 0) s -= tmp[q];
            // cout << "s=" << s << endl;
            
            ans = max(ans, s);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int i,j,k,n,m,x,y,z;
	cin>>n;
	vector<long long int> a(n),b(n),c(n),a1(n),b1(n),c1(n),pr(n,0);
	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
		a1[i]=0;b1[i]=0;c1[i]=0;pr[i]=0;
	}
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			a1[i]=a[i];
			b1[i]=b[i];
			c1[i]=c[i];
		}
		else
		{
			x=max(b1[i-1],c1[i-1]);
			a1[i]=x+a[i];
			x=max(a1[i-1],c1[i-1]);
			b1[i]=x+b[i];
			x=max(a1[i-1],b1[i-1]);
			c1[i]=x+c[i];
		}
		pr[i]=max(a1[i],max(b1[i],c1[i]));
	}
	cout<<pr[n-1];
}

Measured memory_bytes: 5760
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a;
    cin >> a;
    string ans = a[0]+to_string(a.length()-2)+a[a.length()-1];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{
  int a,b,m;
  cin>>a>>b;
  m=(a+b);
  cout<<(m+1)/2;
 
}


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

const int MAX_N=210;

int N,n,d,mx,Mx,my,My;
vector<int> x(MAX_N,0),y(MAX_N,0);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N,N){
        mx=Mx=my=My=0;
        for (int i=1;i<N;++i){
            cin >> n >> d;
            x[i]=x[n],y[i]=y[n];
            if (d==0) --x[i];
            if (d==1) --y[i];
            if (d==2) ++x[i];
            if (d==3) ++y[i];
            mx=min(mx,x[i]);
            Mx=max(Mx,x[i]);
            my=min(my,y[i]);
            My=max(My,y[i]);
        }
        cout << Mx-mx+1 << ' ' << My-my+1 << '\n';
    }
}


Measured memory_bytes: 3112
n = int(input())
a = list(map(int, input().split()))
count = 0
next_list = []
while True:
    for i in range(n):
        ans = a[i] % 2
        if ans == 0:
            next_list.append(a[i] / 2)
        else:
            break
    if len(next_list) < n:
        break
    else:
        count += 1
        a = next_list
        next_list = []
print(count)


Measured memory_bytes: 3060
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX1 10
#define MAX2 1000
int main(void)
{
	char w[MAX1], t[MAX2]; 
	int n=0, len, i;
	scanf("%s", w);
	len = (int)strlen(w);
	for(i=0; i<len; i++){
		w[i] = tolower(w[i]);
	}
	while(scanf("%s", t) != EOF){
		len = (int)strlen(t);
		for(i=0; i<len; i++){
			t[i] = tolower(t[i]);
		}
		if(strcmp(w, t) == 0){
			n++;
		}
	}
	printf("%d\n", n);	
    return 0;
}

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


int main()
{
    int a,b,c;
    bool flag=false;
    cin>>a>>b>>c;
    int B=b;
    while(B!=0){
        if((a*B)%b==c){
            flag=true;
            break;
        }
        B--;
    }
    if(flag) cout << "YES" << endl;
    else cout <<"NO" <<endl;
    return 0;
}

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

int main(){
  int x,y,z;

  while(true){
    //入力
    cin >> x >> y >> z;

    //終了条件
    if(x==-1 && y==-1 && z==-1) break;

    //計算
    int sum = z + y*60 + x*60*60;
    int ans = 2*60*60-sum;
    z = ans%60;
    y = ans/60;
    x = y/60;
    y = y%60;

    //出力
    char strx[100],stry[100],strz[100],strans[100];
    if(x/10 == 0){
      sprintf(strx,"0%d",x);
    }else{
      sprintf(strx,"%d",x);
    }
    if(y/10 == 0){
      sprintf(stry,"0%d",y);
    }else{
      sprintf(stry,"%d",y);
    }
    if(z/10 == 0){
      sprintf(strz,"0%d",z);
    }else{
      sprintf(strz,"%d",z);
    }
    sprintf(strans,"%s:%s:%s",strx,stry,strz);
    puts(strans);
    //３倍録画
    sum *= 3;
    ans = 6*60*60-sum;
    z = ans%60;
    y = ans/60;
    x = y/60;
    y = y%60;

 if(x/10 == 0){
      sprintf(strx,"0%d",x);
    }else{
      sprintf(strx,"%d",x);
    }
    if(y/10 == 0){
      sprintf(stry,"0%d",y);
    }else{
      sprintf(stry,"%d",y);
    }
    if(z/10 == 0){
      sprintf(strz,"0%d",z);
    }else{
      sprintf(strz,"%d",z);
    }
    sprintf(strans,"%s:%s:%s",strx,stry,strz);
    puts(strans);
  }
}

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

using namespace std;

struct StronglyConnectedComponents
{
  vector< vector< int > > gg, rg;
  vector< pair< int, int > > edges;
  vector< int > comp, order, used;

  StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {}

  void add_edge(int x, int y)
  {
    gg[x].push_back(y);
    rg[y].push_back(x);
    edges.emplace_back(x, y);
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  void dfs(int idx)
  {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt)
  {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(vector< vector< int > > &t)
  {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    set< pair< int, int > > connect;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      if(connect.count({x, y})) continue;
      t[x].push_back(y);
      connect.emplace(x, y);
    }
  }
};


const int INF = 1 << 30;

struct edge
{
  int to, cost;
};

int MST_Arborescence(vector< vector< edge > > &g, int start, int sum = 0)
{
  int N = (int) g.size();

  vector< int > rev(N, -1), weight(N, INF);
  for(int idx = 0; idx < N; idx++) {
    for(auto &e : g[idx]) {
      if(e.cost < weight[e.to]) {
        weight[e.to] = e.cost;
        rev[e.to] = idx;
      }
    }
  }

  StronglyConnectedComponents scc(N);
  for(int idx = 0; idx < N; idx++) {
    if(start == idx) continue;
    scc.add_edge(rev[idx], idx);
    sum += weight[idx];
  }
  vector< vector< int > > renew;
  scc.build(renew);
  if(renew.size() == N) return (sum);
  vector< vector< edge > > fixgraph(renew.size());
  for(int i = 0; i < N; i++) {
    for(auto &e : g[i]) {
      if(scc[i] == scc[e.to]) continue;
      fixgraph[scc[i]].emplace_back((edge) {scc[e.to], e.cost - weight[e.to]});
    }
  }
  return (MST_Arborescence(fixgraph, scc[start], sum));
}

void solve()
{
  int V, E, R;
  cin >> V >> E >> R;
  vector< vector< edge > > g(V);
  while(E--) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].emplace_back((edge) {b, c});
  }
  cout << MST_Arborescence(g, R) << endl;
}

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

Measured memory_bytes: 3812
import sys
array_abc = list(map(int,input().split()))
if min(array_abc) < 0 or max(array_abc) > 10000:
    sys.exit()

min = 30000
for I in range(len(array_abc)):
    for J in range(len(array_abc)):
        if not I == J:
            if min > array_abc[I] + array_abc[J]:
                min = array_abc[I] + array_abc[J]

print(min)


Measured memory_bytes: 9096
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '2') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    let mut word_map = HashMap::new();

    for v in [1, -1].iter() {
        let n: usize = read();
        for i in 0..n {
            let word: String = read();
            let current_score: i32 = *word_map.get(&word).unwrap_or(&0);
            word_map.insert(word, current_score+v);
        }
    }

    let mut best = 0;
    for (_k, v) in word_map {
        best = max(best, v);
    }
    println!("{}", best);
}


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

int main() {
  int y , m, d ;
  char c1 ,c2;
  cin >>y >> c1 >> m >> c2 >> d;
  if (m>4)
    cout << "TBD";
  else 
    cout <<"Heisei";
  
     
}


Measured memory_bytes: 256
hn=int(input())
ht=list(map(int,input().split()))
cnt=0
while 1:
    #範囲決め
    for i in range(hn):
        if ht[i]>0:
            st=i
            break
    else:
        break

    for i in range(st+1,hn):
        if ht[i]<=0:
            ed=i
            break
    else:
        ed=hn

    #水やり回数＝最小の花
    mn=min(ht[st:ed])

    #水をやる
    for i in range(st,ed):
        ht[i]-=mn
    cnt+=mn

print(cnt)

Measured memory_bytes: 3064
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
using namespace std;
string::size_type size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(i,l,k) for(int i=l;i<k;i++)
#define fd(i,l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int n, k;
int ans = 0;
void dfs(int i,int j, int sum)
{
    if (i == n)
    {
        if (sum == k)ans++;
    }
    else if (j<=9&&sum<=k)
    {
        dfs(i + 1, j + 1, sum + j);
        dfs(i, j + 1, sum);
    }
}
 
int main()
{
    while (cin>>n>>k)
    {
        if (n == 0 && k == 0)return 0;
        ans = 0;
        dfs(0, 0, 0);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    string ans = "Christmas";
    rep(i, 25-N){
        ans += " Eve";
    }
    cout << ans;
}

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

ll N,K;
ll inf = 1e9+7;
ll fact[200010] = {0};
ll inv[200010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			fact[i] = 1;
			inv[i] = 1;
		}
		else{
			fact[i] = (i*fact[i-1])%inf;
			inv[i] = mult(fact[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	else return (((fact[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll perm(ll n,ll k){
    return comb(n,k)*fact[k]%inf;
}

vector<vector<int>> v(100010);

ll dfs(int n,int m,int d){
    ll res = 1;
    if(n==1) res = K;
    ll t = K-2+(m==0);
    (res *= perm(t,v[n].size()-(m!=0)))%=inf;
    for(auto x:v[n]){
        if(x!=m) (res *= dfs(x,n,d+1))%=inf;
    }
    return res;
}


int main(){
    cin >> N >> K;
    factorial(K);
    int a,b;
    for(int i=0;i<N-1;i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    cout << dfs(1,0,0) << endl;
}

Measured memory_bytes: 11520
def dice_move(a1,a2,a3,a4,a5,a6,s):
    for i in s:
        if i=="E":
            a1,a2,a3,a4,a5,a6=a4,a2,a1,a6,a5,a3
        elif i=="S":
            a1,a2,a3,a4,a5,a6=a5,a1,a3,a4,a6,a2
        elif i=="W":
            a1,a2,a3,a4,a5,a6=a3,a2,a6,a1,a5,a4
        elif i=="N":
            a1,a2,a3,a4,a5,a6=a2,a6,a3,a4,a1,a5
    return None

def dice_place(top,front,a1,a2,a3,a4,a5,a6):
    if top==a1:
        ans=[0,0,a3,a5,a2,a4,0]
    elif top==a2:
        ans=[0,a4,0,a1,a6,0,a3]
    elif top==a3:
        ans=[0,a2,a6,0,0,a1,a5]
    elif top==a4:
        ans=[0,a5,a1,0,0,a6,a2]
    elif top==a5:
        ans=[0,a3,0,a6,a1,0,a4]
    elif top==a6:
        ans=[0,0,a4,a2,a5,a3,0]
    front%=10
    return ans[front]
    
a1,a2,a3,a4,a5,a6=map(int,input().split())
n=int(input())
for i in range(n):
    t,f=map(int,input().split())
    print(dice_place(t,f,a1,a2,a3,a4,a5,a6))


Measured memory_bytes: 5612
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<int> vec(n,0);
	int count[1000001]={0};
	int j;
	for(j=0;j<n;j++)
	  cin>>vec[j];
	map<int,int> mp;
	for(int x:vec)
	  mp[x]++;
	for(auto p:mp)
	{
		int x=p.first;
		int y=p.second;
		for(int i=1;i*x<=1000000;i++)
		{
			count[i*x]+=y;
		}
	}
	int answer=0;
	for(j=0;j<n;j++)
	{
		int val=vec[j];
		int total=count[val]-1;
		if(total==0)
		  answer++;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 25084
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	if(s.size()==2) cout<<s<<endl;
	else{
		REP(i,s.size()) cout<<s[i];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const ll inf = (ll)1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, k;
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (v <= w)
        cout << "NO";
    else
    {
        ll f = 0;
        k = llabs(a - b);
        j = llabs(v - w);
        if (k / j > t)
            f = 1;
        if (k / j == t && k % j != 0)
            f = 1;
        if (f == 0)
            cout << "YES";
        else
        {
            cout << "NO";
        }
    }

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = -1, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[1001][1001];
long long int iremono2[1001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >> n >> m >> c;
	rep(i, m) {
		cin >> iremono2[i];
	}
	rep(i, n) {
		rep(j, m) {
			cin >> iremono[i][j];
			counter += iremono[i][j]*iremono2[j];
		}
		if (counter + c > 0) {
			x++;
		}
		counter = 0;
	}
	cout << x << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q;
	cin>>q;
	for(int i=0; i<q; i++){
		int ans=0;
		int c,a,n;
		cin>>c>>a>>n;
		while(n>0){
			if(a>0 && c>0){
				ans++;
				n--;
				a--;
				c--;
			}else{
				break;
			}
		}
		
		while(a>0){
			if(c>=2){
				ans++;
				a--;
				c-=2;
			}else{
				break;
			}
		}
		ans+=c/3;
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
typedef pair < LL , int > pli;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > T MAX(T a,T b){return (a>b)?a:b;}
template < typename T > T MIN(T a,T b){return (a<b)?a:b;}
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
int readint(){
	char c=getchar();
	int ret=0;
	while(!(c>='0' && c<='9')) c=getchar();
	while(c>='0' && c<='9'){
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
void putint(int v){
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10) putint(v/10);
	putchar('0'+(v%10));
}
int n,fa[100005],sz[100005];
pli D[100005];
vector < int > adj[100005];
multiset < LL > inp,ex;
LL sm[100005];
LL dfs(int v,int f,int d=0){
	int i;
	LL ret=(LL)d;
	for(i=0;i<(int)adj[v].size();++i){
		int u=adj[v][i];
		if(u!=f) ret+=dfs(u,v,d+1);
	}
	return ret;
}
void rdfs(int v,int f){
	int i;
	ex.insert(sm[v]);
	for(i=0;i<(int)adj[v].size();++i){
		int u=adj[v][i];
		if(u!=f){
			sm[u]=sm[v]+(LL)n-2ll*sz[u];
			rdfs(u,v);
		}
	}
}
int main(){
	int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		fa[i]=-1;
		sz[i]=1;
		scanf("%lld",&D[i].FS);
		inp.insert(D[i].FS);
		D[i].SC=i;
	}
	sort(D,D+n);
	for(i=n-1;i>0;--i){
		int v=D[i].SC;
		LL d=D[i].FS,tar=d-(LL)n+2ll*sz[v];
		if(sz[v]*2>=n){
			printf("-1\n");
			return 0;
		}
		int td=lower_bound(D,D+n,mpr(tar,-1))-D;
		if(td>=n || D[td].FS!=tar || fa[D[td].SC]!=-1){
			printf("-1\n");
			return 0;
		}
		fa[v]=D[td].SC;
		sz[D[td].SC]+=sz[v];
	}
	if(sz[D[0].SC]!=n){
		printf("-1\n");
		return 0;
	}
	for(i=0;i<n;++i){
		if(fa[i]!=-1){
			adj[i].push_back(fa[i]);
			adj[fa[i]].push_back(i);
		}
	}
	sm[D[0].SC]=dfs(D[0].SC,-1);
	rdfs(D[0].SC,-1);
	if(ex!=inp){
		printf("-1\n");
		return 0;
	}
	for(i=0;i<n;++i){
		if(fa[i]!=-1) printf("%d %d\n",i+1,fa[i]+1);
	}
	return 0;
}
/*
 * 代码框架
 * 1、读入，对pair排序
 * 2、维护每个点的子树大小（初始=1）和父亲（初始=-1）
 * 3、按照D降序枚举，对于除了最后一个结点以外，都二分出其父亲的位置，找不到就-1
 * 4、每次如果碰到已经确定父亲的点则-1，如果碰到未确定父亲的点就加size
 * 5、最后检查，是否根节点的size=n
*/

Measured memory_bytes: 23296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
  int N, D; cin >> N >> D;
  double X[15][15];
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < D; ++j) {
      cin >> X[i][j];
    }
  }

  int cnt = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      int tmp = 0;
      for(int k = 0; k < D; ++k) {
        tmp += pow(X[i][k] - X[j][k], 2);
      }
      for(int l = 0; l <= 500; ++l) {
        if(tmp == pow(l, 2)) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
from math import ceil
import numpy as np

N, K = [int(c) for c in input().split()]
A = np.array([int(c) for c in input().split()])

min_num = 10000000
min_idx = np.argmin(A)
for i in range(K):
    # print(min_num)
    if ((min_idx - K + i + 1< 0) | (min_idx + i> N - 1)):
        continue
    else:
        min_num = min(min_num, 1 + ceil((min_idx - K + 1 + i)/(K - 1)) + ceil((N - min_idx - i - 1)/(K - 1)))
print(min_num)


Measured memory_bytes: 23428
#include<stdio.h>

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

    int ans=10000;
    int x;
    int a,b;
    int flag=0;

    for( x = 1; x <= 10000; x++ ){
        a = x*0.08;
        b = x*0.10;
        if( a == A && b == B ){
            if( x < ans ){
                ans = x;
                flag += 1;
            }
        }
    }

    if(flag!=0) printf("%d\n", ans);
    else printf("-1\n");

    return 0;
}


Measured memory_bytes: 128
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define REP(a) for(i = 0; i < a; i++)

int main(void)
{
    int a,l,i,j;
    scanf("%d%d",&a,&l);
    char s[a+1][l+1],d[l];
    REP(a) {
        scanf("%s",s[i]);
    }
    REP(a) {
        for(j=1;j<a;j++){
            if(strcmp(s[j-1], s[j])>0){
                strcpy(d, s[j-1]);
                strcpy(s[j-1], s[j]);
                strcpy(s[j], d);
            }
        }
    }
    REP(a) {
        printf("%s",s[i]);
    }
    printf("\n");
    return 0;
 }


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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(m);
  rep(i, m) cin >> b[i];
  vector<ll> acum{0};
  rep(i, n) acum.push_back(a[i] + acum[i]);
  vector<ll> bcum{0};
  rep(i, m) bcum.push_back(b[i] + bcum[i]);
  int ans = 0;
  int j = m;
  rep(i, n+1) {
    if (acum[i] > k) break;
    while (bcum[j] + acum[i] > k) {
      j--;
    }
    ans = max(ans, i+j);
  }
  cout << ans << '\n'; 
  
  return 0;
}

Measured memory_bytes: 9560
n = int(input())
x = list(map(int,input().split()))

m = min(x)
M = max(x)
ans = 10**9
for i in range(m,M+1):
  cost = 0
  for j in range(n):
    cost += (x[j]-i)**2
    
  ans = min(ans,cost)
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最小値を求める関数
Int Min(const Int a, const Int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}
// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}

Int DoubleArray(vector<Int>& a, vector<Int>& b, Int k) {
    Int result = 0;
    Int i = 0;
    Int j = (Int)b.size() - 1;
    while (1) {
        if (a[i] + b[j] > k) {
            --j;
            if (j == -1) {
                break;
            }
        } else {
            result = Max(result, i + j);
            ++i;
            if (i == (Int)a.size()) {
                break;
            }
        }
    }
    return result;
}

int main(void) {
    Int n, m, k;
    cin >> n >> m >> k;
    VI a(n + 2);
    VI b(m + 2);
    for (Int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (Int i = 1; i <= m; ++i) {
        cin >> b[i];
    }
    a[0] = 0;
    a[n + 1] = 1e09 + 7;
    for (Int i = 1; i <= n + 1; ++i) {
        a[i] += a[i - 1];
    }
    b[0] = 0;
    b[m + 1] = 1e09 + 7;
    for (Int i = 1; i <= m + 1; ++i) {
        b[i] += b[i - 1];
    }

    cout << DoubleArray(a, b, k) << endl;
    return 0;
}



Measured memory_bytes: 6420
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
int N, M;
vector<vector<int>> path(100001, vector<int> (0));



  

int main(){
 
 cin >> N >> M;
 
 rep(i, M){
   int j, k;
   cin >> j >> k;
   path[j].push_back(k);
   path[k].push_back(j);
 }
  
  
 
  vector<int> dist(N+1, -1);
  queue<int> que;
  
  dist[0] = 0;
  dist[1] = 0;
  que.push(1);//1に訪問予定
  
  // BFS開始
  while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();//先頭を追い出す

        // v から辿れる頂点をすべて調べる
        for (int nv : path[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v;
            que.push(nv);
        }
    }
  
  
 
  cout << "Yes" << endl;
  rep(i, N-1){
    cout << dist[i+2] << endl;
  }
}
  
  
   
   
  
  

Measured memory_bytes: 10188
import std.stdio;
import std.string;
import std.math;
import std.conv;
import std.algorithm;
import std.bigint;

void main(){

    while(true){
	long n = to!long(chomp(readln()));
	if(n == 0) break;
	long[] a;
	a ~= 0;
	a ~= to!long(chomp(readln()));
	for(long i=1;i<n;i++){
	    a ~= a[i] + to!long(chomp(readln()));
	}
	long res = a[1];
	for(long i=0;i<=n;i++){
	    for(long j=i+1;j<=n;j++){
		res = max( a[j] - a[i] , res);
	    }
	}
	writeln(res);
    }
}

Measured memory_bytes: 2476
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

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

int main() {
    int N;
    cin >> N;
    vector<int> brick(N);
    for (int i = 0; i < N; i++) {
        cin >> brick.at(i);
    }
    int remain = 0;
    for (int j = 0; j < N; j++) {
        if (brick.at(j) == remain+1) {
            remain++;
        }
    }
    if (remain == 0) {
        cout << "-1" << endl;
    }
    else {
        cout << N - remain << endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int r,c,k;
int a[3005][3005];
ll dp[3005][3005][3];
ll f(int row,int col,int cnt)
{
    ll &ret=dp[row][col][cnt];
    if(row>r||col>c) ret=0;
    if(ret!=-1) return ret;
    ret=0;
    if(a[row][col])
    {
        ret+=a[row][col];
        if(cnt==2)
            ret+=f(row+1,col,0);
        else
            ret+=max(f(row+1,col,0),f(row,col+1,cnt+1));
    }
    ret=max({ret,f(row+1,col,0),f(row,col+1,cnt)});
    return ret;
}
int main(void)
{
    cin>>r>>c>>k;
    memset(a,0,sizeof(a));
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<k;++i)
    {
        int row,col,val;
        cin>>row>>col>>val;
        a[row][col]=val;
    }
    cout<<f(1,1,0)<<endl;
    return 0;
}

Measured memory_bytes: 251072
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct edge{
  int to;
  ll cost;
};

vector<edge> G[100005];

int main() {
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b;
    ll w;
    cin >> a >> b >> w;
    a--;b--;
    edge e1,e2;
    e1.to = b;
    e1.cost=w;
    e2.to = a;
    e2.cost=w;
    G[a].push_back(e1);
    G[b].push_back(e2);
  }
  queue<int> q;
  vi color(n,-1);
  q.push(0);
  color[0] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(auto ne:G[u]){
      int v = ne.to;
      ll nw = ne.cost;
      if(color[v] != -1)continue;
      if(nw%2)color[v] = !color[u];
      else color[v] = color[u];
      q.push(v);
  }
  }
  rep(i,n)cout<<color[i]<<endl;
  return 0;
}

Measured memory_bytes: 11068
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int n;
double dp[301][301][301];
double solve(int c1, int c2, int c3) {
    if (dp[c1][c2][c3] >= 0) return dp[c1][c2][c3];
    if (c1 == 0 && c2 == 0 && c3 == 0) return 0.0;
    
    double res = 0.0;
    if (c1 > 0) res += solve(c1 - 1, c2, c3) * c1;
    if (c2 > 0) res += solve(c1 + 1, c2 - 1, c3) * c2;
    if (c3 > 0) res += solve(c1, c2 + 1, c3 - 1) * c3;
    res += n;
    res *= 1.0 / (c1 + c2 + c3);
    return dp[c1][c2][c3] = res;
}

int main() {
    cin >> n;
    vector<int> c(4);
    rep(i, n) {
        int a;
        cin >> a;
        c[a]++;
    }
    
    memset(dp, -1, sizeof(dp));
    printf("%.15lf\n", solve(c[1], c[2], c[3]));
}

Measured memory_bytes: 213376
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String date = sc.next();
        String[] info = date.split("/");
        int year = Integer.parseInt(info[0]),
        month = Integer.parseInt(info[1]);
        if(year < 2019 || year == 2019 && month < 5){
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}

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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  string aa, bb;
  for (int i = 0; i < a; ++i) {
    aa += char(b + '0');
  }
  for (int i = 0; i < b; ++i) {
    bb += char(a + '0');
  }
  cout << min(aa, bb);

  return 0;
}


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

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

    int p[5000];
    for(int i=0;i<N;i++)
        cin >> p[i];
    
    int min_sum = 20000;

    for(int I=0;I<=p[0];I++){
        int q[5000];
        for(int i=0;i<N;i++)
            q[i] = p[i];
        
        int sum = I;
        q[0] -= I;

        for(int i=0;i<=N-2;i++){
            if(q[i]<=0)
                continue;
            sum += q[i]*2;
            q[i+1] -= q[i];
        }

        if(q[N-1]>0)
            sum += q[N-1];

        min_sum = min(min_sum, sum);
    }

    cout << min_sum << endl;

    return 0;
}


Measured memory_bytes: 3140
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b = map(int,input().split())
  a-=1;b-=1
  edge[a].append(b)
  edge[b].append(a)
#print(edge)
colors = [0 for i in range(N)]

def dfs(v,color):
  colors[v] = color
  for u in edge[v]:
    if colors[u] == color:
      return False
    if colors[u] == 0 and not dfs(u, -color):
      return False
  return True

#print(dfs(0,1),colors)
if dfs(0,1): #もし二部グラフなら
  one = 0; zero = 0
  for x in colors:
    if x == 1:
      one += 1
    else:
      zero += 1
  ans = one*zero-M
else:
  ans = N*(N-1)//2-M
print(ans)

Measured memory_bytes: 35344
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var xy = new XY[N];
        for (int i = 0; i < N; i++)
        {
            var a = Console.ReadLine().Split(' ');
            xy[i] = new XY(int.Parse(a[0]), int.Parse(a[1]));
        }

        var range = Enumerable.Range(0, N).ToArray();
        double sum = 0;
        var f = 0;
        foreach (var p in AllPermutation(range))
        {
            f++;
            double res = 0;
            for (int i = 0; i < p.Length - 1; i++)
            {
                res += Math.Sqrt(
                    Math.Pow(xy[p[i]].X - xy[p[i + 1]].X, 2) +
                    Math.Pow(xy[p[i]].Y - xy[p[i + 1]].Y, 2)
                );
            }
            sum += res;
        }

        var ans = sum / f;
        Console.WriteLine(ans);
    }

    static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable
    {
        var a = new List<T>(array).ToArray();
        var res = new List<T[]>();
        res.Add(new List<T>(a).ToArray());
        var n = a.Length;
        var next = true;
        while (next)
        {
            next = false;
            int i;
            for (i = n - 2; i >= 0; i--)
            {
                if (a[i].CompareTo(a[i + 1]) < 0) break;
            }
            if (i < 0) break;

            var j = n;
            do
            {
                j--;
            } while (a[i].CompareTo(a[j]) > 0);

            if (a[i].CompareTo(a[j]) < 0)
            {
                var tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                Array.Reverse(a, i + 1, n - i - 1);
                res.Add(new List<T>(a).ToArray());
                next = true;
            }
        }
        return res;
    }

    struct XY
    {
        public int X { get; set; }
        public int Y { get; set; }
        public XY(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
    }
}



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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  Bint N, X;
  cin >> X;
  N = 100;
  for (int i = 1; i < 10000; i++) {
    N *= 101;
    N /= 100;
    if (N >= X) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	var n, ac, wa, tle, re int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		switch scanner.Text() {
		case "AC":
			ac++
		case "WA":
			wa++
		case "TLE":
			tle++
		case "RE":
			re++
		}
	}
	fmt.Printf("AC x %d\n", ac)
	fmt.Printf("WA x %d\n", wa)
	fmt.Printf("TLE x %d\n", tle)
	fmt.Printf("RE x %d\n", re)
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.rbegin(),A.rend());
    // 1つまで無視できる
    vector<ll> front_gcd(N),back_gcd(N);
    front_gcd[0] = A[0];
    back_gcd[N-1]  = A[N-1];
    for(int i=1;i<N;i++) front_gcd[i] = __gcd(front_gcd[i-1],A[i]);
    for(int i=N-2;i>=0;i--) back_gcd[i] = __gcd(back_gcd[i+1],A[i]);
    ll ans;
    for(int i=0;i<N;i++){
        if(i==0){
            ans = back_gcd[1];
        }else if(i==N-1){
            ans = max(ans,front_gcd[i-1]);
        }else{
            ans = max(ans,__gcd(front_gcd[i-1],back_gcd[i+1]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5584
//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=3e2+4;

//dp[cnt1][cnt2][cnt3] tells the expected no. of moves required to empty all the plates,
//if we start of with cnt1 plates having 1 sushis, cnt2 plates having 2 sushis and
//cnt3 plates having 3 sushis left.

double dp[N][N][N];

int cnt[4];

int main()                  
{
    int n;
    
    scn(n);
    
    rep(i,0,n)
    {
        int val;
        
        scn(val);
        
        cnt[val]++;
    }

    //i denotes no. of plates with 1 sushis, j denotes no. of plates with 2 sushis left
    //and k denotes no. of plates with 3 sushis left.
    
    //we iterate in reverse ordrer to because if we iterate from i->j->k, then we will
    //need i+1 for a transition of i, which will not be computed till now and it is
    //necessary in dp that all states requiered for the current transition must be
    // already computed.
    
    //computing in reverse order is helpful because for dp[i][j][k] we will always need
    // k or k-1 which will be computed,
    //if we need j+1(it will come in the state dp[i][j+1][k-1] which would had been computed),
    //and similarly if we need i+1(required state would be dp[i+1][j-1][k] and since j loop
    //is before i loop all states of j-1 would be computed beforehand.
    
    rep(k,0,n+1)
    {
        rep(j,0,n+1)
        {
            rep(i,0,n+1)
            {
                int total=i+j+k;
                
                if(total==0 or total>n)
                continue;
                
                dp[i][j][k]=1.0;
                
                if(i>0)
                dp[i][j][k]+=dp[i-1][j][k]*i/n;
                
                if(j>0)
                dp[i][j][k]+=dp[i+1][j-1][k]*j/n;
                
                if(k>0)
                dp[i][j][k]+=dp[i][j+1][k-1]*k/n;
                
                dp[i][j][k]*=((double)n/total);
                
                //cout<<i<<" "<<j<<" "<<k<<": "<<dp[i][j][k]<<endl<<endl;
            }
        }
    }
    
    //cout<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<endl;
    
    double ans=dp[cnt[1]][cnt[2]][cnt[3]];
    
    cout<<fixed<<setprecision(10)<<ans;
} 


Measured memory_bytes: 217344