akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000000LL;

int n;
vector<ll> a;

ll f(ll b)
{
	ll res = 0;
	for (int i = 0; i < n; i++)
		res += abs(a[i] - b);
	return res;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	ll result = INF;
	for (int i = max(0, n / 2 - 5); i < min(n, n / 2 + 5); i++)
		result = min(result, f(a[i]));
	cout << result << endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

// SegmentTree
template<class T> struct Min {
  using Type = T;
  T nil;
  Min(){}
  Min(T nil):nil(nil){}
  void update(T& a, T b) { a = b; }
  T operator()(T a, T b) { return a < b ? a : b; }
};
template<class T> struct Max {
  using Type = T;
  T nil;
  Max(){}
  Max(T nil):nil(nil){}
  void update(T& a, T b) { a = b; }
  T operator()(T a, T b) { return a > b ? a : b; }
};
template<class T> struct Sum {
  using Type = T;
  T nil;
  Sum(){}
  Sum(T nil):nil(nil){}
  void update(T& a, T b) { a += b; }
  T operator()(T a, T b) { return a + b; }
};

template<class Monoid> struct SegmentTree {
  using T = typename Monoid::Type;
  vector<T> data;
  Monoid func;
  int sz;
  SegmentTree(int n, Monoid f):func(f) {
    sz = 1; while(sz < n) sz <<= 1;
    data.resize(2*sz+1, func.nil);
  }
  void update(int k, T x) {
    k += sz-1;
    func.update(data[k], x);
    while(k > 0) {
      k = (k-1)/2;
      data[k] = func(data[2*k+1], data[2*k+2]);
    }
  }
  T query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return func.nil;
    if(a <= l && r <= b) return data[k];
    return func(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r));
  }
  T query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};


signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin >> n >> q;
  SegmentTree<Sum<int>> seg(n, Sum<int>(0));
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0) seg.update(x-1, y);
    else cout << seg.query(x-1, y) << endl;
  }

  return 0;
}

Measured memory_bytes: 4800
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e6+10;
const ll m = 1e9+7;

ll fact[N] , ifact[N];
ll pow(ll a , ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b&1)
			ans= (ans*a)%m;
		b/=2;
		a = (a*a)%m;
	}
	return ans;
}
ll modinv(ll k)
{
	return pow(k , m-2);
}

void precompute()
{
	fact[0] = fact[1] = 1;
	rep(i,2,N)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %=m;
	}
	ifact[N-1] = modinv(fact[N-1]);
	for(ll i = N-2 ; i>=0 ; --i)
	{
		ifact[i] = ifact[i+1]*(i+1);
		ifact[i]%=m;
	}
}

ll ncr(ll n , ll r)
{
	if(r > n)
		return 0;
	return ((fact[n]*ifact[r])%m * ifact[n-r])%m;
}
ll h ,w;
vector< pll > v;

ll ways(pll a , pll b)
{
	ll n = abs(a.ff - b.ff);
	ll m = abs(a.ss - b.ss);
	return ncr(n+m , n);
}
ll dp[3005];

signed main()
{

	fast;
////////////////////////////////////////////////////////////////////////////////////////////
	precompute();

	ll n;
	cin >> h >> w >>n;

	while(n--)
	{
		ll i,j;
		cin >> i >> j;
		v.pb({i,j});
	}
	v.pb({h,w});
	v.pb({1,1});
	sort(all(v));

	n = v.size();

	for(ll i = 1 ; i< n ; ++i)
	{
		dp[i] = ways(v[i] , {1,1});
		for(ll j = 1 ; j<i ; ++j)
		{
			if(v[j].ff <= v[i].ff and v[j].ss <= v[i].ss)
			{
				dp[i] = (dp[i] - dp[j]*ways(v[i],v[j])+ m)%m;
			}
		}
	}

	dp[n-1]+=m;
	dp[n-1]%=m;

	cout<<dp[n-1]<<endl;

	return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int n; cin >> n;
    string S; cin >> S;

    int cur, res;
    cur = res = 0;

    for(int i = 0; i < n; i++){
        char c = S[i];
        if(c == 'I'){
            cur++;
        }
        else {
            cur--;
        }
        res = max(res, cur);
    }

    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    try {
      Scanner scan = new Scanner(System.in);
      int n, m, x, i=0, p, a=0, b=0;
      n = Integer.parseInt(scan.next());
      m = Integer.parseInt(scan.next());
      x = Integer.parseInt(scan.next());

      while(i<m){
        p = Integer.parseInt(scan.next());
        if(p<x){
          a = ++a;
        }else if(p>x){
          b = ++b;
        }
        i = ++i;
      }

      System.out.println(Math.min(a, b));
    }
    catch (Exception e) {
      
    }
  }
}

Measured memory_bytes: 23380
n = int(input())
a = list(map(int,input().split()))
c = [0] * 3
for i in range(n):
    if a[i] % 4 == 0:
        c[2] += 1
    elif a[i] % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1

if c[1] == 0:
    if c[0] <= c[2]+1:
        print('Yes')
    else:
        print('No')
else:
    if c[0] <= c[2]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 19988
#include <stdio.h>
#define H 250

int main(){

  int n,i,a[H];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  for(i=1;i<=n;i++) {
    printf("node %d: ",i);
    printf("key = %d, ",a[i]);
    if(i/2 != 0) {
      printf("parent key = %d, ",a[i/2]);
    }
    if((i*2)<=n) {
      printf("left key = %d, ",a[i*2]);
    }
    if((i*2+1)<=n){
      printf("right key = %d, ",a[i*2+1]);
    }
    printf("\n");
  }
  

  return 0;
}

Measured memory_bytes: 600
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n

ans = 0
(1..n).each do |i|
  num = n / i
  # 等差数列の公式 初項a, 公差d, 項数nとするとき、
  # n * (2 * a + (n - 1) * d) / 2
  ans += num * (2 * i + (num - 1) * i) / 2
end
puts ans

# 解説
# 例えば、n=6のとき
# K * f(K) = 1 * 1
# K * f(K) = 2 * 2
# K * f(K) = 3 * 2
# K * f(K) = 4 * 3
# K * f(K) = 5 * 2
# K * f(K) = 6 * 4
# となるが、これは掛け算を読み替えれば1が1個(+1)、2が2個(2+2)、3が2個(3+3)、4が3個(4+4+4)、、、となり
# これらを足し合わせた結果は57となる。
# 各kの約数について考えたとき
# 1の約数は1が1個あるのみ
# 2は1が1個、2が1個あり
# 3は1,3が1個ずつ
# 4は1,2,4が1個ずつ
# 5は1,5が1個ずつ
# 6は1,2,3,6が1個ずつあるのみである
# 上で示した約数のように、1はn以下のどのkにも含まれる約数であり
# 一方で1にkを掛けたとき、K * f(K)の項の1つであるとも言える
# ※例えば、K=6のとき K * f(K) = 6 * f(6) = 6 * 4 = 6 * 1 + 6 * 1 + 6 * 1 + 6 * 1
# 1と同様に2はn以下の2の倍数すべてに含まれる約数であり
# 3も同様にn以下の3の倍数すべてに含まれる約数である
# (上の例でいえば、4..6も同様ではあるがn=6以下という条件から倍数は自分自身しか含まない)
# すなわち、1..nに含まれる値kについて、
# kの倍数を列挙して足し合わせれば、2k,3k,4k,...の各約数についてそのうちの1個を足し合わせているのと等価になる
# ※例えば、3は3,6の約数であるが、3の倍数は3,6である
# 　f(6)=4のとおり、6の約数は全部で4個で、その内訳は1,2,3,6
# 　n=6でk=3のとき、2k=6を足し合わせることで6 * f(6)のうちの1項を足し合わせたのと等しくなる
# よって、1からnまで、順にkの倍数を足し合わせていけば答えが求められる
# ここで、n以下のkの倍数は等差数列で表すことができる
# ※1,2,3,4,5,6は初項1、公差1、項数6の等差数列
# 　2,4,6は初項2、公差2、項数3の等差数列
# そのため、等差数列の和の公式を用いることで、各kについてkの倍数の和が計算できる
# これはO(1)なので、全体にかかる処理時間はO(N)になる
#
# 付録 K * f(K)と等差数列の一致 
# K * f(K) = 1 * 1
# K * f(K) = 2 * 2
# K * f(K) = 3 * 2
# K * f(K) = 4 * 3
# K * f(K) = 5 * 2
# K * f(K) = 6 * 4
# 1の等差数列 = 1,2,3,4,5,6
# 2の等差数列 = 2,4,6
# 3の等差数列 = 3,6
# 4の等差数列 = 4
# 5の等差数列 = 5
# 6の等差数列 = 6


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

int main() {
  string s;
  cin >> s;
  string a, b, c, d;
  a = s.at(0);
  b = s.at(1);
  c = s.at(2);
  d = s.at(3);
  if(a == b && c == d && a != c)
    cout << "Yes" << endl;
  else if(a == c && d == b && a != b)
    cout << "Yes" << endl;
  else if(a == d && c == b && a != b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
from copy import deepcopy
import numpy as np
H, W, K = map(int, input().split())
C = np.array([[1 if a == '#' else 0 for a in input()] for _ in range(H)])

HA = 2 ** H
WA = 2 ** W



ans = 0
for i in range(HA):
    R = np.copy(C)
    for j in range(H):
        if (i >> j) & 1:
            R[j] = 0
    for k in range(WA):
        RR = np.copy(R)
        for l in range(W):
            if (k>>l) & 1:
                RR[:,l]=0
        if np.sum(RR) == K:
            ans += 1
print(ans)                    

Measured memory_bytes: 27276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.solve();
    }
    private void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        int N = scan.scanInt();
        List<List<Path>> graph = new ArrayList(N);
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < N - 1; i++) {
            int a = scan.scanInt()-1;
            int b = scan.scanInt()-1;
            int c = scan.scanInt();
            graph.get(a).add(new Path(b, c));
            graph.get(b).add(new Path(a, c));
        }
        int Q = scan.scanInt();
        int K = scan.scanInt()-1;
        Queue<Integer> queue = new ArrayDeque<>();
        long[] distances = new long[N];
        boolean[] visited = new boolean[N];
        queue.add(K);
        while(!queue.isEmpty()) {
            int current = queue.poll();
            visited[current] = true;
            for (Path p : graph.get(current)) {
                if (visited[p.to]) {
                    continue;
                }
                distances[p.to] = distances[current] + p.cost;
                queue.add(p.to);
            }
        }
        for (int i = 0; i < Q; i++) {
            int from = scan.scanInt() - 1;
            int to = scan.scanInt() - 1;
            System.out.println(distances[from] + distances[to]);
        }
    }

    class Path {
        int to;
        int cost;
        Path(int to, int cost) {
            this.to = to;
            this.cost = cost;
        }
    }
    class FastScan {
        BufferedReader br;
        StringTokenizer st;
        FastScan(InputStream is) {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String next() throws IOException {
            while (this.st == null || !this.st.hasMoreTokens()) {
                this.st = new StringTokenizer(br.readLine().trim());
            }
            return st.nextToken();
        }
        long scanLong() throws IOException {
            return Long.parseLong(this.next());
        }
        int scanInt() throws IOException {
            return Integer.parseInt(this.next());
        }
        double scanDouble() throws IOException {
            return Double.parseDouble(this.next());
        }
        char scanCharacter() throws IOException {
            return this.next().charAt(0);
        }
        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 81184
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<cstring>
typedef long long ll;
const ll MAXN=110+10;
const int INF=0x7fffffff; 

using namespace std;

int a[MAXN];

int main(){
	int n;
	cin>>n;
	a[1]=0,a[2]=1;
	int mx=0,num=n;
	if(n==1)
		cout<<1<<endl;
	else if(n==2)
		cout<<2<<endl;
	else {
		int num=2;
		for(int i=3;i<=n;i++){
			if(i%2==0){
				a[i]=a[i/2]+1;
			}
			if(a[i]>a[num]){
				num=i;
			}
		}
		cout<<num<<endl;
	}
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int remove_bit(int x, int j) {
  int low = x & ((1 << j) - 1);
  return ((x >> (j + 1)) << j) + low;
}
int insert_bit(int x, int j, int v) {
  int low = x & ((1 << j) - 1);
  return ((x >> j) << (j + 1)) + (v << j) + low;
}
template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (
        T&& t
      ) noexcept
      : T(forward<T>(t))
      {
      }
    template<typename... Args>
    constexpr decltype(auto)
    operator()(
        Args&&... args
      ) const
      {
        return T::operator()(*this, forward<Args>(args)...);
      }
};
template<typename T>
static inline constexpr decltype(auto)
  make_fixed_point (T&& t) noexcept {
    return fixed_point<T>{forward<T>(t)};
  }
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  if (__builtin_popcount(a ^ b) % 2 == 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  auto p = make_fixed_point ([&](auto solve, int n, int a, int b) -> vector<int> {
    if (n == 1) return {a, b};
    for (int j = 0; j < n; j++) if (((a ^ b) >> j) & 1) {
      int aa = remove_bit(a, j);
      int bb = remove_bit(b, j);
      for (int u = 0; u < (1 << n); u++) {
        int uu = remove_bit(u, j);
        if (__builtin_popcount(aa ^ uu) % 2 == 0) continue;
        if (__builtin_popcount(bb ^ uu) % 2 == 0) continue;
        auto p = solve(n - 1, aa, uu);
        auto q = solve(n - 1, uu, bb);
        for (auto& x : p) x = insert_bit(x, j, (a >> j) & 1);
        for (auto& x : q) x = insert_bit(x, j, (b >> j) & 1);
        p.insert(p.end(), q.begin(), q.end());
        return p;
      }
    }
    assert(false);
    return {};
  })(n, a, b);
  set<int> val(p.begin(), p.end());
  for (int i = 0; i < (1 << n); i++) {
    assert(0 <= p[i] && p[i] < (1 << n));
  }
  for (int i = 0; i < (1 << n) - 1; i++) {
    assert(__builtin_popcount(p[i] ^ p[i + 1]) == 1);
  }
  for (int i = 0; i < (1 << n); i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << p[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7792
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	X := sc.nextInt()

	happy := 0
	happy += (X / 500) * 1000
	X = X % 500

	happy += (X / 5) * 5

	fmt.Println(happy)

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
from fractions import gcd


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


A, B = tuple(map(int, input().split(" ")))

print(len(set(prime_factorize(gcd(A, B)))) + 1)


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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight=long long;

struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;
//??????????????????
void dijkstra(const Graph &g,int s,vector<Weight>&dist,vector<int>&prev){
    const int V=g.size();
    priority_queue<Edge>q;
    dist[s]=0;
    for(q.emplace(-2,s,0);!q.empty();){
        Edge e=q.top();q.pop();
        if(prev[e.dst]!=-1)continue;
        prev[e.dst]=e.src;
        //if(prev[t]!=-1)return;
        for(auto ge:g[e.dst]){
            if(dist[ge.dst] > e.weight+ge.weight){
                dist[ge.dst]=e.weight+ge.weight;
                q.emplace(ge.src,ge.dst,e.weight+ge.weight);
            }
        }
    }
}

int main(){
    cin.sync_with_stdio(false);
    int V,E,r;
    cin>>V>>E>>r;
    Graph g(V);
    for(int i=0;i<E;++i){
        int s,t,d;
        cin>>s>>t>>d;
        g[s].emplace_back(s,t,d);
    }
    vector<Weight>dist(V,INF64);//???????????§????????¢?????\???
    vector<int>prev(V,-1);//????????????????????\???
    dijkstra(g,r,dist,prev);
    for(int i=0;i<V;++i){
        if (dist[i] == INF64)cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
}
//be checked by AOJ(GRL-1-A).

Measured memory_bytes: 19788
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
#define INF 100000000
template<class T> inline bool chmax(T& a, T b)
{ if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b)
{ if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(){
  int i,j,k,n,d,a;
  cin >> a;
  cout << 3*a*a<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<int> G[SIZE];
ll ans[SIZE];

void dfs(int now, int back = -1) {
  for (int to : G[now]) {
    if (to == back) continue;
    ans[to] += ans[now];
    dfs(to, now);
  }
}

int main(){
  int N, Q;

  scanf("%d%d",&N ,&Q);

  for (int i=0; i<N-1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  for (int i=0; i<Q; i++) {
    int p, x;
    scanf("%d%d", &p, &x);
    ans[p-1] += x;
  }

  dfs(0);

  for (int i=0; i<N; i++) {
    printf("%lld%c", ans[i], " \n"[i == N-1]);
  }

  return 0;
}


Measured memory_bytes: 24320
a, b, c, k = (int(i) for i in input().split())  
tmp_cnt = k
tmp_sum = 0
if a <= k:
  tmp_sum = a
else:
  tmp_sum += k
tmp_cnt -= a
tmp_cnt -= b
if tmp_cnt>0:
  tmp_sum += tmp_cnt*(-1)
print(tmp_sum)

Measured memory_bytes: 9164
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = 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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
// vector<vector<ll>> vec(100,vector<ll>(3,0));
int main(){
  ll n;
  cin >> n;
  ll h[n];
  rep(i,n){
    cin >> h[i];
  }
  bool can = true;
  ll tmph = -1;
  rep(i,n){
    if(tmph > h[i]){
      can = false;
      break;
    }else{
      if(tmph != h[i]){
        tmph = h[i]-1;
      }else{
        tmph = h[i];
      }
    }
  }
  if(can){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 1024
import java.util.*;


import java.io.*;

class Main {

  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int A = sc.nextInt();
      int B = sc.nextInt();
      int K = sc.nextInt();
      for (int i = 0; i < K; i++) {
        if (i % 2 == 0) {
          if (A % 2 == 1) {
            A --;
          }
          A /= 2;
          B += A;
        } else {
          if (B % 2 == 1) {
            B--;
          }
          B /= 2;
          A += B;
        }
      }
      System.out.printf("%d %d", A, B);
    }
  }
}


Measured memory_bytes: 22996
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

ans = float('inf')
N = int(input())
list_x = list(map(int, input().split()))

for x in range(1, 101):
    temp = 0
    for xi in list_x:
        temp += (x - xi) ** 2
    ans = min(ans, temp)

print(ans)


Measured memory_bytes: 9104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

vector<int> G[SIZE];
int n,k;
int sum[SIZE], sumk[SIZE];
int dp[SIZE];
bool flag_sumk[SIZE];

int dfs1(int now, int back=-1){
  vector<int> vec1;
  vector<int> vec2;
  int sum_vec1 = 0;
  
  for(int i=0;i<G[now].size();i++){
    if(G[now][i] == back) continue;

    int res = dfs1(G[now][i], now);

    vec1.push_back(sumk[G[now][i]] >= 1);
    sum_vec1 += sumk[G[now][i]] >= 1;
    vec2.push_back(res);
    
    sum[now] += sum[G[now][i]];
    sumk[now] += sumk[G[now][i]] >= 1;
  }

  int maxSum = sum_vec1;
  
  for(int i=0;i<vec1.size();i++){
    maxSum = max(maxSum, sum_vec1 - vec1[i] + vec2[i]);
  }

  sum[now]++;

  if(sum[now] >= k && sumk[now] == 0){
    sumk[now] = 1;
    flag_sumk[now] = true;
    //maxSum = max(maxSum, 1);
  }

  dp[now] = maxSum;
  return maxSum;
}

int dfs2(int now, int back = -1, int prev_sumk = -INF){
  int ans = 0;
  int chisum = 0;
  vector<int> vec;
  int chisumk = 0;
  
  bool flag = false;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i] == back) continue;
    chisum += sum[G[now][i]];
    chisumk += sumk[G[now][i]] >= 1;
    vec.push_back(dp[G[now][i]] - (sumk[G[now][i]] >= 1));
    flag |= sumk[G[now][i]] >= 1 && !flag_sumk[G[now][i]];
  }

  vec.push_back(0);
  vec.push_back(0);
  sort(vec.begin(), vec.end(), greater<int>());

  ans = max(ans, vec[0] + chisumk + prev_sumk);

  if(flag)
    ans = max(ans, vec[0] + vec[1] + chisumk + (n-1-chisum >= k));
  
  for(int i=0;i<G[now].size();i++){
    if(G[now][i] == back) continue;
    ans = max(ans, dfs2(G[now][i], now, sumk[now] - !!sumk[G[now][i]] + ((n-1-chisum) >= k) - flag_sumk[now]));
  }

  
  return ans;
}

int main(){
  int u,v;
  
  scanf("%d%d",&n,&k);

  for(int i=0;i<n-1;i++){
    scanf("%d%d",&u,&v);
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  dfs1(0);

  cout << dfs2(0) << endl;
  
  return 0;
}

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

vector<int> r;

void v753(int n) {
    if(to_string(n).size() == 9)
        return;
    int n3=n*10+3, n5=n*10+5, n7=n*10+7;
    r.push_back(n3);
    r.push_back(n5);
    r.push_back(n7);
    v753(n3);
    v753(n5);
    v753(n7);
}

int main() {
    int N,c=0;
    cin >> N;
    v753(0);

    rep(i,r.size()) {
        set<char> s;
        int t = r.at(i);
        string ts=to_string(t);

        rep(i,ts.size())
            s.insert(ts.at(i));

        if(s.size()==3 && t<=N)
            c++;
    }
    cout << c << endl;
}

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

const int N = 1e5 + 5;


int xgcd(int a, int b, int &x, int &y) //Returns GCD of A, B
{
	if(a==0) 
	{
		x=0;
		y=1;
		return b;
	}
	int x1, y1;
	int d = xgcd(b % a, a, x1, y1);
	x = y1 - (b/a)*x1;
	y = x1;
	return d;
}

int modular_inverse(int a, int m)
{
	int x, y;
	int g=xgcd(a, m, x, y);
	if(g!=1)
		return -1;
	else
	{
		x=(x%m + m)%m;
		return x;
	}
}

void shift_solution(int &x, int &y, int a, int b, int cnt)
{
	x+=cnt*b;
	y-=cnt*a;
}

bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g)
{
	g=xgcd(abs(a), abs(b), x0, y0);
	if(c%g!=0)
		return false;
	x0 *= c/g;
	y0 *= c/g;
	if(a<0)
		x0*=-1;
	if(b<0)
		y0*=-1;
	return true;
}

int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) //Returns number of solutions with x∈[minx, maxx], y∈[miny, maxy]
{
	int x, y, g;
	if(!find_any_solution(a, b, c, x, y, g))
		return 0;
	a /= g;  
	b /= g; 

	int sign_a = a>0 ? +1 : -1;
	int sign_b = b>0 ? +1 : -1;

	shift_solution(x, y, a, b, (minx - x) / b);
	if (x < minx) shift_solution(x, y, a, b, sign_b);
	if (x > maxx) return 0;
	int lx1 = x;

	shift_solution(x, y, a, b, (maxx - x) / b);
	if (x > maxx) shift_solution(x, y, a, b, -sign_b);
	int rx1 = x;

	shift_solution(x, y, a, b, - (miny - y) / a);
	if (y < miny) shift_solution(x, y, a, b, -sign_a);
	if (y > maxy) return 0;
	int lx2 = x;

	shift_solution(x, y, a, b, - (maxy - y) / a);
	if (y > maxy) shift_solution(x, y, a, b, sign_a);
	int rx2 = x;

	if (lx2 > rx2) 
		swap (lx2, rx2);
	int lx = max (lx1, lx2);
	int rx = min (rx1, rx2); 

	return (rx - lx) / abs(b) + 1;
}

int32_t main()
{
	IOS;
	int a, b, c, n;
	cin >> a >> b >> c >> n;
	int ans = 0;
	for(int i = 0; i * a <= n; i++)
	{
		int left = n - i * a;
		ans += find_all_solutions(b, c, left, 0, 1e9, 0, 1e9);
	}	
	cout << ans;
	return 0;
}

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

int main()
{
	string s;
	int x=0;
	cin>>s;
	for (int i=0; i<s.size(); i++)
	{
		if (s[i]=='+')
		{
			x++;
		}
		if (s[i]=='-')
		{
			x--;
		}
	}
	cout<<x;
	return 0;
}

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

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

bool palin(string s)
{
    string ss=s;
    reverse(all(ss));
    if(ss==s)return true;
    return false;
}

int main()
{
    string s;cin>>s;
    int n=s.length();
    if(palin(s) && palin(s.substr(0,(n-1)/2)) && palin(s.substr(n+1/2)))
        cout<<"Yes\n";
    else cout<<"No\n";
}


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

int main()
{
    int num;
    cin >> num;
    int box[26]={};
    char str[51];
    for(int i=0;i<num;i++){
        int current[26]={};
        cin >> str;
        for(int j=0;j<strlen(str);j++){
            current[(int)str[j]-97]++;
        }
        for(int j=0;j<26;j++){
            if(i==0){
                box[j]=current[j];
            }else{
                box[j]=min(box[j],current[j]);
            }
        }
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<box[i];j++){
            cout << (char)(i+97);
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
void chmax(t &a, u b)
{
    if (a < b)
        a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
    if (b < a)
        a = b;
}

int main()
{
    int n;
    cin >> n;
    int c[9] = {0};
    rep(i, n)
    {
        int a;
        cin >> a;
        if (a <= 399)
        {
            c[0] = 1;
        }
        else if (a <= 799)
        {
            c[1] = 1;
        }
        else if (a <= 1199)
        {
            c[2] = 1;
        }
        else if (a <= 1599)
        {
            c[3] = 1;
        }
        else if (a <= 1999)
        {
            c[4] = 1;
        }
        else if (a <= 2399)
        {
            c[5] = 1;
        }
        else if (a <= 2799)
        {
            c[6] = 1;
        }
        else if (a <= 3199)
        {
            c[7] = 1;
        }
        else
        {
            c[8]++;
        }
    }
    int cnt = 0;
    rep(i, 8)
    {
        if (c[i] == 1)
        {
            cnt++;
        }
    }
    cout << max(1, cnt) << " " << cnt + c[8] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;

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

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str = br.readLine();
      int x = Integer.parseInt(str);

      System.out.println( (int)Math.pow(x,3) ); 

   }
}

Measured memory_bytes: 24160
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int numofbits(unsigned long long bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned long long flag = 0;
    int n, k, a, q, Q;
    cin >> n;
    vector<unsigned long long> mask(n, 0);
    rep(i, n) {
        cin >> k;
        rep(j, k) {
            cin >> a;
            mask[i] |= (1ull << a);
        }
    }
    cin >> Q;
    rep(i, Q) {
        cin >> q >> a;
        if(q == 0) { // test
            cout << (flag & (1ull << a) ? 1 : 0) << endl;
        } else if(q == 1) { // set
            flag |= mask[a];
        } else if(q == 2) { // clear
            flag &= ~mask[a];
        } else if(q == 3) { // flip
            flag ^= mask[a];
        } else if(q == 4) { // all
            cout << ((flag & mask[a]) == mask[a]) << endl;
        } else if(q == 5) { // any
            cout << ((flag & mask[a]) > 0) << endl;
        } else if(q == 6) { // none
            cout << ((flag & mask[a]) == 0) << endl;
        } else if(q == 7) { // count
            cout << numofbits(flag & mask[a]) << endl;
        } else if(q == 8) { // val
            cout << (flag & mask[a]) << endl;
        }
    }
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define gcd(m,n)        __gcd(m,n)
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz               size()
#define inc(i,x,y)      for(int i=x;i<=y;i++)
#define dec(i,x,y)      for(int i=x;i>=y;i--)



#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}

//////////////////////////////code//////////////////////////////
vi adj[200001];
int vis[200001];
int dp[200001];
vi a(200002);
void filldp(int node,vi &s)
{
    vis[node]++;
    int f=0;
    int ele,x;
    if(s.empty() || s[s.sz-1]<a[node])
    {   f=1;
        s.pb(a[node]);
    }
    else{

         x = lower_bound(all(s),a[node])-s.begin();
        ele=s[x];
        s[x] = a[node];
    }

    dp[node]=s.sz;

    inc(i,0,adj[node].sz-1)
    {
        if(!vis[adj[node][i]])
         filldp(adj[node][i],s);
    }
    if(f)
    s.pop_back();
    else
     s[x]=ele;
}
int32_t main()
{
  fast();

   int n;
   cin>>n;

   memset(vis,0,sizeof(vis));
   inc(i,1,n) cin>>a[i];

   inc(i,0,n-2)
   {
       int u,v;
       cin>>u>>v;
       adj[u].pb(v);
       adj[v].pb(u);
   }

   vi s;
   filldp(1,s);

   inc(i,1,n)
   cout<<dp[i]<< "\n";

}


Measured memory_bytes: 33148
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int N; cin>>N;
    int L[N];
    int sum = 0;
    REP(i,N) {
        cin>>L[i];
        sum += L[i];
    }
    sort(L,L+N);
    if (2*L[N-1]<sum) {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}


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

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

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ++mp[a[i]];
    }
    int ans = 0;
    int cnt = 0;
    for(auto it : mp){
        if(it.second >= 3){
            if(it.second % 2 == 0){
                ans += it.second - 2;
                it.second = 2;
            }
            else{
                ans += it.second -1;
                it.second = 1;
            }
        }
        if(it.second == 2)  ++cnt;
    }
    ans += (cnt % 2 == 0) ? cnt : cnt + 1;
    cout << n - ans << endl;
}

Measured memory_bytes: 5376
using System;
using System.Linq;
using System.Collections.Generic;
    
    
class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();

        if(S == "ABC") {
            Console.WriteLine("ARC");
        } else  {
            Console.WriteLine("ABC");
        }
    }
}

Measured memory_bytes: 25892
cake_kind_cnt,cake_select_cnt = gets.chomp.split(" ").map(&:to_i)
strs = []
cake_kind_cnt.times do
  strs << gets.chomp.split(" ").map(&:to_i)
end

if cake_select_cnt < 1
  puts 0
  exit
end

sums = []
calculated_strs = []
[1,-1].repeated_permutation(3) do |n|
  calculated_strs = strs.collect do |x, y, z|
    x * n[0] + y * n[1] + z * n[2]
  end
  calculated_strs.sort!
  calculated_strs.reverse!
  sums << calculated_strs[0..(cake_select_cnt-1)].inject(:+)
end

puts sums.max

Measured memory_bytes: 2040
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll ans;
	if(k<=(x/d)){
	    ans=x-d*k;
	}
	else{
	    if((k-(x/d))%2){
	        ans=d-x%d;
	    }
	    else{
	        ans=x%d;
	    }
	}
	cout<<ans;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  n = n % 100 % 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    cout << "hon" << endl;
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void){
    int W,H;
    char c;
    scanf("%d %d",&W,&H);
    scanf(" %c",&c);
    for(int i=1;i<H+1;i++){

        for(int j=1;j<W+1;j++){

            if(i==1){
                if(j==1||j==W) printf("+");
                else if(1<j&&W>j) printf("-");
                if(j==W) printf("\n");
            }
            else if(i<H&&1<i){
                if(j==1||j==W) printf("|");
                else if(j==W/2+1&&i==H/2+1){printf("%c",c);}
                else printf(".");
                if(j==W) printf("\n");
            }
            else if(i==H){
                if(j==1||j==W) printf("+");
                else printf("-");
            }
        }
    }
    printf("\n");
    return 0;
}



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

int main(){
  string S;
  cin >> S;
  int n = S.size();
  string S1;
  string S2;
  if(n%2 == 1){
    S1 = S.substr(0,n/2);
    S2 = S.substr(n/2+1,n/2);
  }else{
    S1 = S.substr(0,n/2);
    S2 = S.substr(n/2,n/2);
  }
  
  //S2 = reverse(S2.begin(),S2.end());
  //cout << S1 << " " << S2 <<endl;
  int cnt=0;
  for(int i=0;i<n/2;i++){
    if(S1[i] != S2[n/2-i-1]){
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){

    int n,i,j,ans,z;
    int w[100];
    int sum1[100];
    int sum3[100];
    int sum=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
    }

    for(i=0;i<n;i++){
        sum+=w[i];
    }

    for(i=0;i<n;i++){
        sum3[i]=0;
        for(j=i;j<n;j++){
            sum3[i]+=w[j];
        }
        sum1[i]=sum-sum3[i];

    }

    ans=sum;


    for(i=0;i<n;i++){
        z=abs(sum1[i]-sum3[i]);
        if(z<ans){
            ans=z;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
d=list(map(int, input().split()))

height = d[0]
width = d[1]
A = d[2]
B = d[3]

z = '0'
o = '1'

s=z*A+o*(width-A)
t=o*A+z*(width-A)

for i in range(B):
  print(s)

for i in range(height-B):
  print(t)

Measured memory_bytes: 3956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
  public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(2 * Double.parseDouble(bf.readLine()) * Math.PI);
    }
}

Measured memory_bytes: 33188
# coding: utf-8
# Your code here!

b=0.0001
while True:
    try:
        a=list(map(float,input().split()))
        x=(a[2]*a[4]-a[1]*a[5])/(a[0]*a[4]-a[1]*a[3])
        y=(a[2]*a[3]-a[0]*a[5])/(a[1]*a[3]-a[0]*a[4])
        print("{0:.3f} {1:.03f}".format(x+b,y+b))
    except EOFError:
        break


Measured memory_bytes: 5580
#include <bits/stdc++.h> 
   
using namespace std; 
   
int n, A[21]; 
   
int solve(int i, int m) { 
  if (m == 0) return 1; 
  if (i >= n) return 0; 
  int result = solve(i + 1, m) || solve(i + 1, m - A[i]); 
  return result; 
}  
   
int main() { 
  cin >> n; 
  for (int i = 0; i < n; i++) { 
    cin >> A[i]; 
  } 
  int q, m; 
  cin >> q; 
  for (int i = 0; i < q; i++) { 
    cin >> m; 
    if (solve(0, m)) cout << "yes" << endl; 
    else cout << "no" << endl; 
  } 
  return 0;
}  


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 998244353;
const int maxn = 2e5 + 5;
const int logn = 20;

int n;
int x[maxn], d[maxn], ord[maxn], dp[maxn];
vector<int> vec;

class SegmentTree{
private:
	static const int siz = 262144;
	int dat[siz << 1];
public:
	inline int size(){ return siz; }
	inline void init(){ memset(dat, -1, sizeof(dat)); return; }
	inline void update(int x, int l, int r, int y, int k){
		if(l == r){
			dat[x] = k;
			return;
		}
		int md = l + r >> 1;
		if(y <= md)
			update(x << 1, l, md, y, k);
		else
			update(x << 1 | 1, md + 1, r, y, k);
		dat[x] = max(dat[x << 1], dat[x << 1 | 1]);
		return;
	}
	inline int query(int x, int l, int r, int s, int t){
		if(l >= s && r <= t){
			return dat[x];
		}
		int md = l + r >> 1;
		if(t <= md)
			return query(x << 1, l, md, s, t);
		else if(s > md)
			return query(x << 1 | 1, md + 1, r, s, t);
		return max(query(x << 1, l, md, s, t), query(x << 1 | 1, md + 1, r, s, t));
	}
}seg;

inline bool cmp(const int &i, const int &j){
	return x[i] < x[j];
}

inline int query(int l, int r){
	l = lower_bound(vec.begin(), vec.end(), l) - vec.begin();
	r = upper_bound(vec.begin(), vec.end(), r) - vec.begin() - 1;
	return seg.query(1, 0, seg.size() - 1, l, r);
}

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		scanf("%d%d", x + i, d + i);
		ord[i] = i;
		vec.PB(x[i]);
	}
	sort(vec.begin(), vec.end());
	sort(ord, ord + n, cmp);
	seg.init();
	dp[n] = 1;
	for(int i = n - 1; i >= 0; --i){
		int pos = query(x[ord[i]], x[ord[i]] + d[ord[i]] - 1);
		pos = max(pos, (int)(lower_bound(vec.begin(), vec.end(), x[ord[i]] + d[ord[i]]) - vec.begin()));
		seg.update(1, 0, seg.size() - 1, i, pos);
		dp[i] = (dp[i + 1] + dp[pos]) % INF;
	}
	printf("%d\n", dp[0]);
	return 0;
}


Measured memory_bytes: 6388
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n, m, s, d;
		while (true) {
			n = Integer.parseInt(bf.readLine());
			if (n == 0)
				break;
			m = Integer.parseInt(bf.readLine()) - 1;
			s = Integer.parseInt(bf.readLine()) - 1;
			d = Integer.parseInt(bf.readLine());
			char[][] c = new char[d][n - 1];
			for (int i = 0; i < d; i++)
				c[i] = bf.readLine().toCharArray();
			int[][] col = new int[2][d + 1];
			col[0][0] = m;
			col[1][d] = s;
			for (int i = 0; i < d; i++) {
				if (col[0][i] < n - 1 && c[i][col[0][i]] == '1') {
					col[0][i + 1] = col[0][i] + 1;
				} else if (col[0][i] > 0 && c[i][col[0][i] - 1] == '1') {
					col[0][i + 1] = col[0][i] - 1;
				} else {
					col[0][i + 1] = col[0][i];
				}
			}
			for (int i = d - 1; i >= 0; i--) {
				if (col[1][i + 1] < n - 1 && c[i][col[1][i + 1]] == '1') {
					col[1][i] = col[1][i + 1] + 1;
				} else if (col[1][i + 1] > 0 && c[i][col[1][i + 1] - 1] == '1') {
					col[1][i] = col[1][i + 1] - 1;
				} else {
					col[1][i] = col[1][i + 1];
				}
			}
			if (col[0][0] == col[1][0]) {
				System.out.println("0");
				continue;
			}
			for (int i = 1; i <= d; i++) {
				if (col[0][i] == col[0][i - 1] && col[1][i] == col[1][i - 1] && (col[0][i] - col[1][i] == 1 || col[1][i] - col[0][i] == 1)) {
					System.out.println(i + " " + Math.max(col[0][i], col[1][i]));
					break;
				}
				if (i == d) {
					System.out.println("1");
				}
			}
		}
	}
}

Measured memory_bytes: 8976
using System;

using static System.Console;
using static System.Linq.Enumerable;

public static class Program
{
  public static void Main()
  {
    int N = int.Parse(ReadLine());
    int K = int.Parse(ReadLine());
    var ans =
      ReadLine()
      .Split((char[])null, StringSplitOptions.RemoveEmptyEntries)
      .Select(x => int.Parse(x))
      .Sum(x => 2 * Math.Min(x, K - x));
    WriteLine(ans);
  }
}

Measured memory_bytes: 11348
#include <stdio.h>

int main(){
   int i, j, k;
   int a, b, c, n;
   int num, N[100][100],color[100],d[100];
   
   scanf("%d", &n);
   
   for(i=0; i<n; i++){
      for(j=0; j<n; j++){
         N[i][j]=1000000;
      }
   }

   for(i=0; i<n; i++){
      scanf("%d%d",&a, &c);
         for(j=0; j<c; j++){
            scanf("%d",&b);
            scanf("%d",&N[a][b]);
         }
    }

    for(i=0; i<n; i++){
       d[i] = 1000000;
       color[i] = 0;
    }
    d[0] = 0;

   while (1){
      k = 1000000;
   for(i=0; i<n; i++){
      if(color[i] != 1 && d[i] < k){
          k = d[i];
          num = i;
      }
   }
   if(k == 1000000) break;
   color[num] = 1;
   
   for(i=0; i<n; i++){
      if(color[i] != 1 && d[num]+N[num][i] < d[i]){
         d[i] = d[num]+N[num][i];
       }
   }
   }

   for (i=0; i<n; i++){
       printf("%d %d\n",i, d[i]);
   }

   return 0;
}

Measured memory_bytes: 1768