akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int dfs(int i, int h, const vector<P> &m, vector<vector<int>> &dp) {
    if (h < 0) return 0;
    if (dp[i][h] != INF) return dp[i][h];
    if (i == 0) {
        dp[i][h] = ((h + m[0].first - 1) / m[0].first * m[0].second);
        return dp[i][h];
    }
    dp[i][h] = min(dfs(i-1,h,m,dp), dfs(i,h-m[i].first,m,dp)+m[i].second);
    return dp[i][h];
}

int main() {
    fast_io
    int h, n;
    cin >> h >> n;
    vector<P> m(n);
    rep(i,n) cin >> m[i].first >> m[i].second;
    vector<vector<int>> dp(n, vector<int>(h+1, INF));
    dfs(n-1, h, m, dp);
    cout << dp[n-1][h] << endl;
    return 0;
}

Measured memory_bytes: 39680
def dot(h, w):
    global area
    if 0 <= h and h < 10 and 0 <= w and w < 10:
        area[h][w] += 1
def sdot(h,w):
    [dot(h + i, w + j) for j in range(-1, 2) for i in range(-1 + abs(j), 2 - abs(j))]
def mdot(h,w):
    [dot(h + i, w + j) for j in range(-1, 2) for i in range(-1, 2)]
def ldot(h, w):
    [dot(h + i, w + j) for j in range(-2, 3) for i in range(-2 + abs(j), 3 - abs(j))]
dots = (sdot, mdot, ldot)
area = [[0 for _ in range(10)] for _ in range(10)]
while True:
    try:w, h, s = map(int, input().split(","))
    except:break
    dots[s - 1](h, w)
print(sum(i.count(0) for i in area))
print(max(max(i) for i in area))


Measured memory_bytes: 5608
n = int(input())
s = []
for i in range(n):
    s1 = sorted(input())
    s2 = ''
    for j in s1:
        s2 += j
    s.append(s2)

s.sort()

ans = 0
count = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        ans += count * (count - 1) // 2
        count = 1
ans += count * (count - 1) // 2

print(ans)


Measured memory_bytes: 10644
//B - Echo
#include <stdio.h>

int main(void){
    int n, i;
    char s[100], t[100];
    scanf("%d", &n);
    if(n%2==1){
        puts("No");
        return 0;    
    }
    scanf("%s", s);
    for(i=0; i<n; i++){
        t[i] = s[i];
    }
    for(i=0; i<n/2; i++){
        if(s[i] != t[(n/2)+i]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    ll k;
    cin >> n >> k;
    int dp[61][n];
    rep (i, n) {
        cin >> dp[0][i];
        dp[0][i]--;
    }
    FOR (i, 1, 61) {
        rep (j, n) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }
    int cur = 0;
    rep (i, 60) {
        if (k & (1LL << i)) {
            cur = dp[i][cur];
        }
    }
    cout << cur + 1 << endl;

    return 0;
}



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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> parent;
  vector<int> num_node;

  UnionFind(int N) : parent(N), num_node(N, 1) {
    for (int i = 0; i < N; i++) {
      parent[i] = i;
    }
  }

  // 根を求める
  int root(int x) {
    if (parent[x] == x) {
      return x;
    }

    // 経路圧縮
    parent[x] = root(parent[x]);
    return parent[x];
  }

  // 同一判定
  bool is_same(int x, int y) {
    return this->root(x) == this->root(y);
  }

  // 併合
  void unite(int x, int y) {
    x = this->root(x);
    y = this->root(y);

    // すでに一緒ならなにもしない
    if (x == y) {
      return;
    }
    parent[x] = y;
    num_node[y] += num_node[x];
  }

  // 同一グループのノード数
  int size(int x) {
    return num_node[root(x)];
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m;
  cin >> n >> m;
  vll a(n);
  rep(i, n) cin >> a[i];

  ll num_select = (n - 1 - m) * 2;

  if (n < num_select) {
    cout << "Impossible" << endl;
    return 0;
  }

#if 0
  if (m + n / 2 < n - 1) {
    cout << "Impossible" << endl;
    return 0;
  }
#endif

  UnionFind uf(n);

  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }

  map<ll, vll> nodes;
  rep(i, n) {
    nodes[uf.root(i)].push_back(a[i]);
  }
  if (nodes.size() == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (auto& it : nodes) {
    sort(all(it.second));
    ans += it.second[0];
    it.second.erase(it.second.begin());
    num_select--;
  }

  vll v;
  for (auto& it : nodes) {
    for (auto i : it.second) {
      v.push_back(i);
    }
  }
  sort(all(v));
  ans += accumulate(v.begin(), v.begin() + num_select, 0ll);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11344
N, M = map(int, input().split())

A, B = [0]*M, [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        # 親要素の番号を格納。根の場合は-(その集合のsize)
        # ノード番号とインデックスを対応させるためにn+1にした。0は無視。
        self.parent = [-1 for _ in range(n+1)]

    # 根ノードを検索
    def find(self, x):
        # 根ならその番号を返す
        if self.parent[x] < 0:
            return x
        # 根でないなら親の要素で再検索
        else:
            # 走査していく過程で親を書き換える
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 同じ集合に属するかチェック(根が同じか)
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 自分のいる集合のsizeを返す
    def size(self, x):
        y = self.find(x)  # xの根ノードを検索
        return -self.parent[y]  # 根ノードの番号には-(その集合のsize)があるので-1をかけて返す

    # 併合
    def union(self, x, y):
        # x, yの根ノードを検索
        x_root = self.find(x)
        y_root = self.find(y)

        # 同じ集合に属している場合(根が同じ場合)はそのまま
        if x_root == y_root:
            return False
        # 違う集合の場合(根が違う場合)、x_rootのsizeの方が大きいとしてx_rootにy_rootをつなげる
        else:
            # 大きい方に小さい方をつなげたいので、大小が違うなら入れ替える
            if -self.parent[x_root] < -self.parent[y_root]:
                x_root, y_root = y_root, x_root

            # x_rootのsizeを増やす
            self.parent[x_root] += self.parent[y_root]
            # y_rootの親をx_rootに変更する
            self.parent[y_root] = x_root
            return True


UnionFind = UnionFind(N)
ans = [0]*M
ans[M-1] = N * (N - 1) // 2

# 逆からつないでいき新しくつながった場合は不便さを減らしていく
for i in reversed(range(1, M)):
    a, b = A[i], B[i]
    # すでにつながっている(根が同じ)場合
    if UnionFind.same_check(a, b):
        ans[i-1] = ans[i]
    # 新しくつながった(根が違う)場合
    else:
        a_size = UnionFind.size(a)
        b_size = UnionFind.size(b)
        ans[i-1] = ans[i] - a_size * b_size
        UnionFind.union(a, b)

for i in ans:
    print(i)


Measured memory_bytes: 17424
M,D=map(int,input().split())

if D<=21:
    print(0)
    exit()
ans=0
for i in range(4,M+1):
    for j in range(22,D+1):
        D1=int(str(j)[0])
        D2=int(str(j)[1])
        if i==D1*D2 and D1!=1 and D2!=1:
            ans+=1
            
print(ans)

Measured memory_bytes: 3060
#include <cassert>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <iostream>
#include <tuple>
#include <limits>
using namespace std;

struct MinCostFlowGraph {
private:
  using ll = long long;
  struct edge {
    int to;
    ll cap, cost;
    int r_idx;
    edge(int t, ll cap, ll cost, int r) :
      to(t), cap(cap), cost(cost), r_idx(r) {}
  };
  vector<vector<edge>> G;
  int sz;

public:
  MinCostFlowGraph(int n) : G(n), sz(n) {}

  void add_edge(int from, int to, ll cap, ll cost){
    int i = G[to].size(), i_ = G[from].size();
    G[from].emplace_back(to,cap,cost,i);
    G[to].emplace_back(from,0,-cost,i_);
  }
  
  ll solve(int from, int to, ll k){
    ll f = 0, cost_sum = 0;
    const ll INF = numeric_limits<ll>::max();
    vector<ll> potential(sz);
    while(1){
      vector<ll> dist(sz,INF);
      dist[from] = 0;
      vector<int> prev_v(sz,-1);
      vector<int> prev_e(sz,-1);
      priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<>> pq;
      pq.emplace(0,from);
      while(pq.size()){
        // auto [d, v] = pq.top();
        ll d = pq.top().first;
        ll v = pq.top().second;
        // d *= -1;
        pq.pop();
        if(dist[v] < d) continue;
        for(size_t i = 0; i < G[v].size(); ++i){
          const auto& e = G[v][i];
          if(e.cap == 0) continue;
          int v_ = e.to;
          ll d_ = d + e.cost + potential[v] - potential[v_];
          if(dist[v_] <= d_)
            continue;
          dist[v_] = d_;
          prev_v[v_] = v;
          prev_e[v_] = i;
          // pq.emplace(-d_,e.to);
          pq.emplace(d_,e.to);
        }
      }
      if(dist[to] >= INF) return f;
      for(int i = 0; i < sz; ++i)
        potential[i] += dist[i];
      int v = to;
      ll flow = 1;
      while(v != from){
        int v_ = prev_v[v];
        flow = min(flow,G[v_][prev_e[v]].cap);
        v = v_;
      }
      v = to;
      ll diff = 0;
      while(v != from){
        int v_ = prev_v[v];
        auto& e = G[v_][prev_e[v]];
        e.cap -= flow;
        diff += flow*e.cost;
        G[v][e.r_idx].cap += flow;
        v = v_;
      }
      if(cost_sum+diff > k)
        return f;
      f += flow;
      cost_sum += diff;
    }
    return f;
  }
};

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  MinCostFlowGraph G(a+b+2);
  vector<vector<int>> E(a,vector<int>(b));
  for(int i = 0; i < a; ++i){
    string s;
    cin >> s;
    for(int j = 0; j < b; ++j){
      int c = s[j] - '0';
      E[i][j] += c;
    }
  }
  for(int j = 0; j < b; ++j){
    string s;
    cin >> s;
    for(int i = 0; i < a; ++i){
      int c = s[i] - '0';
      E[i][j] += c;
    }
  }
  for(int i = 0; i < a; ++i)
    for(int j = 0; j < b; ++j)
      G.add_edge(i,a+j,1,E[i][j]);
  int s = a+b, t = s+1;
  for(int i = 0; i < a; ++i)
    G.add_edge(s,i,1,0);
  for(int j = 0; j < b; ++j)
    G.add_edge(a+j,t,1,0);
  cout << G.solve(s,t,k) << endl;
}



Measured memory_bytes: 6396
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#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)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int a, b, c;
  cin >> a >> b >> c;
  int k = b*c;
  if (a <= k) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int A, B, C;
	cin >> A >> B >> C;
	
	int k;
	cin >> k;
	
	if(C > B && B > A){
		cout << "Yes" << endl;
		return 0;
	}
	
	while(B <= A){
		if(B > A){
			break;
		}
		if(k == 0) break;
		B *= 2;
		k--;
	}
	if(k == 0 && C < B){
		cout << "No" << endl;
		return 0;
	}
	if(k > 0) {	
		while(C <= B){
			if(C > B){
				break;
			}
			if(k == 0) break;
			C *= 2;
			k--;
		}
	}
	if(B > A && C > B){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(void)
{
	int n;
	int t[10000],h[10000];
	int jun,ba,tc,hc;
	int flg[10000];
	int ban[10000];
	int i,j,temp;
	
	
	scanf("%d",&n);
	while(n!=0){
		for(i=1;i<=2*n;i++){
			flg[i]=0;
			ban[i]=i;
		}
		for(i=1;i<=n;i++){
			scanf("%d",&t[i]);
			}
		for(i=1;i<=n-1;i++){
			for(j=i+1;j<=n;j++){
				if(t[i]>t[j]){
					temp=t[i];
					t[i]=t[j];
					t[j]=temp;
				}
			}
		}
		for(i=1;i<=2*n;i++){
			for(j=1;j<=n;j++){
				if(t[j]==ban[i]){
					flg[i]=1;
				}
			}
		}
		j=1;
		for(i=1;i<=2*n;i++){
			if(flg[i]==0){
				h[j]=i;
				j++;
			}
		}

		tc=n;
		hc=n;
		ba=0;
		jun=0;
		while(!(tc==0 || hc==0)){
			if(jun==0){
				for(i=1;i<=n;i++){
					if(ba<t[i]){
						jun=1;
						tc--;
						ba=t[i];
						t[i]=0;
						break;
					}
				}
				if(i==n+1){
					jun=1;
					ba=0;
				}
			}
			else if(jun==1){
				for(i=1;i<=n;i++){
					if(ba<h[i]){
						jun=0;
						hc--;
						ba=h[i];
						h[i]=0;
						break;
					}
				}
				if(i==n+1){
					ba=0;
					jun=0;
				}
			}
		}
		printf("%d\n%d\n",hc,tc);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int,int>
#define F first
#define S second

using namespace std;
const int MAX_N = 1e4+10;
const int INF = 1e9+10;
typedef long long ll;
vector <int> vec[MAX_N];
bool ans[MAX_N];
int dp[MAX_N],depth[MAX_N];
void dfs(int v,int cnt,int p){
	depth[v]=cnt+1;
	dp[v]=depth[v];
	int nd=0;
	for(int u:vec[v]){
		if(u==p)
            continue;
		if(dp[u])
			dp[v]=min(dp[v],depth[u]);
		else{
			dfs(u,cnt+1,v);
			dp[v]=min(dp[v],dp[u]);
			if(dp[u]>=depth[v])
                ans[v]=true;
            nd++;
		}
	}
    if(p==-1&&nd<2)
        ans[v]=false;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    dfs(0,0,-1);
    for(int i=0;i<n;i++)
        if(ans[i])
            cout<<i<<endl;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e5 + 5;
int par[N];
bool vis[N];
vector<int>adj[N];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    while(m--)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int>q;
    q.push(1);
    vis[1] = 1;
    while(q.size())
    {
        int v = q.front();
        q.pop();
        for(auto ch : adj[v])
        {
            if(!vis[ch])
            {
                par[ch] = v;
                vis[ch] = 1;
                q.push(ch);
            }
        }
    }
    for(int i = 2;i <= n;++i)
        if(!par[i])
            return cout << "No", 0;
    cout << "Yes\n";
    for(int i = 2;i <= n;++i)
        cout << par[i] << '\n';
    return 0;
}


Measured memory_bytes: 10612
n=int(input())
arr=list(map(int,input().split()))
ans=[]
flag=False
for _ in range(n):
  for i in range(len(arr)-1,-1,-1):
    if arr[i]==i+1:
      ans.append(arr[i])
      arr=arr[:i]+arr[i+1:]
      break
  else:
    flag=True
    break
if flag==True:
  print(-1)
else:
  ans=ans[::-1]
  for i in range(n):
    print(ans[i])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int N;
	std::vector<std::string> s;
	
	std::cin >> N;
	s.reserve(N);
	for (int i = 0; i < N; ++i) {
		std::string ss;
		std::cin >> ss;
		s.push_back(std::move(ss));
	}

	int result = 0;
	int startb = 0;
	int enda = 0;
	int both = 0;
	std::string AB = "AB";

	for (auto& ss : s) {
		size_t pos = 0;
		while ((pos = ss.find(AB, pos)) != ss.npos) {
			++result;
			pos += 2;
		}
		if (ss[0] == 'B')
			++startb;
		if (ss[ss.size() - 1] == 'A')
			++enda;
		if (ss[0] == 'B' && ss[ss.size() - 1] == 'A')
			++both;
	}

	if (startb == 0 || enda == 0)
		result += 0;
	else if (both == startb && both == enda)
		result += both - 1;
	else
		result += std::min(startb, enda);

	std::cout << result << "\n";
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e4;

bool p[MAX];
vector<int> prime;
int n,sum[MAX+1];

void is_prime(){
  fill(p,p+MAX,true);
  p[0] = p[1] = false;

  for(int i = 2 ; i*i <= MAX ; i++){
    if(p[i]){
      for(int j = i*i ; j <= MAX ; j += i){
	p[j] = false;
      }
    }
  }
}

void init(){
  is_prime();
  for(int i = 0 ; i < MAX ; i++){
    if(p[i]) prime.push_back(i);
  }
}

void solve(){
  int sum = 0 ,cnt = 0 ,t = 0;
  for(int i = 0 ; i < prime.size() ; i++){
    sum += prime[i];
    if(sum == n) cnt++;   
    while(sum >= n){
      sum -= prime[t++];
      if(sum == n) cnt++;   
    }
  }
  cout << cnt << endl;
}

int main(){
  init();

  while(cin >> n ,n){
    solve();
  }

  return 0;
}

Measured memory_bytes: 1244
N = int(input())
s = []
ans = 0
ab = 0
a = 0
b = 0
for i in range(N):
    tmp = input()
    s.append(tmp)
    for j in range(len(tmp) - 1):
        if tmp[j] == "A" and tmp[j + 1] == "B":
            ans += 1
    if tmp[0] == "B" and tmp[-1] == "A":
        ab += 1
    elif tmp[0] == "B":
        b += 1
    elif tmp[-1] == "A":
        a += 1
if a == b == 0:
    if ab != 0:
        ans += ab - 1
else:
    ans += ab + min(a, b)
print(ans)






Measured memory_bytes: 3700
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoderBeginnerContest178
{
    class Program
    {
        static void Main(string[] args)
        {
            // 課題B - Product Max(2020/9/13)

            string[] input = Console.ReadLine().Split(' ');
            long max = -1000000000000000000;
            long tmpResult;

            for(int i= 0; i<2; i++)
            {
                for(int j=2; j<4; j++)
                {
                    tmpResult = long.Parse(input[i]) * long.Parse(input[j]);
                    if (tmpResult > max) max = tmpResult;
                }
            }

            Console.Write(max);

        }
    }
}


Measured memory_bytes: 27484
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	long[] fact, ifact;
	void Solve()
	{
		var N = F();
		fact = new long[N + 10];
		fact[0] = 1;
		for (var i = 1; i < N + 10; i++) fact[i] = i * fact[i - 1] % MOD;
		ifact = new long[N + 10];
		for (var i = 0; i < N + 10; i++) ifact[i] = Inverse(fact[i]);
		var a = G();
		var cnt = new int[N];
		foreach (var x in a) cnt[x - 1]++;
		var j = 0;
		while (cnt[j] == 1) j++;
		var dup = new List<int>();
		for (var i = 0; i <= N; i++) if (a[i] == j + 1) dup.Add(i);
		var len = dup[1] - dup[0] + 1;
		for (var k = 1; k <= N + 1; k++)
		{
			var x = (Comb(N + 1, k) - Comb(N + 1 - len, k - 1)) % MOD;
			if (x < 0) x += MOD;
			Console.WriteLine(x);
		}
	}
	long Comb(int n, int m)
	{
		if (m < 0) return 0;
		if (m > n) return 0;
		return fact[n] * ifact[m] % MOD * ifact[n - m] % MOD;
	}
	static long Inverse(long m)
	{
		long a = 1, b = 0, c = 0, d = 1, n = MOD;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return b < 0 ? b + MOD : b;
	}
}


Measured memory_bytes: 28252
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> H(N);
	for (auto& x : H) {
		cin >> x;
	}
	sort(H.rbegin(), H.rend());

	long long ans = accumulate(H.begin() + min(K, N), H.end(), 0LL);
	cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);

        while(true){
            int count = scn.nextInt();

            if(count == 0) break;

            int [] array;
            array = new int[count];

            int sum = 0;
            Double ave = 0.0;
            Double ans = 0.0;
            Double answer = 0.0;


            for(int i = 0; i < count; i++){
                array[i] = scn.nextInt();
                sum += array[i];
            }

            ave = Double.valueOf(sum) / Double.valueOf(count);

            for(int i = 0; i < count; i++){
                ans += (array[i] - ave) * (array[i] - ave);
            }
            ans /= count;
            answer = Math.sqrt(ans);

            System.out.println(String.format("%.8f", answer));

        }
    }
}







Measured memory_bytes: 32192
N, X, Y = map(int,input().split())
dis = Y-X

lists = [0 for i in range(N-1)]
for i in range(1,Y):
    for j in range(i+1,N+1):
        if i <= X and Y <= j:
            pro = j-i-dis+1
            lists[pro-1] += 1
        elif i <= X and X <= j <= Y:
            pro = X+Y-i-j+1
            sta = j-i
            lists[min(pro,sta)-1] += 1
        elif X <= i <= Y and Y <= j:
            pro = i+j-X-Y+1
            sta = j-i
            lists[min(pro,sta)-1] += 1
        elif X <= i <= Y and X <= j <= Y:
            pro = i-j-X+Y+1
            sta = j-i
            lists[min(pro,sta)-1] += 1
        else:
            lists[j-i-1] += 1

for i in range(1,N-Y+1):
    lists[i-1] += N-Y-i+1
    
for i in lists:
    print(i)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<pair<ll,int>> a(n);
	rep(i,n){
		cin >> a.at(i).first;
		a.at(i).second=i+1;
	}
	vector<ll> ans(n+1);
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	a.pb(mp(0,n));
	int k=n;
	rep(i,n){
		k=min(a.at(i).second,k);
		ans.at(k)+=(a.at(i).first-a.at(i+1).first)*(ll)(i+1);
	}
	rep(i,n) cout << ans.at(i+1) << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>

#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a;
    vector<ll> n={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> a;
    cout << n[a-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;


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

  if (n % 2 == 0) {
    cout << n / 2 - 1 << endl;
  } else {
    cout << n / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int a[100100];
ll dp[100100];
int ac[100100];

int main(){
	cin>>n>>m;
	REP(i,m){
		cin>>a[i];
		ac[a[i]]=1;
	}
	dp[0]=1;
	if(ac[1]==0)dp[1]=1;
	for(int i=2;i<=n;i++){
		if(ac[i]==0){
			dp[i]=(ll)dp[i-1]+(ll)dp[i-2];
			dp[i]%=MOD;
		}else{
			dp[i]=0;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}
	

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

long long myabs(long long x) {
	if (x < 0) return -x;
	else return x;
}

int main() {
	long long a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (w >= v) {
		cout << "NO" << endl;
		return 0;
	}
	if ((v - w) * t >= myabs(a-b)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3624
import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np
    N, W = map(int, input().split())

    dp = np.zeros(W + 1, int)

    for i in range(N):
        w, v = map(int, input().split())
        np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
        # print(dp[:-w],dp[w:] )


    print(dp[-1])


if __name__ == "__main__":
    main()


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


int main() {
  int N, K;
  cin >> N >> K;
  
  vector <int> A(N);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<int> bucket(N + 1, 0);
  for(int i = 0; i < N; ++i) {
    ++bucket[A[i]];
  }

  sort(bucket.begin(), bucket.end(), greater<int>());
  for(int i = 0; i < K; ++i) {
    bucket[i] = 0;
  }

  int count = 0;

    for(int i = 0; i < N; ++i) {
    if(bucket[i] != 0) count += bucket[i];
  }

  cout << count << "\n";
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		long n = cin.nextLong();
		long s = cin.nextLong();
		if (s > n)
		{
			Console.WriteLine(-1);
			return;
		}
		List<int> list = new List<int>();
		for (int i = 2; i <= Math.Sqrt(n) + 0.5; i++)
		{
			long f = 0;
			long m = n;
			while (m > 0)
			{
				f += m % i;
				m /= i;
			}
			if (f == s)
			{
				Console.WriteLine(i);
				return;
			}
		}
		for (int i = 1; i <= Math.Sqrt(n - s) + 0.5; i++)
		{
			if ((n - s) % i == 0) list.Add(i);
		}
		for (int i = 1; i < list.Count; i++)
		{
			if (list[i] < Math.Sqrt(n)) continue;
			long b = list[i] + 1;
			long f = 0;
			long m = n;
			while (m > 0)
			{
				f += m % b;
				m /= b;
			}
			if (f == s)
			{
				Console.WriteLine(b);
				return;
			}
		}
		for (int i = list.Count - 1; i >= 0; i--)
		{
			long b = (n - s) / list[i] + 1;
			long f = 0;
			long m = n;
			while (m > 0)
			{
				f += m % b;
				m /= b;
			}
			if (f == s)
			{
				Console.WriteLine(b);
				return;
			}
		}
		if (n == s) Console.WriteLine(n + 1);
		else Console.WriteLine(-1);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2756
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
#define MAX 100000
 
int n,head,tail;
 
typedef struct{
  char name[100];
  int time;
}queue;
queue Q[MAX];
 
void enqueue(queue);
queue dequeue(void);
 
int main(){
  int i,quant,t=0,fin=0;
  queue q;
 
  scanf("%d%d", &n, &quant);
  for(i=1;i<=n;i++) scanf("%s%d", Q[i].name, &Q[i].time);
 
  head=0; tail=0;
   
  while(fin != n){
    q=dequeue();
    if(q.time-quant<=0){
      t+=q.time;
      fin++;
      printf("%s %d\n",q.name , t);
    } else if (q.time > 0){
      t+=quant;
      q.time-=quant;
      enqueue(q);
    }
  }
  return 0;
}
 
void enqueue(queue q){
  if(tail==n) tail=1;
  else tail++;
  Q[tail]=q;
  return;
}
 
queue dequeue(){
  if(head==n) head=1;
  else head++;
  return Q[head];
}

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

using namespace std;

int main(){
	int N, T, min, min_i;
	cin >> N >> T;
	int c[N], t[N];
	for(int i = 0; i < N; i++){
		cin >> c[i] >> t[i];
	}
	for(int i = 0; i < N; i++){
		if(i == 0){
			min = c[i];
			min_i = i;
		}
		if(t[i] <= T){
			if(c[i] < min){
				min = c[i];
				min_i = i;
			}
		}
	}
	if(t[0] > T && min_i == 0 ){
		cout << "TLE";
	}else{
		cout << c[min_i];
	}
	return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	int H,W,A,B; cin >> H >> W >> A >> B;
	vector<string> S(H);
	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) S[i].push_back('0');
	}
	for(int i = 0; i < B; ++i) {
		for(int j = 0; j < A; ++j) {
			S[i][j]='1';
		}
	}

	for(int i = H-1; B <= i; --i) {
		for(int j = W-1; A <= j; --j) {
			S[i][j]='1';
		}
	}
	for(int i = 0; i < H; ++i) {
		cout << S[i] << endl;
	}
	

	
	return 0;
}


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

int balls[10];
int b[10];
int c[10];
int b_size;
int c_size;

bool isAscending() {
    for (int i = 0; i < b_size - 1; i++) {
        if (b[i] > b[i + 1]) {
            return false;
        }
    }
    for (int i = 0; i < c_size - 1; i++) {
        if (c[i] > c[i + 1]) {
            return false;
        }
    }
    return true;
}

bool dfs(int k, bool isB) {
    if (isB == true) {
        b[b_size++] = balls[k];
    } else {
        c[c_size++] = balls[k];
    }
    bool res = false;
    if (k == 9) {
        if (isAscending() == true) {
            res = true;
        }
    } else {
        if (dfs(k + 1, true) == true) {
            res = true;
        } else if (dfs(k + 1, false) == true) {
            res = true;
        }
    }
    if (isB == true) {
        b[--b_size] = 0;
    } else {
        c[--c_size] = 0;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        fill_n(balls, 10, 0);
        fill_n(b, 10, 0);
        fill_n(c, 10, 0);
        b_size = c_size = 0;
        for (int i = 0; i < 10; i++) {
            cin >> balls[i];
        }
        bool res = dfs(0, true);
        if (res == true) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 0
#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 co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define P pair<int, int>
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
int n;
vector<vector<int>> patterns;
void buildPattern(vector<int>);

int main()
{
	cin >> n;
	vector<double>x(n), y(n);
	rep(i, n)cin >> x[i] >> y[i];
	vector<vector<double>>dist(n, vector<double>(n));
	rep(i, n)rep(j, n)
	{
		double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		dist[i][j] = d;
	}
	buildPattern(vector<int>());
	double ave = 0;
	rep(i, patterns.size())
	{
		double l = 0;
		rep(j, patterns[i].size() - 1)
		{
			l += dist[patterns[i][j]][patterns[i][j + 1]];
		}
		ave += l;
	}
	double fact = patterns.size();
	ave /= fact;
	cout << setprecision(12);
	co(ave);
	return 0;
}

void buildPattern(vector<int> v)
{
	if (v.size() == n)
	{
		patterns.push_back(v);
	}
	else if (v.size() == 0)
	{
		rep(i, n)
		{
			auto u = v;
			u.push_back(i);
			buildPattern(u);
		}
	}
	else
	{
		rep(i, n)
		{
			auto result = find(ALL(v), i);
			if (result == v.end())
			{
				auto u = v;
				u.push_back(i);
				buildPattern(u);
			}
		}
	}
}


Measured memory_bytes: 3384
#include<iostream>

using namespace std;

char length(int in){
  if(in > 160) return 'Z';
  if(in > 140) return 'F';
  if(in > 120) return 'E';
  if(in > 100) return 'D';
  if(in > 80) return 'C';
  if(in > 60) return 'B';
  return 'A';
}

char weight(int in){
  if(in > 25) return 'Z';
  if(in > 20) return 'F';
  if(in > 15) return 'E';
  if(in > 10) return 'D';
  if(in > 5) return 'C';
  if(in > 2) return 'B';
  return 'A';
}

int price(char x){
  if(x == 'Z') return 0;
  if(x == 'A') return 600;
  if(x == 'B') return 800;
  if(x == 'C') return 1000;
  if(x == 'D') return 1200;
  if(x == 'E') return 1400;
  return 1600;
}
int main(){

  int n;
  while (cin >> n){
    if(n == 0) break;
    int sum = 0;
    for(int i = 0; i < n; i++){
      int x,y,h,w,len;
      cin >> x>>y>>h>>w;
      len = x+y+h;
      char judgel = length(len);
      char judgew = weight(w);
      char judge;
      if(judgel >= judgew) judge = judgel;
      else judge = judgew;

      sum += price(judge);

    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits//stdc++.h>
#define mod 1000000007
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<double>p;
    double xx;
    p.push_back(0);
    for(int i=0;i<n;i++)
    {
       cin>>xx;
       p.push_back(xx); 
    }
    vector<double>tmp(n+1,0);
    vector<vector<double> >head(n+1,tmp);
    head[1][0]=1-p[1];
    head[1][1]=p[1];
   
    
    for(int i=2;i<=n;i++)
    {
       for(int j=0;j<=n;j++)
       {
          if(!j) 
            head[i][j]=head[i-1][j]*(1-p[i]); 
         else
              head[i][j]=head[i-1][j]*(1-p[i])+head[i-1][j-1]*p[i];
       } 
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
    {
       ans+=head[n][i]; 
    }
    cout.precision(10);
    cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include <iostream>
#define int long long
using namespace std;

int x, y;

signed main() {
	cin >> x >> y;
	
	for (int i = 0; ; i++) {
		if (x * (1LL << i) > y) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
var n,i:Longint;
s:String;
begin
readln(n);
readln(s);
if n mod 2=1 then begin
writeln('No');
exit;
end;
for i:=1 to n div 2 do begin
if s[i]<>s[n div 2+i]then begin
writeln('No');
exit;
end;
end;
writeln('Yes');
end.

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const ll inf = -1e18;

const int SZ = (1 << 18);

struct starry_sky_tree {
    ll all[SZ * 2], ma[SZ * 2];

    void init() {
        memset(all, 0, sizeof(all));
        memset(ma, 0, sizeof(ma));
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = SZ) {
        if (b <= l || r <= a) return ;
        if (a <= l && r <= b) {
            all[k] += x; return ; 
        }

        add(a, b, x, k * 2 + 1, l, (l + r) / 2);
        add(a, b, x, k * 2 + 2, (l + r) / 2, r);
        ma[k] = max(ma[k * 2 + 1] + all[k * 2 + 1], ma[k * 2 + 2] + all[k * 2 + 2]);
    }

    ll get(int a, int b, int k = 0, int l = 0, int r = SZ) {
        if (b <= l || r <= a) return inf;
        if (a <= l && r <= b) {
            return ma[k] + all[k];
        }

        ll lc = get(a, b, k * 2 + 1, l, (l + r) / 2);
        ll rc = get(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(lc, rc) + all[k];
    }
} seg;

const int MX = 200010;

ll dp[MX];
vector<pii> vadd[MX];

int main() {
	int N, M;
	scanf("%d %d", &N, &M);

	rep(i, M) {
		int l, r, a;
		scanf("%d %d %d", &l, &r, &a);
		vadd[l].eb(r, a);
	}

	multiset<pair<int, pii>> st;
	seg.init();

	ll ans = 0LL;

	for (int i = 1; i <= N; ++i) {
		while (st.size()) {
			auto it = st.begin();
			if (it->fi < i) {
				seg.add(0, it->se.fi, -(it->se.se));
				st.erase(it);
			} else {
				break;
			}
		}

		for (auto t : vadd[i]) {
			st.insert(mp(t.fi, mp(i, t.se)));
			seg.add(0, i, t.se);
		}

		dp[i] = seg.get(0, i);
		ans = max(ans, dp[i]);

		seg.add(i, i+1, dp[i]);
	}

	cout << ans << endl;

	return 0;
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    if(n / 100 == n % 10) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
import sys

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

for line in sys.stdin:
    (a,b)=line.split(" ")
    a=eval(a)
    b=eval(b)
    g=gcd(a,b)
    print("%d %d" % (g,a*b/g))

Measured memory_bytes: 4224
a,b,c = map(int,input().split())
if a == b and b == c and a == c:
  if a %2 == 0:
    print(-1)
  else:
    print(0)
else:
  for i in range(10**9):
    if a %2 == 0:
      S = a/2
    else:
      print(i)
      break
    if b%2 == 0:
      T = b/2
    else:
      print(i)
      break
    if c %2 == 0:
      U = c/2
    else:
      print(i)
      break
    a -= S*2
    b -= T*2
    c -= U*2
    a += T
    a += U
    b += S
    b += U
    c += S
    c += T

Measured memory_bytes: 9188
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        HashSet<String> array = new HashSet<String>();
        
        int N = in.nextInt();
        for (int i = 0; i < N; i++){
            String c1 = in.next();
            String c2 = in.next();
            
            if (c1.equals("insert")){
                array.add(c2);
            }else if(c1.equals("find")){   
                if (array.contains(c2)){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }
    }
}

Measured memory_bytes: 252868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcoder097_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力を受け取る
            int X = int.Parse(Console.ReadLine());

            //最終的に出力する変数
            int result = 0; ;

            //1000までのべき定数を作成
            int[] Beki = new int[350];
            int cnt = 0;
            for (int i = 1; i < 33; i++)
            {
                for (int j = 2; j < 9; j++)
                {
                    Beki[cnt] = (int)Math.Pow(i, j);
                    cnt++;
                }
            }

            //X以下で最大のべき乗数を探す
            for (int i = X; i > 0; i--)
            {
                for (int j = 0; j < 350; j++)
                {
                    if (i == Beki[j])
                    {
                        result = Beki[j];
                        goto last;
                    }
                }
            }

            last:;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (b-a == c-b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int H, W, N;
int org[35][35];
int chg[35][35];
int res[35][35];

bool judge() {
	bool ret = true;
	REP(i, H) REP(j, W) if(chg[i][j] != 0) ret = false;
	return ret;
}

void drop(){
	REP(i, H) REP(j, W) chg[i][j] = res[i][j];
	REP(j, W) REP(cnt, H+1) REP(i, H-1)	if(chg[H-1-i][j] == 0) swap(chg[H-1-i][j], chg[H-2-i][j]);
	REP(i, H) REP(j, W) res[i][j] = chg[i][j];
	return;
}

void clear(){
	bool move = false;
	drop();
	REP(i, H) REP(j, W){
		if(chg[i][j] == 0) continue;
		int target = chg[i][j]; int count = 1;
		while(j+count < W and chg[i][j+count] == target) count++;
		if(count >= N) { for(int fr = j; fr < j+count; fr++) res[i][fr] = 0; move = true; }
		count = 1;
		while(i+count < H and chg[i+count][j] == target) count++;
		if(count >= N) { for(int fr = i; fr < i+count; fr++) res[fr][j] = 0; move = true; }
	}
	if(move) clear();
	return;
}

int main(){
	cin >> H >> W >> N;
	REP(i, H){
		string str;	cin >> str;
		REP(j, W)	if(str[j] != '.') res[i][j] = org[i][j] = chg[i][j] = (int)(str[j]-'A'+1);
	}
	REP(i, H) REP(j, W-1){
		swap(chg[i][j], chg[i][j+1]);
		swap(res[i][j], res[i][j+1]);
		clear();
		if(judge()) { cout << "YES" << endl; return 0; }
		REP(k, H) REP(l, W) res[k][l] = chg[k][l] = org[k][l];
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3228
def solve():
    N, Y = map(int, input().split())

    for x in range(N+1):
        for y in range(N+1-x):
            d = Y - x * 10000 - y * 5000
            if d % 1000 == 0:
                z = d // 1000
                if x + y + z == N:
                    print(x, y, z)
                    exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int n;
	int a;
	scanf("%d",&n);
	double sum=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		sum+=(double)1.0/a;
	}
	printf("%.10f\n",1.0/sum);
	return 0;
}


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

int n, a[30];

bool check(int j, int m){//順番に引いていく、全探索
    if(m == 0) return true;
    if(j >= n) return false;
    bool f = check(j + 1, m) || check(j + 1, m - a[j]);//足さなかった時or足した時
    return f;
}
int main(){
    int q, m;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%d", &m);
        if(check(0, m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 3148
import java.io.*;

class Main{
    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String num1 = br.readLine();
        String[] num2 = num1.split(" ");

        int a = Integer.parseInt(num2[0]);
        int b = Integer.parseInt(num2[1]);
        int c = Integer.parseInt(num2[2]);

        int tmp = 0;

        if(a > b){
            tmp = a;
            a = b;
            b = tmp;
        }if(b > c){
            tmp = b;
            b = c;
            c = tmp;
        }if (a > b) {
            tmp = a;
            a = b;
            b = tmp;
        }

        System.out.println(a + " " + b + " " + c);
    }
}

Measured memory_bytes: 24108
#include <iostream>

using namespace std;


int gcd(int a, int b) {

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


int main() {

	int a, b;
	cin >> a >> b;

	cout << gcd(a, b) << endl;

	return 0;
}



Measured memory_bytes: 3108