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

using namespace std;

class UnionFind {
 public:
  std::vector<int> parent;

  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }
  UnionFind uf(N), vf(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    uf.unite(P[x], P[y]);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (uf.issame(i, P[i])) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1408
s = list(input())
N = len(s)
ans = [0 for _ in range(N)]

for i in range(N-1):
  if s[i] == "R" and s[i+1] == "L":
    ans[i+1] += 1
    ans[i] += 1
    if i+1 != N-1:
      t = 0
      for j in range(i+1, N-1):
        if s[j+1] == "R":
          break        
        t += 1
        if t % 2 == 0:
          ans[i+1] += 1
        if t % 2 != 0:
          ans[i] += 1
     
    if i != 0:
      t = 0
      for k in range(i, 0, -1):
        if s[k-1] == "L":
          break
        t += 1
        if t % 2 == 0:
          ans[i] += 1
        if t % 2 != 0:
          ans[i+1] += 1
          
print(*ans)

Measured memory_bytes: 7092
;; I read the submission #7244437.

(use '[clojure.string :only (split)])

(defn readlines [n acc]
  (if (= n 0)
    acc
    (recur (dec n)
           (conj acc (read-line)))))

(defn readline [s]
  (let [ss (split s #" ")]
    (let [[x y] (map #(Long/parseLong %) ss)]
      {:x x :y y})))

(defn distance2 [x y]
  (+ (Math/pow x 2) (Math/pow y 2)))

(defn distance2-v [v]
  (distance2 (:x v) (:y v)))

(defn dot [v1 v2]
  (+ (* (:x v1) (:x v2))
     (* (:y v1) (:y v2))))

(defn cross [v1 v2]
  (- (* (:x v1) (:y v2))
     (* (:x v2) (:y v1))))

(defn sum-v [v1 v2]
  {:x (+ (:x v1) (:x v2))
   :y (+ (:y v1) (:y v2))})

(defn classify [v1 vs acc]
  (if (empty? vs)
    acc
    (recur v1
           (next vs)
           (let [v2 (first vs)
                 d (dot v1 v2)
                 c (cross v1 v2)]
             (cond
               (> d 0) (update acc :positive-dot #(sum-v v2 %))
               (< d 0) (update acc :negative-dot #(sum-v v2 %))
               (> c 0) (update acc :positive-cross #(sum-v v2 %))
               :else (update acc :negative-cross #(sum-v v2 %)))))))

(defn variety [c]
  (let [v (:positive-dot c)
        n1 (:positive-cross c)
        n2 (:negative-cross c)]
    (apply
      max
      (map distance2-v [v
                        (sum-v v n1)
                        (sum-v v n2)
                        (sum-v (sum-v v n1) n2)]))))

(defn rotate90 [v]
  {:x (- (:y v))
   :y (:x v)})

(def zero-c
  {:positive-dot {:x 0 :y 0}
   :negative-dot {:x 0 :y 0}
   :positive-cross {:x 0 :y 0}
   :negative-cross {:x 0 :y 0}})

(defn solve []
  (let [n (Integer/parseInt (read-line))
        ls (readlines n [])
        vs (map readline ls)
        vs' (flatten (map #(take 4 (iterate rotate90 %)) vs))]
    (println
      (Math/sqrt
        (apply
          max
          (map (fn [v1]
                 (let [c (classify v1 vs zero-c)]
                   (variety c)))
               vs'))))))

(solve)


Measured memory_bytes: 80208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int n,m,q;
int a[55];
int b[55];
int c[55];
int d[55];
int A[15];
void dfs(int step,int lim)
{
	if(step == n+1)
	{
		ll res = 0;
		for(int i=1;i<=q;i++)
		{
			if(A[b[i]]-A[a[i]] == c[i])
				res+=d[i];
		}
		ans = max(ans,res);
		return ;
	}
	for(int i=lim;i<=m;i++)
	{
		A[step] = i;
		dfs(step+1,i);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	dfs(1,1);
	cout<<ans; 
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

ll f(ll a, ll b){return a+b;}
int other = 0;

struct segment_tree{
    int n;
    int seg[1000000];
    //要素数Nのセグメントツリーを構築
    segment_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(seg, 2*n-1, other);
    }
    //i番目の要素をxに変更(0番目から数える)
    void update(int i, ll x){
        i += n-1;
        seg[i] = x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //要素数N以上の最小の２べきnを取得
    ll size(){return n;}
    //query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得
    ll query(int a, int b, int i, int l, int r){
        if(a >= r || b <= l) return other;
        elif(a <= l && r <= b) return seg[i];
        else{
            int vl = query(a, b, 2*i+1, l, (l+r)/2);
            int vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

int main(){
    int N;
    cin >> N;
    ll e[N];
    e[0] = 1;
    rep2(i, 1, N-1) e[i] = (2*e[i-1])%MOD2;
    int x[N], y[N];
    vector<P> vecx, vecy, vec;
    rep(i, N){
        cin >> x[i] >> y[i];
        vecx.push_back(P(x[i], i));
        vecy.push_back(P(y[i], i));
    }
    sort(vecx.begin(), vecx.end());
    sort(vecy.begin(), vecy.end());
    rep(i, N){
        int px = vecx[i].second, py = vecy[i].second;
        x[px] = i, y[py] = i;
    }
    rep(i, N) vec.push_back(P(x[i], y[i]));
    sort(vec.begin(), vec.end());
    int X[N], Y[N];
    rep(i, N) X[i] = vec[i].first, Y[i] = vec[i].second;
    segment_tree segl(N), segr(N);
    ll n = segl.size();
    ll ul[N], ur[N], dl[N], dr[N];
    rep(i, N){
        dl[i] = segl.query(0, Y[i], 0, 0, n);
        ul[i] = i - dl[i];
        segl.update(Y[i], 1);
    }
    rep3(i, N-1, 0){
        dr[i] = segr.query(0, Y[i], 0, 0, n);
        ur[i] = N-1-i - dr[i]; 
        segr.update(Y[i], 1);
    }
    ll ans = (N*e[N-1])%MOD2;
    rep(i, N){
        ll a = (e[ul[i]]-1)*(e[dr[i]]-1) % MOD2;
        ll b = (e[ur[i]]-1)*(e[dl[i]]-1) % MOD2;
        ans += a * e[ur[i]+dl[i]];
        ans %= MOD2;
        ans += b * e[ul[i]+dr[i]];
        ans %= MOD2;
        ans += MOD2*MOD2 - a*b;
        ans %= MOD2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 28892
N = int(input())
XS = list(map(int, input().split()))

def hitpoint(n, xs):
    acc = 0
    for x in xs:
        r = (x - n) ** 2
        acc += r
    return acc

ans = hitpoint(1, XS)
tmp = ans
for i in range(2, 100):
    ans = hitpoint(i, XS)
    if ans >= tmp:
        break
    tmp = ans

print(tmp)

Measured memory_bytes: 38512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a == b)
                out.println(c);
            else if (a == c)
                out.println(b);
            else
                out.println(a);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufLength == -1)
                throw new InputMismatchException();
            if (bufPointer >= bufLength) {
                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();
            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) n;
        }

    }
}



Measured memory_bytes: 22740
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = [ord(a)-48 for a in args[1]]

    A = [abs(A[i]-A[i+1]) for i in range(n-1)]
    r = 2 if A.count(1) == 0 else 1

    ret = 0
    for i in range(n-1):
        ret += (A[i]//r)*(n-2 == (i | (n-2-i)))

    return str((ret % 2)*r)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 21452
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd

    n, m = map(int, readline().split())
    s = input()
    t = input()

    d = dict()
    l = (n * m) // gcd(n, m)
    ls = l // n
    lt = l // m

    for i in range(n):
        d[i*ls] = s[i]

    for i in range(m):
        if d.get(i*lt):
            if d[i*lt] != t[i]:
                return print(-1)

    print(l)

if __name__ == '__main__':
    main()


Measured memory_bytes: 92012
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;


int main(){
    ll n,h;cin>>n>>h;
    ll a[1+n],b[1+n];for(ll i=1;i<=n;i++)cin>>a[i]>>b[i];
    ll amax=0,maxi=0;
    for(ll i=1;i<=n;i++){
        if(a[i]>amax)amax=a[i],maxi=i;
        else if(a[i]==amax){
            if(b[i]<b[maxi]){
                amax=a[i],maxi=i;
            }
        }
    }
    ll bmax=b[maxi];
    ll c[n];
    for(ll i=1;i<=maxi-1;i++)c[i]=b[i];
    for(ll i=maxi;i<=n-1;i++)c[i]=b[i+1];
    sort(c+1,c+n);
    ll hit=0;
    ll i=n-1;
    while(h>0&&c[i]>=bmax&&i>=1){
        h-=c[i];
        hit++;
        i--;
    }
    if(h>0){
        h-=bmax;
        hit++;
    }
    
    if(h>0){
        for(ll j=i;j>=1;j--){
            if(c[j]>=amax){
                h-=c[j];
                hit++;
            }
            if(h<=0)break;
          /*  cout<<"c";*/
        }
    }
    if(h>0){
        hit+=((h-1)/amax)+1;
       /* cout<<"d";*/
    }
    cout<<hit<<endl;
    return 0;
}


Measured memory_bytes: 2560
n = gets.to_i
ab = (n-1).times.map{gets.split.map(&:to_i)}

max_path = 0
path = Array.new(n){Hash.new}
ab.each do |a, b|
  path[a - 1][b - 1] = -1
  path[b - 1][a - 1] = -1
  max_path = [max_path, path[a - 1].length, path[b - 1].length].max
end
puts max_path

# bfs
queue = [0]
until queue.empty? do
  from = queue.shift
  colors = {}
  path[from].each do |to, color|
    if color == -1
      queue << to
    else
      colors[color] = true
    end
  end

  c_i = 1
  path[from].each do |to, color|
    next unless color == -1
    t = c_i
    cnt_to = path[from].length
    t.upto(cnt_to) do |i|
      unless colors[i]
        path[from][to] = i
        path[to][from] = i
        colors[i] = true
        c_i += 1
        break
      else
        c_i += 1
      end
    end
  end
end

ab.each do |a, b|
  puts path[a - 1][b - 1]
end


Measured memory_bytes: 59068
use proconio::input;
use std::cmp::max;

fn main() {
    input! {
    n:usize,
    v:[i32;n],
    c:[i32;n],
    }
    let mut ans = 0;
    for i in 0..n {
        ans += max(0, v[i] - c[i]);
    }
    println!("{}", ans);
}

Measured memory_bytes: 2144
code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
# cython: cdivision=True
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/lazysegtree>" namespace "atcoder" nogil:
    cdef cppclass lazy_segtree[S, OP, E, F, mapping, composition, id]:
        lazy_segtree(vector[S] v)
        void set(int p, S x)
        S get(int p)
        S prod(int l, int r)
        S all_prod()
        void apply(int p, F f)
        void apply(int l, int r, F f)
        int max_right[G](int l)
        int min_left[G](int r)
cdef struct s_t:
    long v, s
ctypedef long f_t
cdef extern from *:
    ctypedef int op_t "myop"
    ctypedef int e_t "mye"
    ctypedef int m_t "mymapping"
    ctypedef int c_t "mycomposition"
    ctypedef int i_t "myid"
    ctypedef int g_t "myg"
    cdef s_t myop(s_t a, s_t b) nogil
    cdef s_t mye() nogil
    cdef s_t mymapping(f_t f, s_t x) nogil
    cdef f_t mycomposition(f_t f, f_t g) nogil
    cdef f_t myid() nogil
    cdef bool myg(s_t k) nogil
cdef s_t myop(s_t a, s_t b) nogil:
    cdef s_t c
    c.v = (a.v * b.s + b.v) % 998244353
    c.s = (a.s * b.s) % 998244353
    return c
cdef s_t mye() nogil:
    cdef s_t e
    e.v = 0
    e.s = 1
    return e
cdef f_t myid() nogil:
    return -1
cdef s_t mymapping(f_t f, s_t x) nogil:
    if f == myid(): return x
    cdef s_t y
    y.v = (x.s - 1) * 443664157 * f % 998244353
    y.s = x.s
    return y
cdef f_t mycomposition(f_t f, f_t g) nogil:
    if f == myid(): return g
    return f
from libc.stdio cimport getchar, printf
cdef inline long read() nogil:
    cdef long b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: return c
        c = c * 10 + b
cdef main():
    cdef long n = read(), i, l, r, d
    cdef s_t a
    a.v = 1
    a.s = 10
    cdef lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t] *seg = new lazy_segtree[s_t, op_t, e_t, f_t, m_t, c_t, i_t](vector[s_t](n, a))
    for i in range(read()):
        l, r, d = read(), read(), read()
        seg.apply(l - 1, r, d)
        printf('%ld\n', seg.all_prod().v)
main()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

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

int main(){
  int N, A[100], minj, cnt=0;
  cin >> N;
  for ( int i = 0; i < N; i++) cin >> A[i];
  for ( int i = 0; i < N; i++) {
    minj = i;
    for ( int j = i; j < N; j++)
      if ( A[j] < A[minj] ) minj = j;
    if ( i != minj ) {
      cnt++;
      swap(A[i], A[minj]);
    }
  }
  for ( int i = 0; i < N; i++) {
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;
  return 0;
}


/*
int selectionSort(int A[], int N) {
  int minj = 0;
  int sw = 0;
  for ( int i = 0; i < N; i++ ) {
    minj = i;
    for ( int j = i; i < N; j++ ) {
      if ( A[j] < A[minj] ) {
        minj = j;
      }
    }
    if ( i != minj ) {
      swap(A[i], A[minj]);
      // int tmp = A[i];
      // A[i] = A[minj];
      // A[minj] = tmp;
      sw++;
    }
  }
  cout << sw << endl;
  return sw;
}


int main() {
  int N, sw;
  cin >> N;
  // scanf("%d", &N);
  int A[N];
  for ( int i = 0; i < N; i++ ) cin >> A[i];

  sw = selectionSort(A, N);

  for ( int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}
*/



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

struct account{
    int id;
    int t;
    double r;
};

double calc(int y, int t, double r){
    if( t == 1 ){
        return 10000.0*(1+y*(r/100));
    }else{
        return 10000.0 * pow(1 + r/100, y);
    }
}

int main(){
    int n;
    while(cin >> n, n){
        int y;
        cin >> y;
        vector< account > bank(n);
        for(int i = 0; i < n;i++){
            cin >> bank[i].id >> bank[i].r >> bank[i].t;
        }
        int id, m_i = 0;
        for(int i = 0; i < n; i++){
            double interest = calc(y, bank[i].t, bank[i].r);
            if( interest > m_i ){
                m_i = interest;
                id = bank[i].id;
            }
        }
        cout << id << endl;
    }
    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
using namespace std;
int main() {
	int n, x;
	cin >> n >> x;
	int l[105];
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int count = 1;
	int sum = 0;
	for (int j = 0; j < n; j++) {
		sum = sum + l[j];
		if (sum <= x) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	ll x, y; cin >> x >> y;
	ll n = y / x;
	ll ans = 1;
	while(n / 2){
		ans += 1; n /= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<algorithm>
#include<numeric>
#include<iomanip>
using namespace std;

int main(){

	int N, K;
	cin >> N >> K;

	deque<double> exp_of_dice;
	double sum = 0;
	double  sum_max = 0;
	double p = 0;

	for(int i=0; i<K; ++i){
		cin >> p;
		exp_of_dice.push_back( (1./2.)*(p+1.));
		//cout << float( (1./2.)*(p+1.) ) << endl;
		sum += exp_of_dice[i];
	}

	sum_max = sum;
	//cout << sum_max << endl;

	for(int i=K; i<N; ++i){
		cin >> p;
		p = (1./2.)*(p+1.);
		sum += (p - exp_of_dice[0]);
		exp_of_dice.pop_front();
		exp_of_dice.push_back(p);
		if (sum > sum_max){
			sum_max = sum;
		}
		//cout << "i=" << i << ' ' << sum << ' ' << sum_max << endl;
	}

	//cout << 'a' << endl;
	cout << fixed << setprecision(9) << sum_max << endl;

	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* 多次元デック */template<class T>deque<T> mdeq(size_t a){return deque<T>(a);}template<class T, class... Ts>auto mdeq(size_t a, Ts... ts){return deque<decltype(mdeq<T>(ts...))>(a, mdeq<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N, K;
  cin >> N >> K;
  auto u0 = mdeq<ll>(0);
  auto b0 = mdeq<ll>(0);
  b0.push_back(0);
  rep(i, 0, N){
    ll x;
    cin >> x;
    if(x < 0) u0.push_front(-x);
    else b0.push_back(x);
  }
  u0.push_front(0);
  ll ans{MOD};
  rep(i, 0, K+1){
    if((i >= b0.size()) || ((K - i) >= u0.size())) continue;
    ans = min({ans, 2*b0[i] + u0[K - i], b0[i] + 2*u0[K - i]});
  }
  cout << ans << rt;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <x86intrin.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

signed main() {

    int L;
    cin >> L;
    vector<pair<pair<int, int>, int> > p;
    int mx = 64 - __builtin_clzll(L) - 1;

    //最大以外の各桁について0, 1の辺を張る
    rep(i, 19) {
        p.push_back({ { i, i + 1 }, 0 });
    }
    rep(i, mx) {
        p.push_back({ {i, i + 1}, 1 << (mx - i - 1) });
    }
    RREP(i, mx) {
        int v = mx - i - 1;
        if (L & 1 << i) {
            p.push_back({ { 0, v + 1 } , ((L >> (i + 1))) << (i + 1) });
        }
    }
    cout << 20 << ' ' << p.size() << endl;
    //最大桁は最初のノードから生える辺で立てる、最大桁が立っている場合はそれ以外のけたでL未満であることが確定する必要がある
    for (auto pa : p) {
        cout << pa.first.first + 1 << " " << pa.first.second + 1 << " " << pa.second << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N + 1)]
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i][j], dp[i - 1][k] + abc[i - 1][j])
print(max(dp[-1]))

Measured memory_bytes: 50092
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, Ma, Mb = map(int, input().split())
    items = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        items.append((a, b, c))

    dp = [[INF] * 401 for _ in range(401)]
    dp[0][0] = 0
    for i in range(N):
        a, b, c = items[i]
        for y in range(len(dp) - 1, -1, -1):
            for x in range(len(dp[0]) - 1, -1, -1):
                if dp[y][x] != INF:
                    dp[y + a][x + b] = min(dp[y + a][x + b], dp[y][x] + c)

    ans = INF
    for y in range(1, len(dp)):
        for x in range(1, len(dp[0])):
            if y * Mb == x * Ma:
                ans = min(ans, dp[y][x])

    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

vector<vl> anslist;

void DP(int p, int d) {
	ll pmod = p % 12;
	ll n = 1;
	rep(i, pmod) {
		n *= 10;
	}
	n *= d;
	n %= 13;
	rep(d_from, 13) {
		int d_to = (d_from + n) % 13;
		anslist[p + 1][d_to] += anslist[p][d_from];
		anslist[p + 1][d_to] %= mod;
	}
	return;
}

int main() {
	string S;
	cin >> S;
	int N = S.length();
	anslist.resize(N + 1);
	rep(i, N + 1) {
		vl anslist_ini(13, 0);
		anslist[i] = anslist_ini;
	}
	anslist[0][0] = 1;
	int p = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '?') {
			rep(d, 10) { // n = d*10^p (mod 13)
				DP(p, d);
			}
		}
		else {
			int d = (int)S[i];
			d -= 48;
			DP(p, d);
		}
		p++;
	}
	ll ans = anslist[N][5] % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13696
# ABC 152 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
snm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
p=nl()
s=[]
ans=0
min_v=10**6
for i in range(n):
    if i==0:
        ans+=1
        s.append(p[i])
        min_v=min(min_v,p[i])
        continue
    if p[i]<=min_v:
        ans+=1
    s.append(p[i])
    min_v=min(min_v,p[i])
print(ans)

Measured memory_bytes: 25348
#include <cstdio>
using namespace std;

int Euc(int a, int b){
	int c;
	while(a % b != 0){
		c = b;
		b = a % b;
		a = c;
	}
	
	return b;
}

int main(){
	int a, b;
	int gcd, lcm;
	int sub;
	
	while((scanf("%d", &a)) != EOF){
		scanf("%d", &b);
		
		if(a < b){
			sub = a;
			a = b;
			b = sub;
		}
		
		gcd = Euc(a, b);
		lcm = (a / gcd) * b;
		
		printf("%d %d\n", gcd, lcm);
	}
	
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    um M;
    for(auto p: A)M[p]++;
    if(M.size()==N)prt("YES");
    else prt("NO");

    return 0;
}



Measured memory_bytes: 12940
#include <stdio.h>
char a[20];
int k;
int g;
int main() {
	for (int i = 0; i < 20; i++)a[i] = 'A';
	scanf("%s", a);
	for (int i = 0; i < 20; i++)if (a[i] != 'A')k++;
	for (int i = 0; i < k; i++)if (a[i] == 'x')g++;
	if (g < 8)printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

    sc.Split(bufio.ScanWords)
    n, k := nextInt(), nextInt()

    var h []int

    for i := 0; i < n; i++ {
        h = append(h, nextInt())
    }

    sortIntsRev(h)

    if k >= n {
        fmt.Println(0)
        os.Exit(0)
    }

    attack := 0
    for i := k; i < n; i++ {
        attack += h[i]
    }

    fmt.Println(attack)

}



//===========================
//
// Library
//
//===========================

//===========================
//  round(12.54, 0) -> 13.0
//  round(12.54, -1) -> 12.5
//===========================

func round(num float64, digit uint) float64 {
    d := float64(digit)
    return float64(int(num * math.Pow(10, d) + 0.5)) / math.Pow(10, d)
}

func max(a, b int) int {
    return int(math.Max(float64(a), float64(b)));
}

func min(a, b int) int {
    return int(math.Min(float64(a), float64(b)));
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//===========================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//===========================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

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



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

int mass[252];

int m,n;

int table[252][252];

int main() {

    while(1){

        cin >> m;

        if(m==0) break;

        cin >> n;

        mass[0] = 0;
        mass[n+1] = 500;

        for(int i=1;i<=n;i++){
            cin >> mass[i];
        }

        for(int i=0;i<=n+1;i++){
            for(int j=0;j<=n+1;j++){
                table[i][j] = -1;
            }
        }

        for(int i=0;i<n+1;i++){
            for(int j=1;j<=m;j++){
                int next = i+j+mass[i+j];
                if(next<0) next = 0;
                if(next>n+1) next = n+1;
                table[i][next] = 1;
                //vec[i].push_back(next);
            }
        }

        for(int k=0;k<n+2;k++){
            for(int i=0;i<n+2;i++){
                for(int j=0;j<n+2;j++){
                    if(table[i][k] != -1 && table[k][j] != -1)
                    table[i][j] = 1;
                }
            }
        }

        bool flag = true;

        for(int i=0;i<=n;i++){
            if(table[0][i]!=-1 && table[i][n+1] == -1){
                flag = false;
                break;
            }
        }

        if(flag){
            cout << "OK" << endl;
        }
        else{
            cout << "NG" << endl;
        }



    }


    return 0;
}

Measured memory_bytes: 3240
from collections import deque
n = int(input())

Map = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    Map[a-1].append(b-1)
    Map[b-1].append(a-1)
INF = float('inf')
def distance(st):
    d = [INF for i in range(n)]
    d[st] = 0
    q = deque()
    q.append(st)
    while q:
        index = q.pop()
        for nexts in Map[index]:
            if d[nexts] == INF:
                d[nexts] = d[index]+1
                q.append(nexts)
    return d
d1 = distance(0)
d2 = distance(n-1)

fen = 0
snu = 0
for i in range(n):
    if d1[i]<= d2[i]:
        fen += 1
    else:
        snu += 1

if fen>snu:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 29500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> jamp(n);
    rep(i,n) cin >> jamp[i];
    bool flag1 = false, flag2 = false;

    int now = n - 1;
    for(int i = n-2; i >= 0; i--) {
        if(jamp[i]/10>=now-i) {
            now = i;
        }
    }
    if(now==0) flag1 = true;

    reverse(ALL(jamp));
    now = n - 1;
    for(int i = n-2; i >= 0; i--) {
        if(jamp[i]/10>=now-i) {
            now = i;
        }
    }
    if(now==0) flag2 = true;

    if(flag1 && flag2) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}


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

int main(){

    int X, N;
    cin >> X >> N;
    if(N == 0){
        cout << X << endl;
        return 0;
    }

    int P[N];
    int pi;
    int i;
    for(i=0; i<N; i++){
        cin >> pi;
        P[i] = pi;
    }

    bool flag;
    flag = false;
    for (i=0; i<N; i++){
        if(P[i] == X){
            flag = true;
            break;
        }
    }
    if(flag == false){
        cout << X << endl;
        return 0;
    }


    int abs_num_p, abs_num_n;
    abs_num_p = X + 1;
    abs_num_n = X - 1;

    //int iter;
    bool flag_p;
    bool flag_n;
    //iter = 0;
    
    while(true){
        flag_p = false;
        flag_n = false;
        for (i=0; i<N; i++){
            if(P[i] == abs_num_p){
                flag_p = true;
            }
            if(P[i] == abs_num_n){
                flag_n = true;
            }
        }
        if((     flag_p ==  true) && (flag_n ==  true)){
            abs_num_p += 1;
            abs_num_n -= 1;
            continue;
        }
        else if((flag_p ==  true) && (flag_n == false)){
            cout << abs_num_n << endl;
            return 0;
        }
        else if((flag_p == false) && (flag_n ==  true)){
            cout << abs_num_p << endl;
            return 0;
        }
        else if((flag_p == false) && (flag_n == false)){
            cout << abs_num_n << endl;
            return 0;
        }
    }
    return 0;
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
 
Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    vector<Int> dp(n, INF);
    for (Int i = 0; i < n; i++) {
        *upper_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    dump(lower_bound(dp.begin(), dp.end(), INF) - dp.begin());
    return 0;
}

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

int main(){
    int n,ans = 0,y=0,z=0,x=0;
    cin >> n;
    for(int i = 0;i < n;i ++){
        string s;
        cin >> s;
        for(int i = 0;i < s.size()-1;i ++){
            if(s.substr(i,2)=="AB") ans ++;
        }
        if(s[0]=='B'&&s.back()=='A') x ++;
        else if(s[0]=='B') z ++;
        else if(s.back()=='A') y ++;
    }
    if(y){
        ans += y*(x/y);
        x %= y;

        ans += x;
        x = 0;
    }else if(z){
        ans += z*(x/z);
        x %= z;

        ans += x;
        x = 0;
    }else{
        ans += max(0,x-1);
    }

    
    ans += min(y,z);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class queue:
    val = []
    def __init__(self,arr):
        self.val = arr

    def push_queue(self,el):
        self.val.append(el)

    def pop_queue(self):
        return self.val.pop(0)



n,q = map(int,input().split())
process = [input().split() for a in range(n)]
for a in process:
    a[1] = int(a[1])

queued_process = queue(process)

time_count = 0
while True:
    if queued_process.val[0][1] > q:
        time_count += q
        queued_process.val[0][1] -= q
        queued_process.push_queue(queued_process.pop_queue())
    else:
        time_count += queued_process.val[0][1]
        queued_process.val[0][1] = 0
        print(f'{queued_process.val[0][0]} {time_count}')
        queued_process.pop_queue()
    if queued_process.val == []:
        break






Measured memory_bytes: 16872
def mcomb(n, k):
    a = 1
    b = 1
    for i in range(k):
        a *= n - i
        a %= 1000000007
        b *= i + 1
        b %= 1000000007
    return a * pow(b, 1000000005, 1000000007) % 1000000007


n, a, b = map(int, input().split())

result = pow(2, n, 1000000007) - 1
result -= mcomb(n, a)
result + 1000000007
result %= 1000000007
result -= mcomb(n, b)
result + 1000000007
result %= 1000000007
print(result)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll, lint;
typedef long double ldouble;

#define sz(v) ((int) (v).size())
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define For(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

template<class T>
string to_string(T arr, int len = 1e9) {
    stringstream ss;
    int i = 0;
    for (auto item : arr) {
        ss << item << ' ';
        if (++i == len)
            break;
    }
    return ss.str();
}

#ifdef LOCAL
    #define dbg(expr) cout << "[line " << __LINE__ << "] " << (#expr) << ": " << (expr) << endl;
#else
    #define dbg(expr) (void) 0;
#endif


int main() {
#ifndef LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(false);
#endif

    lint n, a, b;
    cin >> n >> a >> b;
    if (abs(b - a) % 2 == 1)
        cout << "Borys" << endl;
    else
        cout << "Alice" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <bits/stdc++.h>
#include <complex.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;

int main()
{
  int a;
   cin>>a;
   a+=a*a+a*a*a;
   cout<<a<<endl;
}


Measured memory_bytes: 3632
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int a, b, k;
set<int>ans;

int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b >> k;
    ans.clear();
    
    forr(i,0,k){
        if(a+i >= a && a+i <= b)ans.insert(a+i);
        if(b-i >= a && b-i <= b)ans.insert(b-i);
    }

    for(set<int>::iterator it = ans.begin(); it != ans.end(); it++){
        cout << *it << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
MAX_N = 44
dp = [None] * (MAX_N + 1)
dp[0] = 1
dp[1] = 1

def fib(n):
    for i in range(2, n+1):
        dp[i] = dp[i-1] + dp[i-2]
    
    return dp[n]

n = int(input())
print(fib(n))



Measured memory_bytes: 5600
let rec range l r =
    if l > r then []
    else l :: range (l + 1) r

let solve k x =
    let left = max (-1000000) (x - k + 1) in
    let right = min 1000000 (x + k - 1) in
    range left right

let () =
    Scanf.scanf "%d %d\n" @@ fun k x ->
    Printf.printf "%s\n" @@ String.concat " " (List.map string_of_int @@ solve k x)


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
void solve() {
        int len;
        cin >> len;
        string str;
        cin >> str;
        vector <char> v;
        for(int i=0;i<len-1;i++) {
                if(str[i] == str[i+1])
                        continue;
                v.push_back(str[i]);
        }
        cout << v.size()+1 << '\n';
        return ;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}


Measured memory_bytes: 592
import java.util.ArrayDeque

data class Edge<T>(val to: Int, var cost: T)

fun main(args: Array<String>) {
    val (n, q) = readIntegerList()
    val neighborList = Array(n) { mutableListOf<Edge<Int>>() }
    repeat(n - 1) {
        val (a, b) = readIntegerList()
        neighborList[a - 1].add(Edge(b - 1, 0))
        neighborList[b - 1].add(Edge(a - 1, 0))
    }

    val counter = Array(n) { 0 }
    repeat(q) {
        val (p, x) = readIntegerList()
        counter[p - 1] += x
    }

    val queue = ArrayDeque<Int>()
    val isChecked = BooleanArray(n) { false }
    queue.addLast(0)
    while (queue.isNotEmpty()) {
        val current = queue.removeFirst()
        for (edge in neighborList[current]) {
            if (isChecked[edge.to] == false) {
                counter[edge.to] += counter[current]
                queue.addLast(edge.to)
            }
        }

        isChecked[current] = true
    }

    println(counter.joinToString(" "))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 155824
import java.util.Scanner;

//Search of Concatenated Strings
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		byte[][] e = new byte[5000][1<<12];
		boolean[][] f = new boolean[5000][12];
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			String[] s = new String[n];
			for(int i=0;i<n;i++)s[i]=sc.next();
			StringBuilder sb = new StringBuilder();
			while(m--!=0)sb.append(sc.next());
			String t = sb.toString();
			int N = t.length();
			for(int i=0;i<N;i++)for(int j=0;j<1<<n;j++)e[i][j]=0;
			for(int i=1;i<=N;i++){
				String sub = t.substring(0, i);
				for(int j=0;j<n;j++){
					f[i-1][j]=sub.endsWith(s[j]);
					if(f[i-1][j])e[i-1][1<<j]=1;
				}
			}
			int res = 0;
			for(int i=0;i<N;i++)for(int S=0;S<1<<n;S++){
				if(e[i][S]==0)continue;
				if(S==(1<<n)-1)res++;
				for(int j=0;j<n;j++)if(((S>>j)&1)==0){
					if(i+s[j].length()<N&&f[i+s[j].length()][j])e[i+s[j].length()][S|(1<<j)]=1;
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 33000
# -*- coding: utf-8 -*-


def main(n):
    lst = [1, 1]
    for i in range(2, n + 1):
        lst.append(lst[i - 1] + lst[i - 2])
    return lst[n]


if __name__ == '__main__':
    n = int(input())
    print(main(n))

Measured memory_bytes: 7560
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<pair<pair<int,int>,bool>> vpr;
    vector<pair<int,int>> vpb;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        vpr.push_back(make_pair(make_pair(y,x),false));
    }
    sort(vpr.begin(),vpr.end());
    reverse(vpr.begin(),vpr.end());
    rep(i,n){
        swap(vpr[i].first.first,vpr[i].first.second);
    }
    rep(i,n){
        int x,y;
        cin >> x >> y;
        vpb.push_back(make_pair(x,y));
    }
    sort(vpb.begin(),vpb.end());
    int cnt = 0;
    for(int i=0;i<n;i++){
        auto b = vpb[i];
        for(int j=0;j<n;j++){
            auto r = vpr[j];
            if((b.first > r.first.first) && (b.second > r.first.second) && (vpr[j].second==0)){
                cnt++;
                vpr[j].second = 1;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())
menu = []
for i in range(0, M):
	menu.append(0)
for i in range(0, N):
	answer = map(int, raw_input().split())
	for j in range(1, answer[0]+1):
		menu[answer[j]-1] += 1
cnt = 0
for i in range(0, M):
	if menu[i] == N: cnt += 1

print cnt

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

int main(){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  vector<int> DP(F+1,-1);
  DP[0] = 0;
  for(int i = 0; i <= F-100*A; ++i){
    if(DP[i] < 0) continue;
    DP[i+100*A] = DP[i];
  }
  for(int i = 0; i <= F-100*B; ++i){
    if(DP[i] < 0) continue;
    DP[i+100*B] = DP[i];
  }
  for(int i = 0; i <= F-C; ++i){
    if(DP[i] < 0) continue;
    if((i-DP[i])/100*E < C+DP[i]) continue;
    DP[i+C] = DP[i] + C;
  }
  for(int i = 0; i <= F-D; ++i){
    if(DP[i] < 0) continue;
    if((i-DP[i])/100*E < D+DP[i]) continue;
    DP[i+D] = DP[i] + D;
  }
  int sug = 0, sol = 100*A;
  for(int i = 0; i <= F; ++i){
    if(DP[i] <= 0) continue;
    if((double)DP[i]*100/i > (double)sug*100/sol){
      sug = DP[i];
      sol = i;
    }
  }
  cout << sol << " " << sug << endl;
  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n+2,0);
  int d = 0;
  rep(i,n) {
    cin >> a[i+1];
    d += abs(a[i+1] - a[i]);
  }
  d += abs(a[n+1] - a[n]);
  for (int i = 1; i<n+1; i++) {
    int r = abs(a[i] - a[i+1]) + abs(a[i] - a[i-1]);
    cout << d + abs(a[i+1] - a[i-1]) - r << endl;
  }
  return 0;
}

Measured memory_bytes: 3744
n=int(input())
li=list(map(int,input().split()))

flag=True
new=[]
new.append(li[0])

for i in range(1,len(li)):
  #new.apend(li[i])
  if li[i]>=li[i-1] :
    pass
  else :
    flag=False
    break
"""
if flag :
  print("Yes")
else :
  #if li[0]!=1 :
   # li[0]=li[0]-1
  for i in range(0,len(li)-1):
    if li[i] ==li[i+1]+1 :
      li[i]=li[i]-1
    elif li[i]<=li[i+1] :
      pass
    else:
      flag=False
      break
""" 
if flag :
  print("Yes")
else:
  for i in range(n-1,0,-1):
    if li[i-1]>li[i] :
      li[i-1] -= 1
    
 
  flag=True
  for i in range(1,len(li)):
  #new.apend(li[i])
    if li[i]>=li[i-1] :
      pass
    else :
      flag=False
      break
  if flag :
    print("Yes")
  else :
    print("No")
  



Measured memory_bytes: 15964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read(){
	ll x=0,sign=1;char s=getchar();
	while(!isdigit(s)){if(s=='-')sign=-1;s=getchar();}
	while(isdigit(s))x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return x*sign;
}
double n,v[55];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>v[i];
	sort(v+1,v+(int)n+1);
	for(int i=2;i<=n;i++)
		v[i]=(v[i-1]+v[i])/2;
	printf("%.9lf",v[(int)n]);
	return 0;
}


Measured memory_bytes: 256