akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10**5)

def main():
    N, M, K = map(int, input().split())
    parent = [n for n in range(0, N+1)]
    depth  = [1 for _ in range(0, N+1)] 
    blocks = [[] for _ in range(0, N+1)]
    friends = [[] for _ in range(0, N+1)]

    def root(x):
        p = parent[x]
        if p == x:
            return x
        p = root(p)
        parent[x] = p
        return p

    def union(a, b):
        pa = root(a)
        pb = root(b)
        if pa == pb:
            return
        if depth[pa] > depth[pb]:
            parent[pb] = pa
            depth[pa] += depth[pb]
        elif depth[pa] < depth[pb]:
            parent[pa] = pb
            depth[pb] += depth[pa]
        else:
            parent[pa] = pb
            depth[pb] *= 2
        #print((a, b), pa, pb, root(a), depth[2])

    for i in range(M):
        A, B = map(int, input().split())
        friends[A].append(B)
        friends[B].append(A)
        union(A, B)

    for i in range(K):
        C, D = map(int, input().split())
        blocks[C].append(D)
        blocks[D].append(C)
    if 0==1:
        print("index :", *range(1,N+1))
        print("parent:", *parent[1:])
        print("depth :", *[depth[root(x)] for x in range(1,N+1)])
        for n in range(1, N+1):
            p = root(n)
            c = depth[p]-1
            print(c, end=" ")
        print()

    for n in range(1, N+1):
        p = root(n)
        c = depth[p]-1
        for f in friends[n]:
            if root(f) == p:
                c-=1
        for b in blocks[n]:
            if root(b) == p:
                c-=1
        print(c, end=" ")
    print()

main() 


Measured memory_bytes: 42096
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

// 最大公約数を返す
constexpr long long gcd(long long a, long long b) {
	if(a < b) {
		std::swap(a, b);
	}

	long long r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

constexpr ll div_ceil(ll a, ll b) {
	return (a + b - 1) / b;
}

int main() {
	int n;
	cin >> n;
	VLL t(n), a(n);
	REP(i, n) { cin >> t[i] >> a[i]; }

	ll x = 1, y = 1;
	REP(i, n) {
		ll multiply = max(div_ceil(x, t[i]), div_ceil(y, a[i]));
		x = t[i] * multiply;
		y = a[i] * multiply;
	}

	cout << x + y << endl;
	return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<queue>

using namespace std;

struct Process{
  string name;
  int t;
};

int main(){

  int N,Q;
  cin >> N >> Q;
  queue<Process> que;
  while(N--){
    Process p;
    cin >> p.name >> p.t;
    que.push(p);
  }

  int current = 0;
  while(!que.empty()){
    Process tmp = que.front();
    que.pop();
    
    if(tmp.t > Q){
      current += Q;
      tmp.t -= Q;
      que.push(tmp);
    }else{
      current += tmp.t;
      cout << tmp.name << " " << current << endl;
    }
  }
  return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n, a, b;
	cin >> n >> a >> b;

	vector<int> ans(a, 1);

	int m = n-a;

	if(ans[0]+m < b){
		cout << -1 << endl;
		return 0;
	}else{
		for(int i = 0;i < ans.size()-1;i++){
			ans[i] += min(b-1, m);
			m -= min(m, b-1);
			if(m == 0) break;
		}

		if(ans[a-1]+m > b){
			cout << -1 << endl;
			return 0;
		}else{
			ans[a-1] += m;
		}
	}

	vector<int> an(n);

	int now = 0;
	int idx = 0;
	for(int i = 0;i < a;i++){
		now += ans[i];
		int tmp = now; 
		for(int j = 0;j < ans[i];j++){
			an[idx++] = tmp--;
		}
	}

	for(int i = 0;i < n;i++){
		cout << an[i];
		if(i < n-1){
			cout << " ";
		}else{
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 6144
import sys
readline = sys.stdin.readline

X = readline().rstrip()

cnt = 0
ans = 0
# Sが出たら1増やし、Tが出たら1減らす
# 0のときにTが出たらansを+1する。ans * 2が答え
for i in range(len(X)):
  if X[i] == "S":
    cnt += 1
  else:
    if cnt == 0:
      ans += 1
    else:
      cnt -= 1
      
print(ans * 2)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll n;
struct Node{
    ll par;
    vector<ll> chi;
};
Node node[500001];
vector<ll> v[500001];
void init(ll x){
    rep(i,0,(ll)v[x].size()-1){
        if(v[x][i]!=node[x].par){
            node[x].chi.pb(v[x][i]);
            node[v[x][i]].par=x;
            init(v[x][i]);
        }
    }
}
void init(){
    cin>>n;
    rep(i,0,n-2){
        ll x,y;cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    node[1].par=1;
    init(1);
}

ll hoge(ll x){
    ll res=0;
    if(node[x].chi.size()==0){
        return 0;
    }else{
        rep(i,0,node[x].chi.size()-1){
            res=res^(hoge(node[x].chi[i])+1);
        }
        return res;
    }
}

int main(){fastio
    init();
    if(hoge(1)==0){
        cout<<"Bob"<<endl;
    }else{
        cout<<"Alice"<<endl;
    }
    
    return 0;
}





Measured memory_bytes: 41728
from collections import defaultdict
from collections import deque


n, m = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(m)]
g = defaultdict(list)

for u, v in edges:
    g[u].append(v)
    g[v].append(u)


ans = [0] + [0] * n
queue = deque([(1, 0)])
visited = set()
dist = 0

while queue:
    for _ in range(len(queue)):
        node, pre_node = queue.popleft()
        if node in visited:
            continue
        ans[node] = pre_node
        visited.add(node)
        for n in g[node]:
            if n in visited:
                continue
            queue.append((n, node))
    dist += 1

if len(visited) < n:
    print("No")
else:
    print("Yes")
    for i in range(2, len(ans)):
        print(ans[i])








Measured memory_bytes: 74696
L, *A = map(int, open(0).read().split())
a0 = a1 = a2 = a3 = a4 = 0
rest = sum(A)
P = [2, 1, 0]
Q = [1, 0, 1]
for a in A:
    b = (a - 1) % 2 + 1 if a else 0
    p = P[b]; q = Q[b]
    a0 += a
    a1 = min(a0, a1 + p)
    a2 = min(a1, a2 + q)
    a3 = min(a2, a3 + p)
    a4 = min(a3, a4 + a)
print(min(a0, a1, a2, a3, a4))

Measured memory_bytes: 25124
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSData *stdinData = [[NSFileHandle fileHandleWithStandardInput] availableData];
        NSString *s = [[NSString alloc] initWithData:stdinData encoding:NSUTF8StringEncoding];
        NSArray *l = [s componentsSeparatedByString:@" "];
        NSInteger N = [[l objectAtIndex:0] integerValue];
        NSInteger A = [[l objectAtIndex:1] integerValue];
        NSInteger B = [[l objectAtIndex:2] integerValue];
        NSString *answer = [NSString stringWithFormat:@"%ld",MIN(N*A,B)];
        
        NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
        [fileHandle writeData:[answer dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle closeFile];
    }
    return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}

signed main(){
	int n;
	cin>>n;
	cout<<3*n*n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    a -= b;
    out(max(0, c - a));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, K, a[100002];

int gcd(int n, int m){
	if(!m)	return n;
	return gcd(m, n % m);
}

int main(){
	scanf("%d %d", &N, &K);
	int mx = -1e9;
	for(int i = 0; i < N; i++){
		scanf("%d", a + i);
		mx = max(mx, a[i]);
	}
	int g = a[0];
	for(int i = 1; i < N; i++){
		g = gcd(g, a[i]);
	}
	if(mx < K){
		puts("IMPOSSIBLE");
		return 0;
	}
	if(K % g == 0)	puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

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

int main(void){
  int n, x = 0;
  int max = 0;
  string s;

  cin >> n >> s;

  for(int i = 0; i < s.size(); i ++){
    if(s.at(i) == 'I'){
      x ++;
      if(max < x) max = x;
    }
    else x --;
  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
   public static void main(String args[]){
         Scanner str = new Scanner(System.in);
         int X = str.nextInt();
         int Y = str.nextInt();
         String r = String.valueOf(X*Y);
         String l = String.valueOf((X+Y)*2);
         System.out.println(r + " " +l);     
   }

}

Measured memory_bytes: 25884
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int max = 0;
    int ans = Integer.MAX_VALUE;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
      min = Math.min(min, list.get(i));
      max = Math.max(max, list.get(i));
    }
    for (int i = min; i <= max; i++) {
      int total = 0;
      for (int j = 0; j < N; j++) {
        total += Math.pow(i - list.get(j), 2);
      }
      ans = Math.min(ans, total);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
def e_rem_of_sum_is_num():
    # 参考: https://maspypy.com/atcoder-参加感想-2019-11-16abc-146
    from itertools import accumulate
    from collections import defaultdict

    N, K = [int(i) for i in input().split()]
    # 1 引くと、条件を満たす連続部分列の要素の平均は 0 (mod K で) となる
    A = [0] + [int(i) - 1 for i in input().split()]

    acc = list(accumulate(A))
    acc = [x % K for x in acc]  # mod K 上で同一視する

    # S_j ≡ S_i となるような j-K < i < j の個数を数え上げればいい。
    # そのためには、j 未満のインデックスに対する S の度数分布を管理しておけばいい。
    counter = defaultdict(int)  # 値の度数分布
    ans = 0
    for j, x in enumerate(acc):
        ans += counter[x]
        # 数列の右端を追加
        counter[x] += 1
        # 数列の左端を削除 (数列の長さが K 未満になるようにする。
        # 数列の長さが K 以上だと、数列の和を K で割った余りと一致するはずがない)
        if j - K + 1 >= 0:
            counter[acc[j - K + 1]] -= 1
    return ans

print(e_rem_of_sum_is_num())

Measured memory_bytes: 41984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=3700000;
const int INF=123456789;

int f[11];
int dp1[N], dp2[N];

map<vector<int>,int> M;
inline int get_idx(const vector<int> &a)
{
    if(M.count(a)) return M[a];

    int n = a.size();
    int ret=0;

    vector<bool> use(n,false);
    rep(i,n)
    {
        int ct=0;
        rep(j,a[i])if(!use[j]) ++ct;

        ret += ct*f[n-1-i];

        use[a[i]]=true;
    }
    return M[a]=ret;
}

inline vector<int> get_vec(int n, int idx)
{
    vector<int> ret(n);
    vector<bool> use(n,false);
    rep(i,n)
    {
        int s = idx/f[n-1-i];
        int j=0,ct=0;
        while(1)
        {
            if(!use[j])
            {
                ++ct;
                if(ct==s+1) break;
            }
            ++j;
        }

        use[j]=true;
        ret[i]=j;
        idx -= s*f[n-1-i];
    }
    return ret;
}

int main()
{
    f[0]=1;
    for(int i=1; i<=10; ++i) f[i] = f[i-1]*i;

    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n)
    {
        cin >>a[i];
        --a[i];
    }

    int g = get_idx(a);
    queue<int> que;

    fill(dp1,dp1+N,INF);
    dp1[0]=0;
    que.push(0);
    while(!que.empty())
    {
        int now = que.front();
        que.pop();

        vector<int> x = get_vec(n,now);
        // printf(" now %d\n", now);
        rep(i,n)for(int j=i+1; j<=n; ++j)
        {
            reverse(x.begin()+i, x.begin()+j);

            int nx = get_idx(x);
            // printf("  nx %d\n", nx);
            if(dp1[nx]>dp1[now]+1)
            {
                dp1[nx] = dp1[now]+1;
                if(dp1[nx]<4) que.push(nx);
            }

            reverse(x.begin()+i, x.begin()+j);
        }
    }

    fill(dp2,dp2+N,INF);
    dp2[g]=0;
    que.push(g);
    while(!que.empty())
    {
        int now = que.front();
        que.pop();

        vector<int> x = get_vec(n,now);
        rep(i,n)for(int j=i+1; j<=n; ++j)
        {
            reverse(x.begin()+i, x.begin()+j);

            int nx = get_idx(x);
            if(dp2[nx]>dp2[now]+1)
            {
                dp2[nx] = dp2[now]+1;
                if(dp2[nx]<4) que.push(nx);
            }

            reverse(x.begin()+i, x.begin()+j);
        }
    }

    int ans=9;
    rep(i,N)if(dp1[i]<INF && dp2[i]<INF) ans=min(ans,dp1[i]+dp2[i]);

    printf("%d\n", ans);
    return 0;
}

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

char solve(char x , int n) {
  int pos = x - 'A' ;
  pos += n ;
  if(pos >= 26) pos -= 26 ;
  return 'A' + pos ;
}
signed main() {
  ios :: sync_with_stdio(false) ;
  int n ;
  cin >> n ;
  string s ;
  cin >> s ;
  int len = s.length() ;
  for(int i = 0 ; i < len ; i ++)
    cout << solve(s[i] , n) ;
  return 0 ;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  bool ans=false;
  for(int i=0;i<S.length();i++){
    if(S==T){
      ans=true;
      break;
    }
    else{
      S=S[S.length()-1]+S.substr(0, S.length()-1);
    }
  }
  if(ans)cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int n, a, b;
	ll s = 0, sb = 0;
	cin >> n;
	vector<int> v(n);
	rep(i, 0, n)cin >> a >> b, v[i] = a + b, sb += (ll)b;
	sort(all(v));
	for (int i = v.size() - 1; i >= 0; i -= 2)s += (ll)v[i];
	printf("%lld\n", s - sb);
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner; 
public class Main {
  public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
    int x = 1;
      for(int a=1;;a++){
          x = sc.nextInt();
          if(x==0){
              break;
          }
          System.out.println("Case "+a+": "+x);
      }
  }
}


Measured memory_bytes: 42620
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

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;
}

int powM(int x, int n){
  if(n == 0){
    return 1;
  }
  if(n % 2 == 0){
    return powM(mod(x * x), n / 2);
  }
  return mod(powM(x, n-1) * x);
}
void add_edge(vector< vector<edge> >& G, int u, int v, int c)
{
  G[u].push_back((edge){ v, c });
}

void init_graph(vector< vector<edge> >& G, int len)
{
  rep(i, 1, len) {
    rep(k, 0, 3) {
      add_edge(G, i, i+1, k*powM(3,i-1));
    }
  }
}

void divide(vector<int>& num, int L)
{
  while (L > 0) {
    num.push_back(L % 3);
    L /= 3;
  }
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int L; cin >> L;
  vector<int> num;
  divide(num, L);

  vector< vector<edge> > G(21, vector<edge>());
  init_graph(G, SIZE(num));


  int tmp = 0;
  rep(i, 0, SIZE(num)) {
    int n = num[i];
    rep(k, 0, n) {
      add_edge(G, i+1, 20, tmp);
      tmp += powM(3,i);
    }
  }

  int M = 0;
  rep(i, 1, 21) {
    M += SIZE(G[i]);
  }


  cout << 20 << " " << M << endl;
  rep(i, 1, 21) {
    rep(j, 0, SIZE(G[i])) {
      edge e = G[i][j];
      cout << i << " " << e.to << " " << e.cost << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
    ll n,m,i,j=0,cc=0;
    cin>>n>>m;
    ll ara[n];
    for(i=0;i<n;i++)cin>>ara[i],cc+=ara[i];
    double x=cc*1.0/(4.0*m);
    for(i=0;i<n;i++){
        if(x<=ara[i]*1.0)j++;
    }
    if(j>=m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 8348
// dp典型
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	S := make([]int, N+1)
	T := make([]bool, N+1)
	MOD := int(10e8) + 7
	if M > 0 {
		// panic("は？？？？？？なにこれ こんなことして楽しいの？？")
		for i := 0; i < M; i++ {
			var V int
			fmt.Scan(&V)
			T[V] = true // 直感と反してわかりにくいがtrueが踏んじゃ駄目なつもり
		}
	}
	// 初期化
	if N >= 1 {
		S[0] = 1
		if !T[1] {
			S[1] = 1
		}
	}
	if N >= 2 {
		if !T[2] {
			S[2] = S[1] + 1
		}
	}

	// 探索
	for i := 3; i < N+1; i++ {
		if T[i] {
			S[i] = 0
		} else {
			S[i] = S[i-1] + S[i-2]
			S[i] %= MOD
		}
	}
	fmt.Println(S[len(S)-1])
}


Measured memory_bytes: 5504
from fractions import gcd
a,b,c,d=map(int,input().split())
e=c*d//gcd(c,d)#最小公倍数
sm=(b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//e-(a-1)//e)
print(int(b-a+1-sm))

Measured memory_bytes: 5176
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long

#define VI vector<int> 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数定義や変数宣言
int n,q;

bool bs(int* S, int key){

int right=n;
int left=0;

while(left<right){

	int middle=(right+left)/2;

	if( S[middle]==key){return true;}
	else if(S[middle]>key){ right=middle; }
	else { left=middle+1; }

}

return false;

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int N;
cin>>N;
int A[N],B[N],C[N];
REP(i,N){cin>>A[i];}
REP(i,N){cin>>B[i];}
REP(i,N){cin>>C[i];}

sort(A,A+N);
sort(B,B+N);
sort(C,C+N);

int ans=0,itr_a,itr_c;

REP(i,N)
{
	( A[0]<B[i]) ? itr_a=  (lower_bound(A,A+N,B[i])-1 ) - A +1 : itr_a=0;

	( B[i]< C[N-1] ) ? itr_c= &(C[N-1])-upper_bound(C,C+N,B[i]) +1 : itr_c=0;

	ans+=itr_a*itr_c;
}
cout<<ans<<endl;
}

Measured memory_bytes: 5968
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(a+b<c+d){
    cout<<"Right"<<endl;
  }
  else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 3600
import sys
readline=sys.stdin.readline
def main():
  N,M=map(int,readline().split())
  mlst = [0] * M
  for i in range(1,M+1):
    _, *tmp = map(int,readline().split())
    mlst[i-1] = sum(1<<(i-1) for i in tmp)

  def popcnt(n):
      # 求1的个数
      c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
      c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
      c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
      c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
      c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
      return c


  mod = list(map(int, readline().split()))
  ab = list(zip(mlst, mod))
  res = 0
  for i in range(1<<N):
    for a,b in ab:
      tmp = a & i
      if popcnt(tmp) & 1 != b:
        break
    else:
      res += 1
  print(res)
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,suma,sumb;
  suma=sumb=0;
  cin>>N;;
  vector<int> arr(N);
  for(int i=0;i<N;i++){
    cin>>arr.at(i);
  }
  sort(arr.begin(),arr.end());
  reverse(arr.begin(),arr.end());
  for(int i=0;i<N;i++){
    if(i%2) sumb+=arr.at(i);
    else suma+=arr.at(i);
  }
  cout<<suma-sumb<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    int res = 1;

    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);

        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool isprime(int x)
{
      if(x<2)
        return false;
    for(int i=2;i*i<=x;i++)
     {
        if (x%i==0)
            return false;
    }
    return true;
}
vector<int>primeFactors(int n)
{
    vector<int>v;
    while (n % 2 == 0)
    {
        v.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.pb(n);
    return v;
}

void solve()
{
int n,k;
cin>>n>>k;
int a[n];
map<int,int>m;
bool vis[n+1]={false};
for(int i=0;i<n;i++)
{
    cin>>a[i];
    m[i+1]=a[i];
}
int ans=1;
vis[1]=true;
vector<int>v;
v.pb(1);
for(int i=0;i<k;i++)
{
    ans=m[ans];
    if(vis[ans]==true)
    {
        break;
    }
    vis[ans]=true;
    v.pb(ans);
}
k-=(v.size());
int x,y;
for(int i=0;i<v.size();i++)
{
    if(v[i]==ans)
    {
        x=v.size()-i;
        y=i;
        break;
    }
}
k=k%x;
//cout<<k<<" "<<x<<" "<<y<<endl;
for(int i=0;i<k;i++)
{
    y++;
}
ans=v[y];
cout<<ans<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}


Measured memory_bytes: 19540
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int D, N;
	cin >> D >> N;
	if (N == 100)N++;
	while (D--) {
		N *= 100;
	}
	cout << N << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void main(String[]args){
		String a=scan.next();
		boolean bool=false;
		if(a.charAt(0)!='k'||a.charAt(a.length()-1)!='e') {
			if(a.indexOf("keyence")!=-1) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
			return;
		}
		
		for(int i=0;i<a.length();i++) {//一つ目の最初の場所
			for(int j=i+1;j<=a.length();j++) {//一つ目の最後
				String str1=a.substring(i,j);
				for(int k=j;k<a.length();k++) {
					for(int l=k+1;l<=a.length();l++)	{
						String str2=a.substring(k,l);
						String str=str1+str2;
						if(str.equals("keyence"))bool=true;
					}
				}
			}
		}
		System.out.println(bool?"YES":"NO");
	}
}


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

using namespace std;

int z[5050];

void zFunc(string s)
{
    int n = s.size() - 1;
    for(int i = 1 , l = 0 , r = 0; i <= n; i ++)
    {
        if(i <= r)
        {
            z[i] = min(z[i - l] , r - i + 1);
        }
        while(s[z[i]] == s[i + z[i]] && i + z[i] <= n)
            z[i] ++;
        if(i + z[i] - 1 > r)
        {
            l = i;
            r = i + z[i] - 1;
        }
    }
}

int main() {
    int ans = 0 , n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0 ; j <= 5050; j ++) z[j] = 0;
        string p = s.substr(i , n - i);
        zFunc(p);
        for(int j = 0; j <= n; j ++) {
            z[j] = min(z[j] , j);
            ans = max(ans , z[j]);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
use std::collections::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, k, l) = i.read3::<usize, usize, usize>();
    let mut pqs = Vec::new();
    for _ in 0..k {
        let (p, q) = i.read2::<usize, usize>();
        pqs.push((p - 1, q - 1));
    }
    let mut rss = Vec::new();
    for _ in 0..l {
        let (r, s) = i.read2::<usize, usize>();
        rss.push((r - 1, s - 1));
    }

    let r = solve(n, &pqs, &rss);
    for i in 0..r.len() {
        if i != 0 {
            write!(o, " ").unwrap();
        }
        write!(o, "{}", r[i]).unwrap();
    }
    writeln!(o, "").unwrap();
}
fn solve(n: usize, pqs: &[(usize, usize)], rss: &[(usize, usize)]) -> Vec<usize> {
    let g1 = grouping(n, pqs);
    let g2 = grouping(n, rss);

    let mut gs = HashMap::new();
    for i in 0..n {
        *gs.entry((g1[i], g2[i])).or_insert(0) += 1;
    }
    let mut rs = vec![0; n];
    for i in 0..n {
        rs[i] = gs[&(g1[i], g2[i])];
    }
    rs
}

// 各駅のグループIDを返す
fn grouping(n: usize, edges: &[(usize, usize)]) -> Vec<usize> {
    let mut r = vec![0; n];
    let mut t = vec![Vec::new(); n];
    let mut v = vec![false; n];
    for &e in edges {
        t[e.0].push(e.1);
        t[e.1].push(e.0);
    }

    let mut q = Vec::new();
    let mut gid = 0;
    for i in 0..n {
        if v[i] {
            continue;
        }
        v[i] = true;
        q.clear();
        q.push(i);
        let mut qi = 0;
        while qi < q.len() {
            for &j in &t[q[qi]] {
                if v[j] {
                    continue;
                }
                v[j] = true;
                q.push(j);
            }
            qi += 1;
        }
        for qi in 0..q.len() {
            r[q[qi]] = gid;
        }
        gid += 1;
    }
    r
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

int main()
{
	int a, b, c, d, l, r;
	cin >> a >> b >> c >> d;
	l = a + b;
	r = c + d;
	if (l > r)
	{
		cout << "Left";
	}
	else if (l == r)
	{
		cout << "Balanced";
	}
	else
	{
		cout << "Right";
	}
}


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

using namespace std;

int n;
int a[300005];
int jival,ouval;

bool isok(int mid) {
	int vv = a[1];
	for(int i=3;i<=n;i+=2) {
		if(vv>=mid) {
			vv = max(vv+a[i]-a[i-1],a[i]);
		} else vv = vv + a[i] - a[i-1];
	}
	return vv>=mid;
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if(i&1) jival += a[i];
		else ouval += a[i];
	}
	if(!(n&1)) {
		printf("%d %d",max(jival,ouval),min(jival,ouval));
		return 0;
	}
	int l = 0; int r = jival , mid , ans = 0;
	while(l<=r) {
		mid = (l+r)>>1;
		if(isok(mid)) {
			ans = mid , l = mid + 1;
		} else r = mid - 1;
	}
	printf("%d %d",ouval+ans,jival-ans);
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main(void){

  int K;
  string S;
  string S2;

  cin >> K;
  cin >> S;

  if((int)S.length()<=K) cout << S << endl;
  else{
    for(int i=0; i<K; i++){
      S2+=S[i];
    }
    cout << S2 << "..." << endl;
  }

  return 0;
}


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

int main() {
    int c[3][3];
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            std::cin >> c[i][j];
        }
    }

    int a[3] = {0};
    int b[3] = {0};

    for (int i = 0; i <= 100; ++i) {
        a[0] = i;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];

        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];

        bool ok = true;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (c[j][k] != (a[j] + b[k])) {
                    ok = false;
                    break;
                }
            }
        }

        if (ok) {
            std::cout << "Yes" << std::endl;
            return 0;
        } 
    }

    std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
N, M = map(int, input().split())
L = [tuple(map(int, input().split())) for i in range(M)]
L_sort = sorted(L, key=lambda x:x[1])
ans = 0
rb = 0
for l in L_sort:
    if l[0] > rb:
        rb = l[1] - 1
        ans += 1
print(ans)
    


Measured memory_bytes: 19016
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll n, i, j, k, be = 0;
  scanf("%lld", &n);
  ll a[1<<n][2];
  for(i = 0; i < 1<<n; ++i) scanf("%lld", &a[i][0]), a[i][1] = 0;
  for(i = 0; i < n; ++i) for(j = 0; j < 1<<n; ++j) if(j>>i & 1) {
    if(a[j^(1<<i)][0] > a[j][0]) {
      a[j][1] = a[j][0], a[j][0] = a[j^(1<<i)][0];
    } else if(a[j^(1<<i)][0] > a[j][1]) {
      a[j][1] = a[j^(1<<i)][0];
    }
  }
  for(i = 1; i < 1<<n; ++i) printf("%lld\n", be > a[i][0] + a[i][1] ? be : a[i][0] + a[i][1]), be = be > a[i][0] + a[i][1] ? be : a[i][0] + a[i][1];
  return 0;
}

Measured memory_bytes: 7040
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main() {
    string s1, s2, s3, s4;
    s1 = "dream";
    s2 = "dreamer";
    s3 = "erase";
    s4 = "eraser";

    reverse(ALL(s1)); reverse(ALL(s2)); reverse(ALL(s3)); reverse(ALL(s4));

    string s; cin >> s;
    reverse(ALL(s));

    bool fg = true;
    int ind = 0;

    while (fg) {
        if (ind == s.size()) {
            break;
        }
        fg = false;
        if (s1 == s.substr(ind, 5)) {
            ind += 5;
            fg = true;
            continue;
        }
        else if (s2 == s.substr(ind, 7)) {
            ind += 7;
            fg = true;
            continue;
        }
        else if (s3 == s.substr(ind, 5)) {
            ind += 5;
            fg = true;
            continue;
        }else if (s4 == s.substr(ind, 6)) {
            ind += 6;
            fg = true;
            continue;
        }
    }

    if (ind == s.size()) {
        pYES;
    }
    else {
        pNO;
    }

}

Measured memory_bytes: 3712
from math import cos,sin, pi
n = int(input())
def  koch(n, l, r):
    if n == 0:
        return
    s = ((2*l[0] + r[0])/3, (2*l[1] + r[1])/3)
    t = ((l[0] + 2*r[0])/3, (l[1] + 2*r[1])/3)
    u = ((t[0] - s[0]) * cos(pi/3) - (t[1] - s[1]) * sin(pi/3) + s[0], 
         (t[0] - s[0]) * sin(pi/3) + (t[1] - s[1]) * cos(pi/3) + s[1])
    koch(n - 1, l, s)
    print(s[0], s[1])
    koch(n - 1, s, u)
    print(u[0], u[1])
    koch(n - 1, u, t)
    print(t[0], t[1])
    koch(n - 1, t, r)

print(0, 0)
koch(n, (0, 0), (100, 0))
print(100, 0)

Measured memory_bytes: 8036
import java.util.Arrays;
import java.util.Scanner;

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

        int[] a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        System.out.println(a[0] + a[1]);
    }
}


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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  // cerr << s << " " << k << endl;

  rep(i, s.size()) {
    if (s[i] == 'a') continue;
    int cost = 'z' + 1 - s[i];
    if (cost <= k) {
      s[i] = 'a';
      k -= cost;
    }
    // cerr << s << " " << k << endl;
  }
  if (k > 0) s[s.size() - 1] = (s[s.size() - 1] - 'a' + k) % 26 + 'a';

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3668
program abc129e;
const
  M = 1000000007;
var
  L: string;
  I, T, Result: Int64;
begin
  Read(L);

  Result := 1;
  T := 1;
  for I := Length(L) downto 1 do
  begin
    if L[i] = '1' then
    begin
      Result := Result * 2 + t;
      Result := Result mod M;
    end;
    T := T * 3;
    T := T mod M;
  end;
  WriteLn(Result);
end.


Measured memory_bytes: 1384
#include <iostream>
using namespace	std;
int main(){

  int w,h,t0,p,a[50][50]={},r=0;
  cin>>w>>h>>t0>>p;
  for(int i=0,x,y,t;i<p&&cin>>x>>y>>t;i++) if(t<=t0) a[y][x]++;
  for(int i=0,tmp;i<h;i++) for(int j=0;j<w&&cin>>tmp;j++) if(tmp) r+=a[i][j];
  cout<<r<<endl;
  return 0;

}

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

int main() {
	int count = 0;
	int c[3][3];
	int a[3];
	int b[3];
	
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> c[i][j];
		}

	}
	for ( a[0] = 0; a[0] <= c[0][0]; a[0]++)
	{
		 b[0] = c[0][0] - a[0];
		 b[1] = c[0][1] - a[0];
		 b[2] = c[0][2] - a[0];
		 a[1] = c[1][0] - b[0];
		 a[2] = c[2][0] - b[0];
		 count = 0;

		 for (int i = 0; i < 3; i++)
		 {
			 for (int j = 0; j < 3; j++)
			 {
				 if (c[i][j] == (a[i] + b[j]))
				 {
					 count++;
				 }
			 }
		 }
		 if (count == 9)
		 {
			 cout << "Yes" << endl;
			 break;
		 }
		 
	}
	if (count !=9)
	{
		cout << "No" << endl;
	}

	

}

Measured memory_bytes: 256
N = int(input())
A = list()
B = list()
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
A.sort()
B.sort()

if(N%2==1):
  x = A[(N-1)//2]
  y = B[(N-1)//2]
  print(y-x+1)
else:
  x = A[(N//2)-1] + A[N//2]
  y = B[(N//2)-1] + B[N//2]
  print(y-x+1)

Measured memory_bytes: 25320
#include<stdio.h>
#define M 1000000
#define N 101
int n,A[N][N];

void D(){
  int d[N],c[N],m,u,i,v;

  for(i=0;i<n;i++){
    d[i] = M;
    c[i] = 0;
  }

  d[0] = 0;
  c[0] = 1;

  while(1){
    m = M;
    u = -1;

    for(i=0;i<n;i++)
      if(c[i]!=2 && d[i]<m){
        m = d[i];
        u = i;
      }

    if(u==-1) break;
    c[u] = 2;

    for(v=0;v<n;v++)
      if(c[v]!=2 && A[u][v]!=M)
        if(d[u] + A[u][v] < d[v]){
          d[v] = d[u] + A[u][v];
          c[v] = 1;
        }
  }

  for(i=0;i<n;i++)
    printf("%d %d\n",i,(d[i] == M ? -1 : d[i]));
}

int main(){
  int k,u,c,v,i,j;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      A[i][j] = M;

  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d%d",&v,&c);
      A[u][v] = c;
    }
  }

  D();

  return 0;
}


Measured memory_bytes: 2004
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
      ll n,i;
      cin>>n;
      ll a[n],s=0;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
      }
      for(i=1;i<n;i++)
      {
          if(a[i]<a[i-1])
          {
              s+=a[i-1]-a[i];
              a[i]=a[i-1];
          }
      }
      cout<<s<<"\n";
    return 0;
}

Measured memory_bytes: 5196
import sys
 
sys.setrecursionlimit(10 ** 8)

n = int(input())

edge = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

odd = []
even = []

ans = [-1] * n
def dfs(x, last = -1, d = 0):
    if d%2 == 0: even.append(x)
    else: odd.append(x)
    for nxt in edge[x]:
        if nxt == last:
            continue
        dfs(nxt, x, d + 1)

dfs(0)

nums = [[],[],[]]
for i in range(1,n+1):
    nums[i%3].append(i)

zerocnt = len(nums[0])
 
if len(even) <= zerocnt:
    for even_node in even:
        ans[even_node] = nums[0].pop()
    rest = nums[0] + nums[1] + nums[2]
    for odd_node in odd:
        ans[odd_node] = rest.pop()
 
elif len(odd) <= zerocnt:
    for odd_node in odd:
        ans[odd_node] = nums[0].pop()
    rest = nums[0] + nums[1] + nums[2]
    for even_node in even:
        ans[even_node] = rest.pop()

else:
    for num in nums[1]:
        ans[odd.pop()] = num
    for num in nums[2]:
        ans[even.pop()] = num
    rest = nums[0] + nums[1] + nums[2]
    for num in rest:
        if len(odd):
            ans[odd.pop()] = num
        elif len(even):
            ans[even.pop()] = num

print(*ans)




Measured memory_bytes: 186372