akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;

void solve(string s) {
    int i = 0;
    int count() {
        if (s[i] == '[') {
            int[] xs;
            while (s[i] == '[') {
                i++; // skip '['
                xs ~= count();
                assert(s[i] == ']');
                i++; // skip ']'
                if (i == s.length) break;
            }
            xs.sort;
            return xs[0 .. $ / 2 + 1].reduce!"a + b";
        } else {
            string x;
            while (s[i].isDigit) {
                x ~= s[i];
                i++;
            }
            return x.to!int / 2 + 1;
        }
    }
    count.writeln;
}

void main() {
    int n; readf("%d\n", &n);
    foreach (_; 0 .. n) {
        solve(readln.chomp);
    }
}

Measured memory_bytes: 1824
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

long long dp[1111][22222];

int main(){
    int N;
    cin >> N;
    vector<tuple<int, int, int, int>> A(N);
    for(int i=0; i<N; i++){
        int w, s, v;
        cin >> w >> s >> v;
        A[i] = make_tuple(w+s, w, s, v);
    }
    sort(A.begin(), A.end());

    for(int i=0; i<N; i++){
        int ws, w, s, v;
        tie(ws, w, s, v) = A[i];

        for(int j=0; j<22222; j++)
            dp[i+1][j] = dp[i][j];

        for(int j=0; j<=s; j++){
            if(j+w >= 22222) continue;
            dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j] + v);
        }
    }
    long long ans = 0;
    for(int i=0; i<22222; i++)
        ans = max(ans, dp[N][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 174208
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll n, a=LINF;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, 5){
    ll l;
    cin >> l;
    mins(a, l);
  }
  cout << (n+a-1)/a + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    int n, W; cin>>n>>W;
    vector<int> w(n), v(n);
    for(int i=0; i<n; i++) cin>>w[i]>>v[i];

    vector<vector<ll>> dp(n+10, vector<ll>(n*1000+10, INF));
    dp[0][0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=n*1000; j++){
            if(j-v[i]>=0) dp[i+1][j]=min(dp[i][j], dp[i][j-v[i]]+w[i]);
            else dp[i+1][j]=dp[i][j];
        }
    }

    int ans=0;
    for(int i=0; i<=n*1000; i++){
        if(dp[n][i]<=W) chmax(ans, i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 87296
#include<bits/stdc++.h>
#pragma optimize ("O3")
#pragma target ("sse4")
const int MAXN=35;
const int INF=1e9+17;
const int MOD=1000000021;
using namespace std;

void mainp()
{
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    int maxx=max(a, max(b, c)), mx=maxx;
    for(int i=0; i<k; i++) maxx*=2;
    cout<<a+b+c-mx+maxx<<endl;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mainp();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	if (s[0]==s[1] && s[1]==s[2])
		cout << "No";
	else
		cout << "Yes";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*m
c=[0]*m
for i in range(m):
    b[i],c[i]=map(int,input().split())
xc=np.argsort(c)
a.sort()
co=0
f=0
for i in range(m-1,-1,-1):
    for j in range(b[xc[i]]):
        a[co]=max(a[co],c[xc[i]])
        if a[co]>c[xc[i]]:
            f=1
            break                
        co+=1
        if co>=n:
            f=1 
            break
    if f==1:
        break
print(sum(a))

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

int main(){
	string S;
	cin >> S;
	int N=S.size();
	char c1=S.at(0);
	char c2;
	int count=0;
	for(int i=1;i<N;i++){
		c2=S.at(i);
		if(c1!=c2){
			count++;
		}
		c1=c2;
	}
	cout<<count<<endl;
}



Measured memory_bytes: 512
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 50;
int N;
int A[MAX_N], B[MAX_N];
bool S[MAX_N+1];

ll pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = pow(x*x, n/2);
  if (n & 1) res *= x;
  return res;
}

const int MAX_V = 51, INF = 1e9;
int V = MAX_V;
int d[MAX_V][MAX_V];

void warshall_floyd() {
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
     for (int j = 0; j < V; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  for (int i = 0; i < N; ++i) cin >> B[i];

  fill(S+1, S+50, true);


  for (int i = 49; i >= 0; --i) {

    // iより大きいtrueの数と、i以下の数でグラフを作る
    fill(*d, *d+V*V, INF);
    for (int i = 0; i <= 50; ++i) d[i][i] = 0;
    for (int i = 0; i <= 50; ++i) {
      for (int k = 1; k <= 49; ++k) {
        if (S[k]) { d[i][i%k] = 1; }
      }
    }

    // A[i]からB[i]にたどり着けるかどうか判定
    warshall_floyd();
    bool ok = true;
    for (int i = 0; i < N; ++i) {
      if (d[A[i]][B[i]] >= INF) ok = false;
    }

    // 全て書き換え可能ならS[i]をfalse、書き換え不可能ならS[i+1]をtrue。
    if (!ok) S[i+1] = true;
    S[i] = false;
  }

  if (S[50]) {
    cout << -1 << endl;
  } else {
    ll ans = 0;
    for (int k = 1; k < 50; ++k) if (S[k]) { ans += pow(2, k); }
    cout << ans << endl;
  }

  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto &v : a) cin >> v;
    int m = accumulate(a.begin(), a.end(), 0) / N;
    int a0 = 0, a1 = 0;
    for (auto v : a)
    {
        a0 += (m - v) * (m - v);
        a1 += (m + 1 - v) * (m + 1 - v);
    }
    cout << min(a0, a1) << endl;
}


Measured memory_bytes: 256
import math
from itertools import permutations


N = int(input())
point = [None] * N
for i in range(N):
    x, y = map(int, input().split())
    point[i] = (x, y)

total_distance = 0
num = 0
for perm_points in permutations(point, N):
    num += 1
    for i in range(N - 1):
        p1 = perm_points[i]
        p2 = perm_points[i + 1]
        total_distance += math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)

print(total_distance / num)


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, x, y, sum = 0, q; cin>>n;
    vector<int> a(100005);
    for(int i = 0; i<n; i++){
        cin>>x;
        a[x]++;
        sum += x;
    }

    cin>>q;
    while(q--){
        cin>>x>>y;
        if(a[x]>0){
            sum -= a[x]*x;
            sum += a[x]*y;
            a[y] += a[x];
            a[x] = 0;
        }
        cout<<sum<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int  x,y,s2,s1;
    scanf("%lld%lld",&x,&y);
    if(y<x*2)
        s2=y/2;
    else
    {
        s1=y-x*2;
        s2=x+s1/4;
    }
    printf("%lld",s2);
    return 0;
}


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

int main(void){
	double x1, x2, y1, y2;

	cin >> x1 >> y1 >> x2 >> y2;
	printf("%.8f\n", sqrt((x1 - x2)*(x1 - x2) + (y1-y2)*(y1-y2)));

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  long long a[n];
  long long max = 1000000000000000000;
  long long ans=1;
  
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }

  for(int i=0;i<n;i++){
    if(max/ans<a[i]){
      cout << -1 << endl;return 0;
    }
    ans = ans*a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int kazu=s.size();
  int kotae=0;
  for(int i=0;i<kazu;i++){
    if(s[i]=='+')kotae++;
    if(s[i]=='-')kotae--;
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define NIL -1
#define INF 100000000
#define WHITE 1
#define GREY 2
#define BLACK 3
#define N_MAX 10000

vector<pair<int, int>> G[N_MAX];
int V[N_MAX];
int V_value[N_MAX];

void init(){
    for(int i = 0; i < N_MAX; i++){
        V[i] = WHITE;
        V_value[i] = INF;
    }
}

int main(void){
    init();
    int n;
    scanf("%d\n", &n);

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

    priority_queue<pair<int, int>> PQ;

    V[0] = BLACK;
    V_value[0] = 0;
    int new_node = 0;
    
    while(1){
        for(int i = 0; i < G[new_node].size(); i++){
            int node_num = G[new_node][i].first;
            int node_value = G[new_node][i].second;
            V_value[node_num] = min(V_value[node_num], V_value[new_node] + node_value);
            PQ.push(make_pair(V_value[node_num] * (-1), node_num));
        }

        int min_value;
        int min_index = NIL;
        while(!PQ.empty()){
            pair<int, int> p = PQ.top(); PQ.pop();
            //printf("pop %d %d\n", p.second, p.first * (-1));
            if(p.first * (-1) == V_value[p.second] && V[p.second] == WHITE){
                min_value = p.first * (-1);
                min_index = p.second;
                break;
            }
        }

        if(min_index == NIL)
            break;

        new_node = min_index;
        V[new_node] = BLACK;
        V_value[new_node] = min_value;
    }
    
    for(int i = 0; i < n; i++){
        printf("%d %d\n", i, V_value[i]);
    }

    return 0;
}



Measured memory_bytes: 9924
## 最初のmodをどうにか高速にやりたい → modの性質を使う
## xiのpopcount（1の数）はxのpopcount+1または-1
n=int(input())
x_str=input()
x_popcount=x_str.count('1')
dp=[0]*(x_popcount+1)
for i in range(1,x_popcount+1):
    popcount=format(i,'b').count('1')
    dp[i]=dp[i%popcount]+1
# print(dp)
# x=int(x_str,2)
if x_popcount>1:
    pows_minus=[pow(2,i,(x_popcount-1)) for i in range(n)]
    # x_minus=x%(x_popcount-1)
    x_minus=0
    for i in range(n):
        if x_str[i]=='1':
            x_minus+=pows_minus[n-1-i]
pows_plus=[pow(2,i,(x_popcount+1)) for i in range(n)]
# x_plus=x%(x_popcount+1)
x_plus=0
for i in range(n):
    if x_str[i]=='1':
        x_plus+=pows_plus[n-1-i]

for i in range(len(x_str)):
    ## xi=xi mod popcount(x)+-1
    xi=-1
    if x_str[i]=='1':
        if x_popcount>1: ## else: xi=-1
            xi=(x_minus-pows_minus[n-1-i])%(x_popcount-1)
    else:
        xi=(x_plus+pows_plus[n-1-i])%(x_popcount+1)
    if xi==-1:
        print(0)
    else:
        print(dp[xi]+1)

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

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			Integer a[] = new Integer[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: 21332
import heapq
n,m=map(int,input().split())
c=[list(map(int,input().split())) for i in range(n)]
ans, available = 0, []
heapq.heapify(available)
heapq.heapify(c)
for i in range(1, m+1):
    while len(c)!=0 and c[0][0]<=i:
        now = heapq.heappop(c)
        heapq.heappush(available,-now[1])
    if len(available) != 0:
        ans -= heapq.heappop(available)
print(ans)


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

using namespace std;

int n, u, v;
vector<vector<int> > g;
vector<int> adist, tdist;
int ans;

int dfs(int v, int pv, vector<int> &d) {
  for (auto nv : g[v]) {
    if (nv == pv) continue;
    d[nv] = d[v] + 1;
    dfs(nv, v, d);
  }
}

int dfs2(int v, int pv) {
  bool leaf = true;
  for (auto nv : g[v]) {
    if (nv == pv) continue;
    dfs2(nv, v);
    leaf = false;
  }
  if (leaf) {
    if (adist[v] > tdist[v]) {
      ans = max(ans, adist[v]);
    }
  }
}

int main() {
  cin >> n >> u >> v;
  u--, v--;
  g.assign(n, vector<int>());
  for (int i = 0; i + 1 < n; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  adist.assign(n, 0);
  tdist.assign(n, 0);
  dfs(u, -1, tdist);
  dfs(v, -1, adist);
  dfs2(v, -1);
  cout << ans - 1 << endl;

  return 0;
}

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

public class Hello
{
    private const ulong MOD9 = 1000000007;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var gcd_f = new int[n];
        var gcd_l = new int[n];

        gcd_f[0] = 0;
        for (int i = 1; i < gcd_f.Length; ++i)
        {
            gcd_f[i] = GCD(gcd_f[i - 1], a[i - 1]);
        }

        gcd_l[n - 1] = 0;
        for (int i = n - 2; i >= 0; --i)
        {
            gcd_l[i] = GCD(gcd_l[i + 1], a[i + 1]);
        }

        var max = 0;
        for (int i = 0; i < gcd_l.Length; ++i)
        {
            var g = GCD(gcd_l[i], gcd_f[i]);
            if (g > max)
                max = g;
        }

        Console.WriteLine(max);
    }

    public static int GCD(int a, int b) => b > a ? GCD_core(b, a) : GCD_core(a, b);
    private static int GCD_core(int a, int b) => b != 0 ? GCD_core(b, a % b) : a;
}


Measured memory_bytes: 31068
L = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [(A[i], L[A[i]]) for i in range(M)]

X = [0] + ([-1] * N)
for i in range(1, N+1):
  for b in B:
    if b[1] <= i:
      X[i] = max(X[i], X[i-b[1]] * 10 + b[0])

print(X[N])


Measured memory_bytes: 14516
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

// デバッグ用
#define _DEBUG
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
// ここまで
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

struct D {
    LLI a, b;

    D(LLI _a, LLI _b) : a(_a), b(_b) {}

    bool operator<(D &another) {
        if(a == another.a) {
            return b > another.b;
        }
        return a < another.a;
    }
};

int main() {
    int N, M;
    LLI a, b;
    cin >> N >> M;
    vector<D> v;
    REP(i, N) {
        cin >> a >> b;
        v.push_back(D(a, b));
    }
    sort(ALL(v));
    int c = 0;
    LLI p = 0;
    for(auto f : v) {
        if(M <= c) {
            break;
        }
        p += f.a * (f.b < (M - c) ? f.b : (M - c));
        c += f.b;
    }
    cout << p;

    return 0;
}

Measured memory_bytes: 2420
#include<vector>
#include<iostream>
using namespace std;
int main() {
	vector<int> a;
	int q;
	int cmd;
	int n;

	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin>>cmd;
		switch (cmd)
		{
		case 0:
			cin >> n;
			a.push_back(n);
			break;
		case 1:
			cin >> n;
			cout << a[n] << endl;
			break;
		case 2:
			a.pop_back();
			break;
		default :
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3876
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(m);
  vector<int>b(m);
  rep(i,m)cin>>a[i]>>b[i];
  rep(i,m){
    a[i]--;
    b[i]-=2;
  }
  vector<pair<int,int>>p(m);
  rep(i,m){
    p[i].first=b[i];
    p[i].second=a[i];
  }
  sort(p.begin(),p.end());
  rep(i,m){
    
  }
  int ans=0,t=-1;
  for(int i=0;i<m;i++){
    if(t<p[i].second){
      ans++;
      t=p[i].first;
    }
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<bitset>
using namespace std;
bitset<3000000>D;
int n, a, s;
int main() {
	int i;
	scanf("%d", &n);
	D[0] = 1;
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		D |= D << a;
		s += a;
	}
	for (i = (s + 1) / 2;; i++)if (D[i])break;
	printf("%d\n", i);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 200 + 10;
int A[maxn], B[maxn];
int main(void)
{
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i)
		cin >> B[i];
	int s = 0;
	for (int i = n; i >= 1; --i) {
		if (i == 1)
			A[i] = B[i];
		else if (i == n)
			A[i] = B[i - 1];
		else
			A[i] = min(B[i], B[i - 1]);
		s += A[i];
		// cout << i << " " << A[i] << endl;
	}
	cout << s << endl;


	return 0;
}

/*
2 2 5
*/

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		int result = 0;
		int min = 0;
		int max = 0;
		HashSet<Integer> hs = new HashSet<Integer>();
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(a[i] < 400){
		        hs.add(1);
		    }else if(a[i] < 800){
		        hs.add(2);
		    }else if(a[i] < 1200){
		        hs.add(3);
		    }else if(a[i] < 1600){
		        hs.add(4);
		    }else if(a[i] < 2000){
		        hs.add(5);
		    }else if(a[i] < 2400){
		        hs.add(6);
		    }else if(a[i] < 2800){
		        hs.add(7);
		    }else if(a[i] < 3200){
		        hs.add(8);
		    }else{
		        cnt++;
		    }
		}
		if(hs.size() == 0){
		    min = 1;
		    max = cnt;
		}else{
		    min = hs.size();
		    max = min + cnt; 
		}
		

		// 出力
		System.out.println(min + " " + max);
		//System.out.println(result);
	}
}



Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i;
	cin>>N;
	vector<int> V(N);
	for (i=0;i<N;i++){
		cin>>V[i];
	}
	sort(V.begin(),V.end());
	double x=(V[0]+V[1])/2.0;;
	for (i=2;i<N;i++){
		x=(x+V[i])/2.0;
	}
	cout<<x<<endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans, acc = 0, list(accumulate(a))
for i in range(n - 1):
    ans += a[i] * (acc[-1] - acc[i])
    ans %= mod
print(ans)


Measured memory_bytes: 102008
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{
	private void solve(){
		System.out.println(s.next().replaceFirst("7","8"));
	}

	public static void main(String[] $){
		new Main().solve();
		System.out.flush();
	}


	static class System{
		private static final InputStream	in	=java.lang.System.in;
		private static final PrintWriter	out	=new PrintWriter(java.lang.System.out,false);
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}

	static long gLong(){
		return s.nextLong();
	}

	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}

	static Range rep(int f,int t){
		return new Range(f,t);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
		int from,to,c;
		Range(int from,int to){
			this.from=from;
			this.to=to;
			this.c=from;
		}
		Range(int n){
			this(0,n-1);
		}
		@Override
		public Iterator<Integer> iterator(){
			return this;
		}
		@Override
		public boolean hasNext(){
			return c<=to;
		}
		@Override
		public int nextInt(){
			return c++;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}

Measured memory_bytes: 21844
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] counter = new int[200000];

        HashSet<Integer> list = new HashSet<>();

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list.add(value);
            counter[value - 1]++;
        }

        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (Integer value: list
             ) {
            queue.add(counter[value - 1]);
        }

        int ans = 0;

        for (int i = 0; i < list.size() - k; i++) {
            ans += queue.poll();
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 100728
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

n, k, *a = map(int, read().split())
c = Counter(a)

l = list(c.items())
l.sort(key=lambda x: x[1])

ans = 0
for i in range(len(set(a)) - k):
    ans += l[i][1]
print(ans)

Measured memory_bytes: 56988
import copy

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))

#(っ•₃•c)♡(っ•₃•c)♡(っ•₃•c)♡(っ•₃•c)♡(っ•₃•c)♡

visited = []
for _ in range(h):
    visited.append([-1 for __ in range(w)])

visited[0][0] = 0
here = [[0,0]]
count = 0

#(っ०ω०c)(っ०ω०c)(っ०ω०c)(っ०ω०c)(っ०ω०c)(っ०ω०c)

def udlr(line):
    ans = []
    for cell in line:
        if cell[0]-1 >= 0:
            ans.append([cell[0]-1, cell[1]])
        if cell[0]+1 < h:
            ans.append([cell[0]+1, cell[1]])
        if cell[1]-1 >= 0:
            ans.append([cell[0], cell[1]-1])
        if cell[1]+1 < w:
            ans.append([cell[0], cell[1]+1])
    return ans

flag = 0

#ｏ(｡・‧̫・｡)ｏｏ(｡・‧̫・｡)ｏｏ(｡・‧̫・｡)ｏｏ(｡・‧̫・｡)ｏｏ(｡・‧̫・｡)ｏ

while True:
    count += 1
    line = []
    for cell in udlr(here):
        a = cell[0]
        b = cell[1]
        if s[a][b] == "." and visited[a][b] == -1:
            visited[a][b] = count
            line.append([a, b])
            if a == h-1 and b == w-1:
                flag = 1
    here = copy.deepcopy(line)
    if flag:
        break
    if here == []:
        break

#(੭ु ›ω‹ )੭ु⁾⁾♡(੭ु ›ω‹ )੭ु⁾⁾♡(੭ु ›ω‹ )੭ु⁾⁾♡(੭ु ›ω‹ )੭ु⁾⁾♡

if visited[h-1][w-1] == -1:
    print(-1)
else:
    cnt = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                cnt += 1
    print(h*w - 1 - visited[h-1][w-1] - cnt)

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

int compare_asc(const void * a,  const void * b){
    return *(ll*)a - *(ll*)b;
}

ll X[200001];
ll origX[200001];
int main(void){
    int N;
    scanf("%d",&N);
    
    for(int i = 1; i <= N; i++){
        scanf("%lld", X+i);
        origX[i]=X[i];
    }
    origX[0] = X[0] = 0;
    qsort(X,N+1,sizeof(ll),compare_asc);
    
    //for(int i = 0; i <= N; i++){ printf("%lld ", X[i]); } puts("");
    
    for(int i = 1; i <= N; i++){
        printf("%lld\n", (origX[i] <= X[N/2]) ? X[N/2+1] : X[N/2]);
    }
}

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

int main(){
    int N;
    cin >> N;
    int A_list[110];
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> A_list[i];
        sum += A_list[i];
    }
    int x1 = sum/N, x2 = sum/N+1;
    int cost1 = 0, cost2 = 0;
    for(int i=0; i<N; i++){
        cost1 += (A_list[i]-x1)*(A_list[i]-x1);
        cost2 += (A_list[i]-x2)*(A_list[i]-x2);
    }
    cout << (cost1 < cost2 ? cost1 : cost2);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
ll MOD = 1000000007;
#define INF (1e9)

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll A, B;
    cin >> A >> B;
    cout << (A-1) * (B-1) << endl;
    return 0;
}


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

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 << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }

  return 0;
}

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

int main() {
  char  a, b;
  cin >> a >> b;
  if(a == 'H'){
    cout << b << endl;
  }
  else if(a == 'D'){
    if(b == 'H'){
      cout << 'D' <<endl;
    }
    else if(b == 'D'){
      cout << 'H' << endl;
    }
  }
}


Measured memory_bytes: 256
import sys
from math import log10

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

def bisearch_min(mn, mx, func):
    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

def mat_pow(mat, init, K, MOD):
    """ 行列累乗 """

    def mat_dot(A, B, MOD):
        """ 行列の積 """

        if not isinstance(A[0], list) and not isinstance(A[0], tuple):
            A = [A]
        if not isinstance(B[0], list) and not isinstance(A[0], tuple):
            B = [[b] for b in B]
        n1 = len(A)
        n2 = len(A[0])
        _ = len(B)
        m2 = len(B[0])
        res = list2d(n1, m2, 0)
        for i in range(n1):
            for j in range(m2):
                for k in range(n2):
                    res[i][j] += A[i][k] * B[k][j]
                    res[i][j] %= MOD
        return res

    def _mat_pow(mat, k, MOD):
        """ 行列matをk乗する """

        n = len(mat)
        res = list2d(n, n, 0)
        for i in range(n):
            res[i][i] = 1
        while k > 0:
            if k & 1:
                res = mat_dot(res, mat, MOD)
            mat = mat_dot(mat, mat, MOD)
            k >>= 1
        return res

    res = _mat_pow(mat, K, MOD)
    res = mat_dot(res, init, MOD)
    return [a[0] for a in res]

L, a, b, M = MAP()

A = [0] * 20
for i in range(1, 20):
    x = 10 ** i
    res = bisearch_min(-1, L, lambda m: ceil(x-a, b)-1 < m)
    A[i] = res
C = [0] * 20
for i in range(1, 20):
    C[i] = A[i] - A[i-1]

init = [0, a, 1]
for d in range(1, 20):
    K = C[d]
    if K == 0:
        continue
    mat = [
        [pow(10, d, M), 1, 0],
        [0, 1, b],
        [0, 0, 1],
    ]
    res = mat_pow(mat, init, K, M)
    init[0] = res[0]
    init[1] = res[1]
ans = res[0]
print(ans)

# dp0 = [0] * (L+1)
# dp1 = [0] * (L+1)
# dp0[0] = 0
# dp1[0] = a
# for i in range(1, L+1):
#     dp0[i] = (dp0[i-1]*pow(10, int(log10(dp1[i-1]))+1, M) + dp1[i-1]) % M
#     dp1[i] = dp1[i-1] + b
# ans = dp0[-1]
# print(ans)


Measured memory_bytes: 74340
#include <iostream>
using namespace std;
int main(){
  int N,K;
  char str[11];
  cin >> N >> str >> K;
  for(int i=0;i<N;i++){
    if(str[i]!=str[K-1])cout << "*";
    else cout << str[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

int K, N;
int input[200000 + 5];

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

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

	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &input[i]);
	}

	int ans = 2147483647;

	for (int i = 0; i < N; ++i)
	{
		int temp = input[(i + N - 1) % N] - input[i];
		if (temp < 0) temp += K;
		if (temp < ans) ans = temp;
	}

	for (int i = 0; i < N; ++i)
	{
		int temp = input[i] - input[(i + 1) % N];
		if (temp < 0) temp += K;
		if (temp < ans) ans = temp;
	}

	printf("%d\n", ans);

	return 0;
}

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

#define mp make_pair
#define mx 105

int main(){
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	int ar[n][3];
	for(int i = 0; i<n; i++){
		for(int j = 0; j<3; j++){
			cin>>ar[i][j];
		}
	}

	for(int i = 1; i<n; i++){
		for(int j = 0; j<3; j++){
			if(j==0)
				ar[i][j] = max(ar[i][j]+ar[i-1][j+1], ar[i][j]+ar[i-1][j+2]);
			if(j==1)
				ar[i][j] = max(ar[i][j]+ar[i-1][j-1], ar[i][j]+ar[i-1][j+1]);
			if(j==2)
				ar[i][j] = max(ar[i][j]+ar[i-1][j-1], ar[i][j]+ar[i-1][j-2]);
		}
	}
	cout<<max(ar[n-1][0],max(ar[n-1][1], ar[n-1][2]))<<endl;

	return 0;

}

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

int main(){
      int n;cin >> n;
      int arr[n + 10];
      int ans = 0;
      for(int i = 0;i < n;i++){
            cin >> arr[i];
            if(arr[i] != i + 1)ans++;
      }
      if(ans == 0 || ans == 2)cout << "YES";
      else cout << "NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
    fast
    int n;
    cin>>n;
    vector<vector<int>>mp(10010,vector<int>(4,0));
    dom(i,100)
    {
        for(int j=i; j<=100; j++)
        {
            for(int k=j; k<=100; k++)
            {
                if(i*i+j*j+k*k+i*j+j*k+k*i<=10000)
                {
                    set<int>ss;
                    ss.insert(i);
                    ss.insert(j);
                    ss.insert(k);
                    mp[i*i+j*j+k*k+i*j+j*k+k*i][ss.size()]++;
                }
            }
        }
    }
    ll ans[n+1];
    dom(i,n)
    {
        mp[i][2]*=3;
        mp[i][3]*=6;
        ans[i]=mp[i][1]+mp[i][2]+mp[i][3];
    }
    dom(i,n)
    {
        cout << ans[i] << endl;
    }
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

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

    vector<vector<int>> v(n + 1, vector<int>());
    int a, b;
    REP(i, n - 1) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<int> w(n + 1, 0);
    int p, x;
    REP(i, q) {
        cin >> p >> x;
        w[p] += x;
    }

    function<void(int, int)> rec = [&](int pointer, int parent) {
        for (auto x : v[pointer]) {
            if (x == parent) continue;
            w[x] += w[pointer];
            rec(x, pointer);
        }
    };

    rec(1, -1);

    REP1(i, n) {
        cout << w[i];
        if (i != n) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 29696
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1e9+7;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,k;
    cin >> n >> k;

    vector<int> num(n);

    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            a--;
            num[a]++;
        }
    }

    int ans = 0;
    rep(i,n) if(num[i] == 0) ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int n;
int v[21],c;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  FOR(i,n) cin>>v[i];
  FOR(i,n){
    cin>>c;
    v[i]-=c;
  }
  sort(v,v+n,greater<int>() );
  int ans=0,oldans;
  FOR(i,n){
    if(ans+v[i]<ans) break;
    ans+=v[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	// int a = 3^0;
	// cout << a << endl;
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll all=0;
	rep(i,n){
		all=all^a[i];
	}
	// cout << all << endl;
	rep(i,n){
		int now = all^a[i];
		cout << now << ' ';
		// cout << all^a[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 4776
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    ll t = 1LL, a = 1LL;

    for(int i = 0; i < N; i++) {
        ll T, A;
        cin >> T >> A;

        ll front = 1LL;
        ll back = ll(pow(10, 18)) * 2LL / max(T, A);

        ll s = pow(10, 18);

        while(front < back) {
            ll mid = front + (back - front) / 2LL;
            if(T * mid >= t && A * mid >= a) {
                s = min(s, mid);
                back = mid;
            } else {
                front = mid + 1LL;
            }
        }

        t = T * s;
        a = A * s;
    }

    cout << t + a << endl;
}

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

# define M_PI           3.14159265358979323846
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    double r;
    cin>>r;
    double ans=2*M_PI*r;
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

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

int main() {
  int r,c;
  cin >> r >> c;
  vector<vector<int> > vec(r+1,vector<int>(c+1));
  
  for (int i=0; i<r; i++) {
      vec.at(i).at(c)=0;
      for (int j=0; j<c; j++) {
          cin >> vec.at(i).at(j);
          vec.at(i).at(c)+=vec.at(i).at(j);
      }
  }
  
  for (int i=0; i<c+1; i++) {
      vec.at(r).at(i)=0;
      for (int j=0; j<r; j++) {
          vec.at(r).at(i)+=vec.at(j).at(i);
      }
  }
  
  for (int i=0; i<r+1; i++) {
      for (int j=0; j<c+1; j++) {
          cout << vec.at(i).at(j);
          if(j!=c) cout << " ";
      }
      cout << endl;
  }
  
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);
typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,m,l; cin >> n >> m >> l;
    vvll d(n, vll(n));
    rep(i,n){
        rep(j,n){
            if(i == j)d[i][j] = 0;
            else d[i][j] = INF;
        }
    }

    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c; d[b][a] = c;
    }

    //わーシャル
    rep(k,n)rep(i,n)rep(j,n)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    /*rep(i,n){
        rep(j,n)cout << d[i][j] << " ";
        cout << endl;
    }*/

    vvll dt(n, vll(n));
    rep(i,n){
        rep(j,n){
            if(i == j)dt[i][j] = 0;
            else if(d[i][j] <= l)dt[i][j] = 1;
            else dt[i][j] = INF;
        }
    }

    rep(k,n)rep(i,n)rep(j,n)dt[i][j] = min(dt[i][j], dt[k][j] + dt[i][k]);

    ll q;
    cin >> q;
    vll ans(q);
    rep(i,q){
        ll s,t;
        cin >> s >> t;
        s--;t--;
        ans[i] = (dt[s][t] != INF)? dt[s][t] : 0;
    }

    rep(i,q)cout << ans[i]-1 << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *x, const void *y) {
  return *(int *)x-*(int *)y;
}

int main() {
  int n, m, k=0; long long int ans = 0;
  scanf("%d%d", &n, &m);
  int a[n], b[30];
  for (int i=0; i<n; i++) scanf("%d", a+i);
  for (int i=0; i<30; i++) b[i]=0;
  qsort(a, n, sizeof(int), cmp);
  for (int i=0; i<n; i++) {
    for (int j=k; j<30; j++) {
      if (a[i]>=(1<<j) && a[i]<(1<<(j+1))) {
        b[j]++;
        k=j;
      }
    }
  }
  for (int i=29; i>=0; i--) {
    if (b[i] == 0) continue;
    if (m <= 0) break;
    int l = (m<b[i]) ? m : b[i];
    for (int j=0; j<l; j++) {
      a[n-1-j] /= 2;
    }
    b[i-1] += b[i];
    m-=l;
    qsort(a, n, sizeof(int), cmp);
  }
  /*while (m > 0) {
    qsort(a, n, sizeof(int), cmp);
    a[0] /= 2;
    m--;
  }*/
  for (int i=0; i<n; i++) {
    ans += a[i];
  }
  printf("%lld\n", ans);
  return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}



int check(int n){

	int temp=n+9;

	temp=temp/10;
	return temp*10;



}

bool comp(int a,int b){


	return a%10 > b%10;

}

int main() {
    int i,n,m,k,c=0;
    c_p_c();
    cin>>n;
    int a[n];
    fo(i,n) cin>>a[i];


    int ans = 1;
    int stillbig = a[0];
    for (int i = 1; i < n; ++i)
    {
    	/* code */
    	if(stillbig<=a[i]){
    		stillbig=a[i];
    		ans++;
    	}
    }
    cout<<ans<<endl;
    return 0;
 }



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,d=0;
  cin>>a;
  vector<int> b(a);
  fo(i,a)
    cin>>b[i];
  vector<int> c=b;
  Sort(c);
  fo(i,a){
    if(b[i]!=c[i])
      d++;
  }
  if(d<=2)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
let list_init n f =
  let rec aux i f l = if i < n then aux (i + 1) f (f i :: l) else l in
  aux 0 f []

let sumd x =
  let rec aux x s = if x < 10 then s + x else aux (x / 10) (s + (x mod 10)) in
  aux x 0

let calc i =
  list_init (i - 1) (fun x -> sumd (x + 1) + sumd (i - x - 1))
  |> List.fold_left min 9999999999

let () = Scanf.scanf "%d" calc |> Printf.printf "%d\n"


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll s=0;
    rep(0,i,n){
        cin>>a[i];
        s^=a[i];
    }
    rep(0,i,n){
        ll ans=s^a[i];
        cout<<ans<<" ";
    }
}

Measured memory_bytes: 4736
#include <cstdio>
#include <iostream>
#define MAX 25
#define NIL -1

struct Node{int parent,left,right;};
Node T[MAX];

void preParse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}

int main(){
  int n,a,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent=NIL;
  for(int i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    T[a].left=b;
    T[a].right=c;
    if(b!=NIL) T[b].parent=a;
    if(c!=NIL) T[c].parent=a;
  }
  int root=NIL;
  for(int i=0;i<n;i++){
    if(T[i].parent==NIL){
      root=i;
      break;
    }
  }
  int leftest=root;
  while(T[leftest].left!=NIL) leftest=T[leftest].left;

  std::cout << "Preorder\n";
  preParse(root);
  std::cout << std::endl;
  std::cout << "Inorder\n";
  inParse(root);
  std::cout << std::endl;
  std::cout << "Postorder\n";
  postParse(root);
  std::cout << std::endl;
}

Measured memory_bytes: 3288