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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

struct BIT {
  using Val = int;
  int n;
  vector<Val> tree;
  BIT(int n):n(n),tree(n+1) {}
  void fill(Val val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, Val val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  // sum[0, idx]
  Val range(int idx) {
    Val sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
  // sum[a, b]
  Val range(int a, int b) {
    return range(b) - range(a - 1);
  }
};


struct Query {
  int L, R;
  int id;
};

int main2() {
  int N = nextLong();
  int Q = nextLong();
  vector<ll> c(N);
  REP(i, N) c[i] = nextLong();

  vector<Query> qs(Q);
  REP(i, Q) {
    int L = nextLong() - 1;
    int R = nextLong();
    qs[i] = (Query){L, R, i};
  }

  sort(ALL(qs), [](const Query&a, const Query&b) {
    return a.R < b.R;
  });

  vector<int> ans(Q);
  BIT bit(N+5);

  vector<int> last(N + 10, -1);
  int pos = 0;
  for (auto q : qs) {
    while (pos < q.R) {
      if (last[c[pos]] != -1) bit.add(last[c[pos]], -1);
      last[c[pos]] = pos;
      bit.add(last[c[pos]], +1);
      pos++;
    }
    ans[q.id] = bit.range(q.L, q.R - 1);
  }
  REP(i, Q) cout << ans[i] << '\n';

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 19336
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

H,W,K=get_i

$num=1
$ans=array(W,0,H)
def cut(l,r,s)
  pos=[]
  l.upto(r) do|i|
    W.times do|j|
        pos.push(j) if s[i][j]=="#"
    end
  end
  pos.sort!
  pos[0]=0
  pos.push(W)
  (pos.size-1).times do|j|
      pos[j].upto(max(pos[j+1]-1,pos[j])) do|k|
            l.upto(r) do|i|
              $ans[i][k]=$num
          end
      end
      $num+=1
  end
end

s=array(H)
h=[]
H.times do|i|
    s[i]=get_nsp
    h.push(i) if s[i].count("#")>0
end
h[0]=0
h.push(H)
#p h
(h.size-1).times do|i|
  cut(h[i],max(h[i+1]-1,h[i]),s)
end
H.times do|i|
    puts $ans[i].join(" ")
end

Measured memory_bytes: 11640
#include <cstdio>

using namespace std;

int main() {
    int n, a, b, c, d, i;
    
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    
    for (i = 0; i <= n - 1; i++) {
        int x = i, y = n - 1 - x;
        long long p1 = (long long)c * x + a;
        long long q1 = (long long)d * x + a;
        long long p2 = (long long)c * y + b;
        long long q2 = (long long)d * y + b;
        
        if (q1 < p2 || p1 > q2) continue;
        
        puts("YES");
        
        return 0;
    }
    
    puts("NO");
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b,d,e;
    cin>>x>>a>>b;
    d=abs(x-a);
    e=abs(x-b);
    if(d<e)
    {
       cout<<"A"<<endl;
    }
    else
    {
        cout<<"B"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
using namespace std;

int main()
{
    int n, max_w;
    cin >> n >> max_w;
    vector<int> v(n);
    vector<int> w(n);
    for (int i=0; i<n; ++i){
        cin >> v[i] >> w[i];
    }
    int dp[n+1][max_w+1];
    // init
    for (int i=0; i<=n; ++i){
        for (int j=0; j<=max_w; ++j){
            dp[i][j] = 0;
        }
    }
    // solve
    for (int i=0; i<n; ++i){
        for (int j=0; j<=max_w; ++j){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j - w[i]] + v[i]);
            }
            else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][max_w] << endl;
    return 0;
}


Measured memory_bytes: 7032
#include<stdio.h>
#include<string.h>
#define N 1000
int Max(int,int);
int lcn(void);
char X[N+1],Y[N+1];

int main(){
  int i,j,n;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s",X);
    scanf("%s",Y);
    printf("%d\n",lcn());
  }

  return 0;
}

int lcn(){
  int i,j,x,y,max=0;
  int c[N+1][N+1];
  x = strlen(X);
  y = strlen(Y);
  for(i = 1; i <= x; i++) c[i][0] = 0;
  for(i = 1; i <= y; i++) c[0][i] = 0;

  for(i = 1; i <= x; i++){
    for(j = 1; j <= y; j++){
      if(X[i-1] == Y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
      max = Max(max,c[i][j]);
    }
  }
  return max;
}

int Max(int x,int y){
  if(x >= y) return x;
  else return y;
}

Measured memory_bytes: 4512
lis = []
for i in range(3,10):
  l = []
  for _ in range(i):
   if l == []:
    l.append(["3","5","7"])
   else:
    c = l[-1]
    x1 = list(map((lambda x:x+"3"),c))
    x2 = list(map((lambda x:x+"5"),c))
    x3 = list(map((lambda x:x+"7"),c))
    l.append(x1+x2+x3)
  lis += l[-1]

l = [k for k in lis if k.count("3") and k.count("5") and k.count("7")]
l = list(map(int,l))

N = int(input())
if N in l:
 N += 1
l.append(N)
l.sort()
print(l.index(N))
quit()

Measured memory_bytes: 7384
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
using namespace std;

int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
signed main() {
	int a, b; cin >> a >> b;
	cout << a + b + 2 - gcd(a, b) - 1 << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int n, m, ans = 0;
	cin >> n >> m;
	vector<int> h(n + 1);
	vector<vector<int> > vec(n + 1);
	for (int i = 1; i <= n; ++i) cin >> h[i];
	for (int i = 1; i <= m; ++i) {
		int x, y;
		cin >> x >> y;
		vec[x].emplace_back(y);
		vec[y].emplace_back(x);
	}
	for (int i = 1; i <= n; ++i) {
		if (vec[i].empty()) ++ans;
		else {
			bool f = true;
			for (auto j : vec[i])
				if (h[i] <= h[j])
					f = false;
			if(f) ++ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 8756
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;
        int l[12] = {};
        for (int i = 0; i < n; ++i) {
            int d, p;
            cin >> d >> p;
            l[p] += d;
        }
        int ans = 0;
        for (int i = 11; i >= 0; --i) {
            ans += i * max(l[i] - m, 0);
            m = max(m - l[i], 0);
        }
        cout << ans << "\n";
    }
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,a;
    cin>>n>>a;
    Vec x(n);
    cin>>x;
    vector<vector<vector<ll>>> dp(n+1,VV(n*52,Vec(n+2,0)));
    dp[0][0][0] = 1;
    rep(i,n){
        rep(j,n*52){
            rep(k, n){
                dp[i+1][j][k] += dp[i][j][k];
                if(j+x[i]<n*52){
                    dp[i+1][j+x[i]][k+1] += dp[i][j][k];
                }
            }
        }
    }
    ll ans = 0;
    REP(i,1,n+1){
        ans += dp[n][a*i][i];
    }
    out(ans);
    return  0;
}


Measured memory_bytes: 60416
using System;

namespace B___Algae
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var r = read[0];
            var D = read[1];
            var x2k = read[2];

            for(int i = 0 ; i < 10 ; i++)
            {
                x2k = r*x2k -D;
                Console.WriteLine(x2k);
            }
        }
    }
}


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

int main() {
	int a[2];
	cin >> a[0] >> a[1];
	
	sort(a, a+2);
	
	int sum = a[1];
	a[1]--;
	
	sort(a, a+2);
	
	sum += a[1];
	
	cout << sum << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int unsigned long long
#define endl "\n"
using namespace std;

int32_t main() {
  ios;
  int t = 1;
  // cin>>t;
  while(t--) {
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i = 0;i < n;i++) cin>>p[i];
    sort(p,p+n);
    int i = 0,s = 0;
    while(k--) {
      s += p[i++];
    }
    cout<<s;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3652
import java.util.*;
class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long arr[][]= new long[n][3];
        // long res[][] = new long[n][3]; 
        for(int i =0;i<n;i++)
        {
            arr[i][0]=(long)(sc.nextInt());
            arr[i][1]=(long)(sc.nextInt());
            arr[i][2]=(long)(sc.nextInt());
        }
        long max = Long.MIN_VALUE;
        for(int j=1;j<n;j++)
        {
            arr[j][0] += Math.max(arr[j-1][1],arr[j-1][2]);
            arr[j][1] +=Math.max(arr[j-1][0],arr[j-1][2]);
            arr[j][2] +=Math.max(arr[j-1][1],arr[j-1][0]);
        }
        for(int i=0;i<3;i++)
        {
            max = Math.max(max,arr[n-1][i]);
        }
        System.out.println(max);

    }
}

Measured memory_bytes: 64560
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;
typedef std::tuple<int, int> P;



struct Edge{
    int to, cost;
};

namespace W5{
    template<typename T>
    T max(T t){
        return t;
    }

    template<typename First, typename... Rest>
    First max(First f, Rest... r){
        return std::max(f, W5::max(r...));
    }
};

std::vector<Edge> G[3010];
std::vector<int> S;
int d[3010];
int N, M, K;

int dijkstra(){
    int res = 0;
    std::priority_queue<P, std::vector<P>, std::greater<P>> q;
    std::fill(d, d+3010, INF);

    REP(i, K){
        d[S[i]] = 0;
        q.push(std::make_tuple(0, S[i]));
    }

    while(!q.empty()){
        P p = q.top(); q.pop();
        int u = std::get<0>(p), v = std::get<1>(p);
        
        if(d[v] < u){continue;}

        REP(i, G[v].size()){
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                q.push(std::make_tuple(d[e.to], e.to));
                res = std::max(res, d[e.to]);
            }
        }
    }

    return res;
}

int main(){
    std::cin >> N >> M >> K;
    
    REP(i, M){
        int from, to, l;
        std::cin >> from >> to >> l;
        from--; to--;

        G[from].push_back({to, l});
        G[to].push_back({from, l});
    }

    REP(i, K){
        int s;
        std::cin >> s;
        s--;

        S.push_back(s);
    }

    dijkstra();

    int res = 0;
    REP(i, N){
        int l = 0;
        REP(j, G[i].size()){
            Edge e = G[i][j];

            l = std::max(l, static_cast<int>(1. * (d[i] + d[e.to] + e.cost) / 2.0 + 0.5));
        }

        res = W5::max(res, d[i], l);
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 4212
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
 
n,m,x = LI()
a = [LI() for i in range(n)]
result = 12000000
for i in range(1 << n):
    c = 0
    val = [0]*m
    for j in range(n):
        if(i & (1 << j)):
            c += a[j][0]
            for k in range(m):
                val[k] += a[j][k+1]
    f = True
    for j in range(m):
        if(val[j] < x):
            f = False
            break
    
    if(f):
        if(result > c):
            result = c

if(result == 12000000):
    print(-1)
else:
    print(result)

Measured memory_bytes: 9244
// 以下４パターンを考えてやる
// 上に曲がったので次曲がれない
// 上に進んだので次曲がれる
// 右に曲がったので次曲がれない
// 右に進んだので次曲がれる


#include <iostream>
#define up_can 0
#define up_cant 1
#define right_can 2
#define right_cant 3

using namespace std;

typedef long long ll;

int dp[100][100][4];

void getAns(int w, int h){

  for( int i = 0 ; i < h ; i++ )
    for( int j = 0 ; j < w ; j++ ){
      // 初期化
      dp[i][j][up_can] = dp[i][j][up_cant] = 0;
      dp[i][j][right_can] = dp[i][j][right_cant] = 0;
    }

  dp[0][1][up_can] = 1;
  dp[1][0][right_can] = 1;

  for( int i = 0 ; i < h ; i++ ){
    for( int j = 0 ; j < w ; j++ ){
      dp[i][j][up_can] %= 100000;
      dp[i][j][up_cant] %= 100000;
      dp[i][j][right_can] %= 100000;
      dp[i][j][right_cant] %= 100000;   

    if( i < h - 1 ){
	// 曲がらずに（曲がれないから）進み次に曲がれる（ようになる）
	dp[i + 1][j][right_can] += dp[i][j][right_cant]; // 曲がれないから次に曲がれる
	dp[i + 1][j][right_can] += dp[i][j][right_can]; // 右にそのまま
	// 上に曲がって進み、次曲がれない
	dp[i + 1][j][right_cant] += dp[i][j][up_can];
      }
      if( j < w - 1 ){
	// 曲がらずに（曲がれないから）進み次に曲がれる（ようになる）
	dp[i][j + 1][up_can] += dp[i][j][up_cant]; //曲がれないから次に曲がれる
	dp[i][j + 1][up_can] += dp[i][j][up_can]; // 上にそのまま
	// 右に曲がって進み、次曲がれない
	dp[i][j + 1][up_cant] += dp[i][j][right_can];
      }
    }
  }

}

int main(void){

  int w,h;
  while( cin >> w >> h, w || h ){

    getAns(w, h);
    cout << ( dp[h - 1][w - 1][0] + dp[h - 1][w - 1][1] + dp[h - 1][w - 1][2] + dp[h - 1][w - 1][3] ) % 100000 << endl;

  }
  return 0;
}

Measured memory_bytes: 1316
N,X = map(int,input().split())
ls = []
ls = list(map(int,input().split()))
an = []
an.append(0)
for i in range(len(ls)):
    if i == 0:
        an.append(ls[i])
    else:
        an.append(ls[i] + an[i])
p = 0

for j in an:
    if j <= X:
        p+=1
print(p)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const int MAX_V = 500;
const int INF = 1e9;

// 辺を表す構造体（行き先，容量，逆辺）
struct edge { int to, cap, rev; };

vector<vector<edge>> G(MAX_V);
vector<bool> used(MAX_V);

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
    int n = G[to].size();
    int m = G[from].size();
    G[from].push_back((edge){to, cap, n});
    G[to].push_back((edge){from, 0, m});
}

// 増加パスをDFSで探す
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f,e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t) {
    int flow = 0;
    while(flow <= 100) {
        for (int j = 0; j < used.size(); j++) used[j] = 0;
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
    return 0;
}


int main() {
    int N; cin >> N;
    vector<int> a(N), b(N), c(N), d(N);

    rep(i,N) cin >> a[i] >> b[i];
    rep(i,N) cin >> c[i] >> d[i];
    rep(i,N) {
        rep(j,N) {
            if (a[i] < c[j] && b[i] < d[j]) add_edge(i+1,j+201,1);
        }
    }
    rep(i,N) add_edge(0,i+1,1);
    rep(i,N) add_edge(i+201,401,1);

    cout << max_flow(0,401) << endl;
}


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

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			int k=in.nextInt();
			String s=in.next();
			if(s.length()<=k) out.println(s);
			else out.println(s.substring(0,k)+"...");
		}
		out.close();		
		
	}

	static boolean tri(int a, int b, int c) {
		if(c<a+b && c>abs(a-b)) return true;
		return false;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static int max(int a, int b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

Measured memory_bytes: 36836
//abc089_c.cpp
//Sun Mar  4 20:55:53 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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

	string str;
	unsigned long m = 0;
	unsigned long a = 0;
	unsigned long r = 0;
	unsigned long c = 0;
	unsigned long h = 0;
	for (int i=0;i<n;i++){
		cin >> str;
		if (str[0] == 'M'){
			m++;
		}else if (str[0] == 'A'){
			a++;
		}else if (str[0] == 'R'){
			r++;
		}else if (str[0] == 'C'){
			c++;
		}else if (str[0] == 'H'){
			h++;
		}
	}

	unsigned long answer=0;

	answer = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;

	cout << answer << endl;
}

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


int main()
{
    int n;
    
    scanf("%d", &n);
    if (n == 0)
        printf("1");
    else
        printf("0");
    
    
    
   

}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> grid(H);
  for(int i=0; i<H; i++){
      cin >> grid.at(i);
  }

  vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
  vector<int> dy = {0, 1, 1, 1, 0, -1, -1, -1};

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(grid.at(i).at(j) == '.'){
        int cnt = 0;
        for(int k=0; k<8; k++){
          int tmp_x = i+dx.at(k);
          int tmp_y = j+dy.at(k);
          if(tmp_x >= 0 && tmp_x < H &&
             tmp_y >= 0 && tmp_y < W &&
             grid.at(tmp_x).at(tmp_y) == '#'){
               cnt++;
             }
        }
        grid.at(i).at(j) = char(cnt + '0');
      }
    }
  }

  for(int i=0; i<H; i++){
    cout << grid.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n=0,i=0,j=0,count=0;
  cin >> n;
  long long int arr[n+1],dp[n+1];
  memset(arr,0,sizeof(arr));
  for(i=0;i<n;i++){
  	cin >> arr[i];
  }
  dp[0] = 0;
  dp[1] = abs(arr[1] - arr[0]);
  dp[2] = min(dp[1] + abs(arr[2] - arr[1]),abs(arr[2]-arr[0]));
  for(i=3;i<n;i++){
  dp[i] = min( abs(arr[i] - arr[i-1])+dp[i-1],abs(arr[i-2]-arr[i]) + dp[i-2]);
  }
  cout << dp[n-1]<<endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int x;
  cin >> x;
  for(ll i = 1;i < 100000;i++){
    if((360ll*i%x) == 0){
      cout << 360ll*i/x << endl;
      return 0;
    }
  }



  return 0;
}

Measured memory_bytes: 3632
//ΔAGC034B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
int n;
char s[N];
int main()
{
	int i,x=0;
	LL o=0;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i=i+1){
		if(s[i]=='A')
			x++;
		else{
			if(s[i]=='B'&&s[i+1]=='C')
				o+=x,i++;
			else
				x=0;
		}
	}
	cout<<o;
	return 0;
}

Measured memory_bytes: 384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
int main(void){
	int n,m,i,j,ans=0;cin>>n>>m;
	vector<vector<int>>hana(m);
	vector<vector<int>>spe(n);
	vector<bool>koto(m);
	vector<bool>hito(n);
	for(i=0;i<n;i++){
		int k;cin>>k;
		while(k--){int L;cin>>L;L--;hana[L].pub(i);spe[i].pub(L);}
	}
	queue<int>que;
	que.push(spe[0][0]);
	while(que.size()>0){
		int gen=que.front();que.pop();
		if(koto[gen]){continue;}koto[gen]=true;
		for(auto it:hana[gen]){
			if(hito[it]){continue;}hito[it]=true;ans++;
			for(auto itr:spe[it]){que.push(itr);}
		}
	}
	cout<<(ans==n?"YES":"NO")<<endl;
	RE;
}

Measured memory_bytes: 8824
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    string s;
    cin >> s;
    ll ans = 700;
    for (ll i = 0; i < 3; i++)
    {
        if (s[i] == 'o'){
            ans += 100;
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int n, sum = 0, curr_height = 0;
  cin >> n;
  int arr[n], vect[n] = {0};
  for(int i=0; i<n; i++)
  {
    cin >> arr[i];
  }
  vect[0] = 0;
  vect[1] = abs(arr[1] - arr[0]);
  for(int i=2; i<n; i++)
  {
    vect[i] = min(abs(arr[i] - arr[i-1]) + vect[i-1],abs(arr[i] - arr[i-2]) + vect[i-2]);
  }

  	cout << vect[n-1];
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//インデックスの文字には注意

int main(void){
	ll ans=0;
	int N,L[202];
	cin>>N;
	rep(i,2*N){
		cin>>L[i];
	}
	sort(L,L+2*N);
	rep(i,N){
		ans+=L[i*2];
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ld l;
	cin>>l;
	cout<<(l*l*l)/27.0<<endl;

	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> t, x, y;
    int in_t, in_x, in_y;
    t.emplace_back(0);
    x.emplace_back(0);
    y.emplace_back(0);

    for (int i = 0; i < N; i++)
    {
        cin >> in_t >> in_x >> in_y;
        t.emplace_back(in_t);
        x.emplace_back(in_x);
        y.emplace_back(in_y);
    }

    int prvt = 0;
    int d;
    for (int i = 1; i <= N; i++)
    {
        d = (x[i] - x[i - 1]) + (y[i] - y[i - 1]);
        if (d > (t[i] - t[i - 1]))
        {
            cout << "No" << endl;
            return 0;
        }else
        {
            if ((d - (t[i] - t[i - 1])) % 2 == 0)
            {
                continue;
            }else
            {
                cout << "No" << endl;
                return 0;
            }
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 1644
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,t = readline() |> split |> parseMap
    a = Tuple{Int,Int}[(0,0) for i in 1:n]
    for i in 1:n
        p,q = readline() |> split |> parseMap
        a[i] = (p,q)
    end
    a = sort(a,by=x->x[1])
    dp = -ones(Int,n+1,t+3000)
    dp[1,1] = 0
    for i in 1:n
        for j in 1:t
            if dp[i,j]>-1
                dp[i+1,j] = max(dp[i+1,j],dp[i,j])
                dp[i+1,j+a[i][1]] = max(dp[i+1,j+a[i][1]], dp[i,j]+a[i][2])
            end
        end
    end
    println(maximum(dp))
end
main()

Measured memory_bytes: 400788
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>

int main(){

    std::array<int, 5> a;
    int k;

    for(auto &&e : a){
        std::cin >> e;
    }

    std::cin >> k;

    for(size_t i = 0; i < a.size() - 1; i++){
        for(size_t j = i; j < a.size(); j++){
            if(a[j] - a[i] > k){
                std::cout << ":(" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "Yay!" << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <unistd.h>


#define ll long long
#define lst(x) x.size()-1
#define ld long double
#define pr pair<ll,ll>
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define rep(i,x,n) for(int i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using os = tree<T, null_type, less_equal<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const ll N=3e5+5,M=1e1+5,MOD=1e9+7,OO=1e13;
int h,n,sum;
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "rt" , stdin);
    // freopen("in.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
    cin>>h>>n;
    loop(i,n){
        int x;
        cin>>x;
        sum+=x;
    }
    cout<<(sum>=h?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

bool cross(int x1,int y1,int r1,int x2,int y2,int r2){
	if((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)<(r1+r2)*(r1+r2))return true;
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	while(cin>>N,N){
		vector<int>x(N);
		vector<int>y(N);
		vector<int>r(N);
		vector<int>c(N);
		for(int i=0;i<N;i++){
			cin>>x[i]>>y[i]>>r[i]>>c[i];
		}
		bitset<1024*1024*4*4>bs;
		bs.flip(0);
		for(int i=0;i<1<<N;i++){
			if(!bs.test(i))continue;
			for(int j=0;j<N;j++){
				if((i>>j)&1)continue;
				bool fed=false;
				for(int k=0;k<j;k++){
					if((i>>k)&1)continue;
					fed|=cross(x[j],y[j],r[j],x[k],y[k],r[k]);
				}
				if(fed)continue;
				for(int k=j+1;k<N;k++){
					if((i>>k)&1)continue;
					if(c[k]!=c[j])continue;
					bool sed=false;
					for(int l=0;l<k;l++){
						if((i>>l)&1)continue;
						sed|=cross(x[k],y[k],r[k],x[l],y[l],r[l]);
					}
					if(sed)continue;
					bs.set(i|(1<<j)|(1<<k));
				}
			}
		}
		int ans=0;
		for(int i=0;i<1<<N;i++){
			if(!bs.test(i))continue;
			int box=0;
			for(int j=0;j<N;j++)box+=(i>>j)&1;
			ans=max(ans,box);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 5184
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int

signed main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int c = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == '1'){c++;}else{break;}
    }
    if(c>=k){
        cout << 1 << endl;
    }else{
        cout << s[c] << endl;
    }
}

Measured memory_bytes: 256
n=int(input())

a=list(map(int,input().split()))
b=0
for i in range(n):

    if a[i-1]%2==1:
        b=b+1
    elif a[i-1]%3==0 or a[i-1]%5==0:
        b=b+1
    
if b==n:
    print("APPROVED")
else:
    print("DENIED")


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

cnt = 0
for i in range(n):
    min_a = min(a)
    a.remove(min_a)
    if x < min_a:
        break
    x -= min_a
    cnt += 1

if cnt == n and x != 0:
    cnt -= 1

print(cnt)



Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<utility>
#include<bitset>
#include<climits>
#include<cstdio>
#include<cassert>
#include<climits>
using namespace std;
#define INF INT_MAX

int pay;
int c[4];//10.50.100.500
void init(){
  pay=c[0]=c[1]=c[2]=c[3]=0;
}
bool input(){
  cin>>pay;
  if(pay==0)return false;
  cin>>c[0]>>c[1]>>c[2]>>c[3];
  return true;
}

int toC(int i){
  switch(i){
    case 0:return 10;
    case 1:return 50;
    case 2:return 100;
    case 3:return 500;
    default:return INF;
  }
}


vector<pair<int,int> > solve(){
  vector<pair<int,int> > res;
  vector<int> turi;
  turi.resize(4);
  int sum=0;
  for(int i=0;i<4;i++){
    sum+=c[i]*toC(i);
  }
  sum-=pay;
  for(int i=4;i--;){
    if(sum<=0)break;
    turi[i]=sum/toC(i);
    sum=sum%toC(i);
  }
  for(int i=0;i<4;i++){
    if(0<c[i]-turi[i]){
      res.push_back(make_pair(toC(i),c[i]-turi[i]));
    }
  }
  
  sort(res.begin(),res.end());
  return res;
}

int main(){
  int cc=0;
  while(init(),input()){
    if(cc!=0){
      cout<<endl;
    }
    cc++;
    vector<pair<int,int> > ans=solve();
    for(int i=0;i<ans.size();i++){
      cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
  }
}

Measured memory_bytes: 1196
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  uint64_t N;
  cin >> N;
  uint64_t sum = 0;
  for (uint64_t i = 1; i <= N; ++i) {
    if (i % 3 != 0 && i % 5 != 0)
      sum += i;
  }

  cout << sum;
  return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
    	int a, b, c, x, y;
    	cin >> a >> b >> c >> x >> y;
     
    	int price = 0;
    	price += min(a+b, 2*c)*min(x, y);
     
    	if (x >= y) {
    		price += min(a, 2*c)*(x-y);
    	} else {
    		price += min(b, 2*c)*(y-x);
    	}
     
    	cout << price << endl;
    }

Measured memory_bytes: 256
/*1803115*/
#include <stdio.h>
int main()
{
    char ch;
    int x,c[26]= {0};

    while(scanf("%c",&ch)!=EOF)
    {
        if(ch>='A' && ch<='Z')
        {
            x=ch-'A';
            c[x]+=1;
        }
        else if(ch>='a' && ch<='z')
        {
            x=ch-'a';
            c[x]+=1;
        }
    }

    for(x=0,ch='a'; x<26; x++,ch++)
    {
        printf("%c : %d\n",ch,c[x]);
    }
    return 0;
}



Measured memory_bytes: 2084
#include <stdio.h>
#define NIL -1
void dep(int u,int k);
int high(int u);
int sib(int u);
void print(int u);

typedef struct Node{
  int p;
  int l;
  int r;
} node;
  
node T[10005];
int n,Dp[10005],H[10005];

int main(){
  int i,j;
  int v,root=0,left,right;

  scanf("%d",&n);
  //ini
  for(i=0;i<n;i++) T[i].p=-1;
  
  //input
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&left,&right); 
    T[v].l=left;
    T[v].r=right;
    if(left!=NIL) T[left].p=v;
    if(right!=NIL) T[right].p=v;
  }

  for(i=0;i<n;i++){
    if(T[i].p==NIL) root=i;
  }

  dep(root,0);
  high(root);

  for(i=0;i<n;i++) print(i);

  return 0;
}

void dep(int u,int k){  
  //calc depth
  if(u==NIL) return;  
  Dp[u]=k;
  dep(T[u].r,k+1);
  dep(T[u].l,k+1);
}

int high(int u){
  int h,x=0,y=0;

  //calc height(left,right)
  if(T[u].l!=NIL) x=high(T[u].l)+1;
  if(T[u].r!=NIL) y=high(T[u].r)+1;

  //get bigger value(left,right)
  if(x<y) H[u]=y; 
  else H[u]=x;

  return H[u];
}

int sib(int u){
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL) return T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=NIL) return T[T[u].p].r;
  return NIL;
}

void print(int u){
  int dg=0;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",sib(u));

  if(T[u].l!=NIL) dg++;
  if(T[u].r!=NIL) dg++;
  printf("degree = %d, ",dg);
  printf("depth = %d, ",Dp[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p==NIL) printf("root\n");
  else if(T[u].l==NIL && T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 100005;

lint dap[MAXN];

struct disj{
	int pa[MAXN], sz[MAXN];
	lint offset[MAXN];
	vector<int> nd[MAXN];
	void init(int n){
		for(int i=1; i<=n; i++){
			pa[i] = i;
			sz[i] = 1;
			nd[i].push_back(i);
		}
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q, lint x){
		p = find(p);
		q = find(q);
		if(sz[p] < sz[q]) swap(p, q);
		pa[q] = p;
		offset[p] += sz[q] * x;
		for(auto &i : nd[q]){
			dap[i] += sz[p] * x + offset[q];
			dap[i] -= offset[p];
			nd[p].push_back(i);
		}
		sz[p] += sz[q];
		return 1;
	}
}disj;

struct edg{
	int s, e, x;
	bool operator<(const edg &e)const{
		return x > e.x;
	}
}v[MAXN];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e, x;
		scanf("%d %d %d",&s,&e,&x);
		v[i] = {s, e, x};
	}
	sort(v+1, v+n);
	disj.init(n);
	for(int i=1; i<n; i++){
		disj.uni(v[i].s, v[i].e, v[i].x);
	}
	lint f = disj.offset[disj.find(1)];
	for(int i=1; i<=n; i++) printf("%lld\n",f +  dap[i]);
}


Measured memory_bytes: 13944
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	inputs := scanIntNums()
	fmt.Println(check(inputs))
}

func check(nums []int) int {
	a := nums[0]
	b := nums[1]

	if (a < 1) || (10 <= a) || (b < 1) || (10 <= b) {
		return -1
	}
	return a * b

}

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	mp := make(map[string]int)
	var word string
	fmt.Scan(&word)
	start := word[len(word) - 1]
	mp[word] = 1
	for i := 0; i < n - 1; i++ {
		fmt.Scan(&word)
		if word[0] != start {
			fmt.Println("No")
			return
		}
		_, ok := mp[word]
		if ok {
			fmt.Println("No")
			return
		}
		start = word[len(word) - 1]
		mp[word] = 1
	}
	fmt.Println("Yes")
}

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

int main(){
    string s;
    cin >> s;
    int t = s.size();
    while(t > 1){
        t -= 2;
        if(s.substr(0, t/2) == s.substr(t/2, t/2)) break;
    }
    cout << t << endl;
}

Measured memory_bytes: 3620
# input
r,c = input().split()
r = int(r)
c = int(c)

Data = []

while True:
    if r == 0:
        break
    temp = input().split()
    Data.append(list(map(int,temp)))
    r -= 1

# output
for a in Data:
    a.append(sum(a))

temp = [0]*(c+1)
for a in Data:
    temp = [x + y for(x,y) in zip(temp,a)]
Data.append(temp)

for a in Data:
    b = map(str,a)
    print(' '.join(b))



Measured memory_bytes: 5712
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int y, x;
	char field[100][100];

	scanf("%d %d", &y, &x);

	char c;
	for (int i = 0; i < y; i++) {
		scanf("%s", field[i]);
	}

	int v;
	for (int i = 0; i < y; i++) {
		v = -1;
		for (int j = 0; j < x; j++) {
			if (field[i][j] == 'c') {
				v = 0;
			}
			else if (v >= 0) {
				v++;
			}

			if (j == x - 1) {
				printf("%d", v);
			}
			else {
				printf("%d ", v);
			}
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1048
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <string,int> earn,lose;
    int n; cin>>n; 
    while (n--){
        string s; cin>>s;
        earn[s]++;
    }
    cin >> n;
    while (n--){
        string  s; cin>>s;
        earn[s]--;
    }
    int ans=0;
    for (auto it: earn)
        ans = max(ans,earn[it.ff]);
    cout << ans << endl;
}

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


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

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  
  double b=0;
  double c=0;
  for(int i=0;i<N;i++){
    b=b+1.00000000/a.at(i);
  }
  c=1.0000000000/b;
  cout<<fixed<<c<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  int n,a,b;
  int ans=0;
  cin>>n>>a>>b;
  while(b-a>1){
    ans++;
    a++;
  }
  while(b-a>1){
    b--;
    ans++;
  }
  if(ans%2==0)
  cout<<"Borys"<<endl;
  else
  cout<<"Alice"<<endl;
}


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

int main() {
	int n, k, a;
	cin >> n >> k;
	vector<char> d(k);
	for(int i = 0; i < k; i++){
		cin >> d.at(i);
	}
	a = n;
	while(1){
		for(int i = 0; i < k; i++){
			if(to_string(a).find(d.at(i)) != string::npos){
				a += 1;
				break;
			}
			if(i == k - 1){
				cout << a << endl;
				return 0;
			}
		}
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=200005;
const ll INF=0x3f3f3f3f;
const ll MOD=1000000007;
ll n,a[MAX],c[MAX],l,r,fact[MAX];
ll power(ll x,ll y){
    if(y==0) return 1;
    ll t=power(x,y/2);
    if(y%2) return t*t%MOD*x%MOD;
    return t*t%MOD;
}
ll comb(ll x,ll y){
    if(x<y||y<0) return 0;
    if(x==y||y==0) return 1;
    return fact[x]*power(fact[x-y],MOD-2)%MOD*power(fact[y],MOD-2)%MOD;
}
int main()
{
    scanf("%lld",&n);
    for(ll i=0;i<n+1;i++) scanf("%lld",&a[i]);
    fact[0]=1;
    for(ll i=1;i<=n+1;i++) fact[i]=fact[i-1]*i%MOD,fact[i]%=MOD;
    for(ll i=0;i<n+1;i++) {
        if(c[a[i]]==0) c[a[i]]=i+1;
        else{
            ll t1=c[a[i]]-1,t2=i;
            if(t1>t2) swap(t1,t2);
            l=t1,r=n-t2;
        }
    }
    for(ll i=1;i<=n+1;i++){
        printf("%lld\n",(comb(n+1,i)-comb(l+r,i-1)+MOD)%MOD);
    }
}


Measured memory_bytes: 4480
package main

import (
	"bufio"
	"os"
	"fmt"
	"strings"
	"strconv"
	"math"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	string_list := strings.Split(text, " ")
	N, _ := strconv.ParseFloat(string_list[0], 64)
	K, _ := strconv.ParseFloat(strings.Trim(string_list[1], "\r\n"), 64)
	
	res := 0.0

	for i := 1.0; i <= N; i++ {
		c := 0.0
		p := i
		for p < K {
			p = p * 2
			c++
		}
		res = res + ((1.0 / N) * math.Pow(0.5, c))
	}
	fmt.Println(res)
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

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

const int MAXN = 21;
int dc = 0;

string dif(string a, string b)
{
    int down = 0;
    string ans = a;
    for(int i = dc -1; i > -1; i--)
    {
        if(a[i] - b[i] - down < 0)
        {
            ans[i] = (a[i] - b[i] - down + 10) + '0';
            down = 1;
        }
        else
        {
            ans[i] = (a[i] - b[i] - down ) + '0';
            down = 0;
        }
    }
    return ans;

}

int main()
{
    string in;
    while(cin >>in >> dc && dc)
    {
        string a[MAXN] = {};
        a[0] = in;
        while(a[0].size() < dc) a[0] = "0" + a[0];

        string nexta;
        REP(MAXN - 1)
        {
            string mina = a[i];
            sort(mina.begin(), mina.end());
            string maxa = mina;
            //reverse(maxa.begin(), maxa.end());
            sort(maxa.begin(), maxa.end(), greater<char>() );
            //cout <<"max:" << maxa << " min:" << mina << endl;
            a[i+1] = dif(maxa, mina);
            //cout <<i+1 << " a:" <<  a[i+1] <<endl;
        }
        

        int ansed = false;
        ///cout << "dc " << dc << endl;
        for(int i = 1; i<MAXN;i++)
        {
            if(ansed) break;
            for(int j = 0; j < i;j++)if(!ansed && a[j] == a[i])
            {
                cout << j << " "; 
                int starti = 0;
                for(starti  = 0;starti < dc ; starti++)
                {   
                    if(a[i][starti] != '0')break;
                    //cout << starti << " " << endl;
                }
                //cout << "starti " << starti << endl;

                if(starti == dc) cout << "0" ;
                else cout << a[i].substr(starti, a[i].size() - starti);

                cout << " " << i-j << endl;
                ansed = true;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 0