akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "3 3 2", "1 2", "5 4", "9 2" ].parse.expand.solve == 2 );
	assert( [ "9 4 1", "1 5", "2 4", "3 3", "4 2", "5 1", "6 2", "7 3", "8 4", "9 5" ].parse.expand.solve == 5 );
	assert( [ "3 0 1", "300000000 1000000000", "100000000 1000000000", "200000000 1000000000" ].parse.expand.solve == 3000000000 );
	
	assert( [ "9 2 2", "1 3", "2 4", "3 3", "4 2", "5 5", "6 2", "7 3", "8 4", "9 5" ].parse.expand.solve == 5 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nda = input.front.split.to!( long[] );
	auto xhs = new long[ 2 ][ nda[ 0 ] ];
	foreach( ref xh; xhs )
	{
		input.popFront;
		xh = input.front.split.to!( long[] );
	}
	return tuple( nda[ 1 ], nda[ 2 ], xhs );
}

auto solve( long d, long a, long[ 2 ][] xhs )
{
	xhs.sort();
	
	auto ans = 0L;
	auto bs = new long[ xhs.length + 1 ];
	auto bt = 0L;
	for( auto li = 0L, ri = 1L; li < xhs.length; /* nop */ )
	{
		// 爆弾を使う座標を計算
		auto cx = xhs[ li ][ 0 ] + d;
		
		// 爆弾の範囲右端の一つ外を検索
		while( ri < xhs.length && xhs[ ri ][ 0 ] <= cx + d ) ri++;
		
		// 左端のモンスターを倒せる分だけ爆弾を使う
		auto b = ( ( xhs[ li ][ 1 ] - a * bt ) + ( a - 1 ) ) / a;
		bs[ li ] += b;
		bs[ ri ] -= b;
		bt += b;
		ans += b;
		
		// 次の範囲の左端を検索
		while( li < xhs.length && xhs[ li ][ 1 ] <= a * bt )
		{
			li++;
			bt += bs[ li ];
		}
	}
	return ans;
}


Measured memory_bytes: 8828
# coding: utf-8

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

X_dif = sorted([X[i + 1] - X[i] for i in range(M - 1)], reverse=True)
X_dif = X_dif[N - 1:]

print(sum(X_dif))



Measured memory_bytes: 13188
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

int main()
{
	long long x,y;
	cin>>x>>y;
	long long count=0;
	while(x<=y)
	{
		x*=2;
		count++;
	}
	printf("%lld\n",count);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B, C;
	cin >> A >> B >> C;

	cout << max(C - (A - B), 0);

	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
void solve(int a){cout<<( a?"YES":"NO")<<endl;}
int main(){
	int a,b,c;
	cin >>a>>b>>c;
	solve(b-a==c-b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int A,P;
  cin >> A >> P;
  cout << (A*3+P)/2 << endl;
  return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		int res=0;
		rep(i,n) res+=__builtin_ctz(a[i]);
		cout<<res<<endl;
	}
}


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

using namespace std;
#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e6+10;

ll fa[maxn],s;
void getf(ll x)
{
    for(int i=2; i<=sqrt(x+0.5); i++)
    {
        if(x%i==0)
        {
            if(x%i==i)
                fa[s++]=i;
            else
            {
                fa[s++]=i;
                fa[s++]=x/i;
            }
        }
    }
    if(x!=1)
        fa[s++]=x;
}
int main()
{
    ll n;
    sll(n);
    set<ll>st;
    for(ll i=2; i<sqrt(n+0.5); i++)
    {
        ll k=n;
        if(n%i==0)
        {
            ll x=i;
            while(k%x==0)
                k/=x;
            if(k%x==1)
                st.insert(x);
        }
    }
    n--;
    for(ll i=2; i<sqrt(n+0.5); i++)
    {
        if(n%i==0)
        {
            st.insert(i);
            st.insert(n/i);
        }
    }
    st.insert(n);
    st.insert(n+1);
    if(n==1)
        cout<<1<<endl;
    else
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    S = input()

    c = 0
    ans = 0

    for s in S:
        if s == "I":
            c += 1
            ans = max(ans, c)
        else:
            c -= 1

    print(ans)


main()


Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,ans,sum,temp,n,a,h,x;
    double dans,asum,diff,y,min=100000.00;
    vector<int>v1;
    vector<double>v2,v3;
    cin>>n>>h>>a;
    for(i=0;i<n;i++)
    {
        cin>>x;
        v1.push_back(x);
    }
    for(i=0;i<n;i++)
    {
        diff=(h-v1[i]*0.006);
        v2.push_back(diff);
    }
    for(i=0;i<v2.size();i++)
    {
        diff=abs(v2[i]-a);
        v3.push_back(diff);
    }
    for(i=0;i<v3.size();i++)
    {
        if(v3[i]<min)
        {
            min=v3[i];
        }
    }
    for(i=0;i<v3.size();i++)
    {
        if(min==v3[i])
        {
            break;
        }
    }
    cout<<i+1<<endl;
}

Measured memory_bytes: 256
while arr = gets
  arr = arr.split(",").map(&:to_i)
  len = arr[0..9].inject{|sum,i|sum + i}.to_f * arr[10] / (arr[10] + arr[11])
  i = 0
  while len > 0
    len -= arr[i]
    i += 1
  end
  puts i
end

Measured memory_bytes: 6112
#include <stdio.h>
int main(void)
{
    int n, i, j;
    int v[100];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &v[i]);
    int w[100];
    for (j = 0; j < n; j++)
    {
        w[j] = v[n - j - 1];
    }
    for (j = 0; j < n - 1; j++)
    {
        printf("%d ", w[j]);
    }
    printf("%d\n", w[j]);
    return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

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 INF = 1LL << 60;

signed 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<int>> dp(n + 1, vector<int>(W + 1, 0));
	for(int i = 1; i < n + 1; i++) {
		for(int j = 0; j < W + 1; j++) {
			chmax(dp[i][j], dp[i - 1][j]);
			if(j + w[i - 1] <= W) chmax(dp[i][j + w[i - 1]], dp[i - 1][j] + v[i - 1]);
		}
	}

	cout << dp[n][W] << endl;
	
	return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long lli;
typedef pair<lli,lli> P;

lli A, B, D;

bool compare(const P &a, const P &b) {
  if(a.first+a.second != b.first+b.second)
    return a.first+a.second < b.first+b.second;
  return A*a.first+B*a.second < A*b.first+B*b.second;
}

int main() {
  while(cin >> A >> B >> D && (A|B|D)) {
    P res(10000000, 10000000);
    for(lli x = -1000000; x <= 1000000; ++x) {
      lli tmp = D - A*x;
      if(tmp % B != 0) continue;
      lli y = tmp / B;
      res = min(res, P(labs(x), labs(y)), compare);
    }
    cout << res.first << " " << res.second << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K, Q) = (input[0], input[1], input[2])
var cnt = (0..<N).flatMap{_ in [0]}
for _ in 0..<Q {
  cnt[Int(readLine()!)!-1] += 1
}
cnt.forEach{print($0>Q-K ?"Yes":"No")}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
#define pb push_back 
#define ll long long
using namespace std;
int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n,d;
	cin>>n>>d;
	ll mod = n%(2*d + 1);
	if( mod == 0) cout<<n/(2*d+1);
	else cout<<(n/(2*d+1))+1;
	cout<<endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  vi32 f(501, 1);
  int x, n;
  cin >> x >> n;
  x += 200;
  rep(i, n) {
    int p;
    cin >> p;
    p += 200;
    f[p] = 0;
  }
  int mi = INF;
  int ans = -1;
  repc(i, 500) if (f[i]) {
    if (mi > abs(i - x)) {
      mi = abs(i - x);
      ans = i - 200;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3664
var
	N,i,j,ans:int64;
begin
	read(N);
	i:=1;
	while i<=N do begin
		j:=N div(N div i)+1;
		inc(ans,(j-i)*(i+j-1)*(N div i)*(N div i+1)div 4);
		i:=j;
	end;
	writeln(ans);
end.

Measured memory_bytes: 1320
import java.io.*;
class Main{
    public static void main(String[] args) throws IOException {
        int i;
        int[] n = new int[5];
        String[] str = new String[5];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<3;i++)
            n[i] = Integer.parseInt(str[i]);
        System.out.println((n[0]<n[1] && n[1]<n[2]) ? "Yes" : "No");
    }
}

Measured memory_bytes: 24348
#include <stdio.h>
#include <iostream>
using namespace std;
const int N=100001;
int a[N];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    int m=a[0]+a[1];
    for(int i=2;i<N;i++)
    {
        int t=a[i-2]+a[i-1]+a[i];
        if(t>m)
         {m=t;}
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 640
(function main() {
  var n = Number(require('fs').readFileSync('/dev/stdin', 'utf8'));
  var cache = [1, 1];
  var fib = (n) => cache[n] || (cache[n] = fib(n - 1) + fib(n - 2));
  console.log(fib(n));
})();



Measured memory_bytes: 15128
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

int N; 

int parse(in string s) {
    int[char] M = [
        'm': 1000,
        'c': 100,
        'x': 10,
        'i': 1
    ];
    int ret = 0;
    int p = 1;
    foreach (c; s) {
        if (isDigit(c)) {
            p = cast(int)(c - '0');
        } else {
            ret += p * M[c];
            p = 1;
        }
    }
    return ret;
}

string to_s(int n) {
    int[] x = [0, 0, 0, 0];
    x[0] = n / 1000; n %= 1000;
    x[1] = n / 100;  n %= 100;
    x[2] = n / 10;   n %= 10;
    x[3] = n;

    string p = "mcxi";

    string ret;
    foreach (i; 0 .. 4) {
        if (x[i] == 0) {
            // do nothing
        } else if (x[i] == 1) {
            ret ~= p[i];
        } else {
            ret ~= format("%d%s", x[i], p[i]);
        }
    }
    return ret;
}

void solve() {
    string s, t; readf("%s %s\n", &s, &t);
    //writeln([parse(s), parse(t)]);
    //writeln((parse(s) + parse(t)));
    writeln(to_s(parse(s) + parse(t)));
}

void main() {
    scanf("%d\n", &N);
    foreach (i; 0 .. N) {
        solve();
    }
}

Measured memory_bytes: 2040
#include <iostream>


using namespace std;

const int INF = 1000000001;
const int MAX = 500000;
int cnt,N;
int S[MAX] = {0}, L[1 + MAX/2] = {0}, R[1 + MAX/2] = {0};


void merge(int* A,int left,int mid,int right)
{
	int n1,n2,i,j;
	n1 = mid - left;
	n2 = right - mid;

	for(int i = 0; i < n1; i++)
	{
		L[i] = A[left + i];
	}
	for(int i = 0; i < n2; i++)
	{
		R[i] = A[mid + i];
	}

	L[n1] = INF;
	R[n2] = INF;

	i = 0;
	j = 0;

	for(int k = 0; k < right - left; k++)
	{
		if (L[i] <= R[j] )
		{
			A[left + k] = L[i];
			i++;
		}else
		{
			A[left + k] = R[j];
			j++;
		}

		cnt++;
	}
}


void mergesort(int* A,int left,int right)
{
	int mid;

	if(left + 1 < right)
	{
		mid = (left + right) / 2;
		mergesort(A,left,mid);
		mergesort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main()
{
	cnt = 0;

	cin >> N;

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

	mergesort(S,0,N);

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

	cout << cnt << endl;

	return 0;
}
	

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

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

    vector<long> a(3*n);
    for (int i = 0; i < 3*n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());

    long ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += a.at(2*i + 1);  
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  cin>>S;
  bool CAN=true;
  
  int s[30];
  for(int i=0; i<30; ++i) s[i]=0;
  for(int i=0; i<S.size(); ++i){
    if(S.at(i)=='A' && i==0) s[27]+=1;
    else if(S.at(i)=='C' && i>=2 && i<=S.size()-2) s[28]+=1;
    
    else if(S.at(i)=='q') s[1]+=1;
    else if(S.at(i)=='w') s[2]+=1;
    else if(S.at(i)=='e') s[3]+=1;
    else if(S.at(i)=='r') s[4]+=1;
    else if(S.at(i)=='t') s[5]+=1;
    
    else if(S.at(i)=='y') s[6]+=1;
    else if(S.at(i)=='u') s[7]+=1;
    else if(S.at(i)=='i') s[8]+=1;
    else if(S.at(i)=='o') s[9]+=1;
    else if(S.at(i)=='p') s[10]+=1;
    
    else if(S.at(i)=='a') s[11]+=1;
    else if(S.at(i)=='s') s[12]+=1;
    else if(S.at(i)=='d') s[13]+=1;
    else if(S.at(i)=='f') s[14]+=1;
    else if(S.at(i)=='g') s[15]+=1;
    
    else if(S.at(i)=='h') s[16]+=1;
    else if(S.at(i)=='j') s[17]+=1;
    else if(S.at(i)=='k') s[18]+=1;
    else if(S.at(i)=='l') s[19]+=1;
    else if(S.at(i)=='z') s[20]+=1;
    
    else if(S.at(i)=='x') s[21]+=1;
    else if(S.at(i)=='c') s[22]+=1;
    else if(S.at(i)=='v') s[23]+=1;
    else if(S.at(i)=='b') s[24]+=1;
    else if(S.at(i)=='n') s[25]+=1;
    else if(S.at(i)=='m') s[26]+=1;
    
    else s[29]+=1;
  }
  
  if(s[27]!=1) CAN=false;
  if(s[28]!=1) CAN=false;
  if(s[29]>0) CAN=false;
  
  if(CAN) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int mn = 1010101010;
	if (k == 1) {
		for (int i = 0; i < n; i++) {
			mn = min(mn, abs(a[i]));
		}
	} else {
		for (int i = 0; i + k - 1 < n; i++) {
			int t = 0;
			if (a[i] < 0) {
				if (a[i + k - 1] < 0) {
					t = -a[i];
				} else {
					t = min(-a[i] * 2 + a[i + k - 1], -a[i] + a[i + k - 1] * 2);
				}
			} else {
				t = a[i + k - 1];
			}
			mn = min(mn, t);
		}
	}
	cout << mn << endl;

	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll D[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> D[i];
    }
    sort(D, D + N);
    ll a = (N - 1) / 2;
    ll b = a + 1;

    cout << D[b]-D[a] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=400010;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
void print(int x) {if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,k,a[N];
inline int F(int now,int s)
{
	if(!a[now])
	{
		if(s>=0) return n-1;
		else return 0;
	}
	int res;
	if(a[now]>0) res=0;
	else res=n+1;
	#define mid (L+R>>1)
	int L,R; L=1, R=n;
	while(L<=R)
	{
		if(a[now]*a[mid]<=s)
		{
			res=mid;
			if(a[now]>0) L=mid+1;
			else R=mid-1;
		}
		else
		{
			if(a[now]>0) R=mid-1;
			else L=mid+1;
		}
	}
	#undef mid
	int pp;
	if(a[now]>0)
	{
		pp=res;
		if(now<=res) pp--;
	}
	else
	{
		pp=n-res+1;
		if(now>=res) pp--;
	}
	return pp;
}
inline int Check(int x)
{
	int res=0;
	for(ri int i=1;i<=n;i++) res+=F(i,x);
	return res/2;
}
signed main()
{
	n=read(), k=read();
	for(ri int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	#define mid (l+r>>1)
	int l=-1e18, r=1e18; int ans=r;
	while(l<=r)
	{
		if(Check(mid)>=k) ans=mid, r=mid-1;
		else l=mid+1; 
	}
	#undef mid
	printf("%lld\n",ans);
	return 0;
}

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

static const int MAX = 200000;
static const int SENTINEL = 2000000000;
int L[MAX/2+1], R[MAX/2+1];

long long merge(int A[], int left, int mid, int right)
{
    long long cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;

    for (int i = 0; i != n1; ++i)
    {
        L[i] = A[left + i];
    }

    for (int i = 0; i != n2; ++i)
    {
        R[i] = A[mid + i];
    }

    L[n1] = R[n2] = SENTINEL;

    int i = 0;
    int j = 0;

    for (int k = left; k != right; ++k)
    {
        if (L[i] <= R[j])
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

long long mergeSort(int A[], int left, int right)
{
    if (left + 1 < right)
    {
        long long a, b, c;
        int mid = (left + right) / 2;
        a = mergeSort(A, left, mid);
        b = mergeSort(A, mid, right);
        c = merge(A, left, mid, right);
        return a + b + c;
    }
    return 0;
}

int main()
{
    int n;
    int A[MAX];

    cin >> n;

    for (int i = 0; i != n; ++i)
    {
        cin >> A[i];
    }

    cout << mergeSort(A, 0, n) << endl;

    return 0;
}


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

struct Area {
	int position;
	int size;
public:
	Area(int p, int s) {
		position = p;
		size = s;
	}
};

int main() {
	string s;
	cin >> s;
	// ?????¨?????????????????????
	vector<int> st;
	// ???????????°????°´??????????????§?°?
	vector<Area> areas;
	st.clear();
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '\\') {
			st.push_back(i);
		} else if (s[i] == '/') {
			if (st.size() > 0) {
				// ????????????????????????????????°???????????£???????????£?????????????????????????????????????¢???¢?????¶??¢?§?????\???????
				int lastDownPos = st[st.size() - 1];
				st.pop_back();
				int areaSize = i - lastDownPos;
				// ?????????????¢???¢????????§?????£????°?????°?????????\???????°´????????¶???  ????????\???????°´??????????°±?????\?????????????????¶???
				while (areas.size() > 0 && areas[areas.size() - 1].position >= lastDownPos) {
					areaSize += areas[areas.size() - 1].size;
					areas.pop_back();
				}
				// ?°??????¶??\??????????????°?°´?±???????
				areas.push_back(Area(lastDownPos, areaSize));
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < areas.size(); i++) {
		sum += areas[i].size;
	}
	cout << sum << endl;
	cout << areas.size();
	for (int i = 0; i < areas.size(); i++) {
		cout << ' ' << areas[i].size;
	}
	cout << endl;
}

Measured memory_bytes: 1372
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;


int main(){
  int h, w;
  int n;
  cin >> h >> w;
  cin >> n;
  int a[n];
  REP(i,n)cin >> a[i];
  vector<vector<int>> ans(h, vector<int>(w));
  int ct = 0;
  REP(i,n){
    REP(j, a[i]){
      ans[ct/w][ct%w] = i+1;
      ct++;
    }
  }

  REP(i,h){
    if(i %2 == 0){
      REP(j,w){
        cout << ans[i][j] << " ";
      }
    }else{
      REP(j,w){
        cout << ans[i][w-1-j] << " ";
      }
    }
    cout << endl;

  }

  return 0;
}


Measured memory_bytes: 384
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, x = nm()
a = nl()
ans = 0
for i in range(n):
    if i == 0:
        if a[i] <= x:
            tmp = a[i]
        else:
            if a[i] > x:
                ans += a[i] - x
                tmp = x
            else:
                tmp = a[i]
    else:
        if tmp + a[i] <= x:
            tmp = a[i]
        else:
            ans += tmp + a[i] - x
            tmp = x - tmp
print(ans)


Measured memory_bytes: 14508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			List<String> ret = new ArrayList<String>();
			String str = br.readLine();
			int q = Integer.parseInt(br.readLine());
			int i, j, start, from;
			String com;
			for (i = 0; i < q; i++) {
				String[] line = br.readLine().split(" ");
				com = line[0];
				start = Integer.parseInt(line[1]);
				from = Integer.parseInt(line[2]) + 1;
				if (com.indexOf("replace") != -1) {
					str = str.substring(0, start) + line[3] + str.substring(from, str.length());
				} else if (com.indexOf("reverse") != -1) {
					String tmp = "";
					String text = str.substring(start, from);
					for (j = text.length(); j > 0; j--) {
						tmp = tmp + text.charAt(j - 1);
					}
					str = str.substring(0, start) + tmp + str.substring(from, str.length());
				} else if (com.indexOf("print") != -1) {
					ret.add(str.substring(start, from));
				}
			}
			for (String text : ret) {
				System.out.println(text);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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


int main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    sort(all(a));
    cout << a[n-1] - a[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()


int main(){
    double r, area, circum;
    cin >> r;
    area = r*r*M_PI;
    circum = 2*r*M_PI;
    printf("%.6f %.6f\n", area, circum);

}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i=(n);i<(m);i++)
using namespace std;typedef long long l;
int main(){int N;cin>>N;queue<l>q;rep(i,1,10)q.push(i);rep(i,0,N-1){l f=q.front();q.pop();l k=f%10,g=f*10;if(k!=0)q.push(g+k-1);q.push(g+k);if(k!=9)q.push(g+k+1);}cout<<q.front()<<endl;}

Measured memory_bytes: 1792
n = gets.to_i
p = []
n.times do |i|
  p[i], p[i+1] = gets.split.map &:to_i
end

def p.matrix_chain_multiplication(n)
  m = Array.new(n+1) { Array.new(n+1, 0)} # m[1][n]..m[n][1]までの計算結果を保持する2次元配列i==jのとき0とするため、0で初期化した。
  for length in 2..n                      # 連鎖行列積の長さをlengthとおく
    for i in 1..(n - length +1)           # 部分行列積の初項の位置を表すi
      j = i + length - 1                  # 部分行列積の末項の位置を表すj
      m[i][j] = Float::INFINITY
      for k in i..j-1                     # i ≦ k < j のk
        m[i][j] = [m[i][j], m[i][k] + m[k+1][j] + self[i-1] * self[k] * self[j]].min
      end
    end
  end
  m[1][n]
end

puts p.matrix_chain_multiplication(n)



Measured memory_bytes: 6944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

void init(){
	
}

vector<LL> v4;

void create(){
	int i,j,k;
	LL a,b;
	for(i=0,k=0;i<60 && k<v4.size();i++){
		a=(LL)1<<i;
		for(j=k;j<v4.size();j++){
			if(v4[j]&a){
				swap(v4[j],v4[k]);
				break;
			}
		}
		if((v4[k]&a)==0)continue;
		for(j=k+1;j<v4.size();j++){
			if(v4[j]&a)v4[j]^=v4[k];
		}
		k++;
	}
}

bool solve(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	vector<LL> v1,v2,v3;
	string sa;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		v3.push_back(a);
	}
	cin>>sa;
	for(i=0;i<n;i++){
		if(sa[i]=='0')v1.push_back(v3[i]);
		else v2.push_back(v3[i]);
	}
	reverse(v1.begin(),v1.end());
	v4=v1;
	create();
	for(i=0;i<n;i++){
		if(sa[i]=='0'){
			v1.pop_back();
			v4=v1;
			create();
			continue;
		}
		for(j=0,k=0;j<v4.size();j++){
			if(v4[j]==0)continue;
			while((v4[j]&((LL)1<<k))==0 && k<60){
				if(v3[i]&((LL)1<<k))return false;
				k++;
			}
			if(k>=60)break;
			if(v3[i]&((LL)1<<k))v3[i]^=v4[j];
		}
		if(v3[i])return false;
	}
	return true;
}

int main(){
	int n,i;
	init();
	cin>>n;
	for(i=0;i<n;i++){
		if(solve())cout<<0<<endl;
		else cout<<1<<endl;
	}
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    int a; cin >> a;
    int cnt = 0;
    int ans = 0;
    REP(i, n - 1) {
        int b; cin >> b;
        if (a == b) cnt++;
        else {
            if (cnt > 0) ans += (cnt + 1) / 2;
            cnt = 0;
        }
        a = b;
    }
    if (cnt > 0) ans += (cnt + 1) / 2;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>val(n);
  rep(i,n)cin>>val[i];
  ll res=0;
  rep(l,n+1)rep(r,n+1){
    if(l+r>n)continue;
    if(l+r>k)continue;
    ll tv=0;
    ll tk=k-l-r;
    vector<ll> va;
    rep(i,l)va.push_back(val[i]);
    rep(i,r)va.push_back(val[n-1-i]);
    sort(all(va));
    rep(i,min((int)tk,l+r))if(va[i]<0)va[i]=0;
    rep(i,l+r)tv+=va[i];
    chmax(res,tv);
    //cout<<l<<" "<<r<<" "<<tv<<endl;
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
H,W,K = map(int, input().split())
MOD = 10**9 + 7


dp = [[0 for _ in range(W)] for _ in range(H+1)]
dp[0][0] = 1

ws = set()
for bit in range(1 << (W-1)):
    if "11" in bin(bit):
        continue
    ws.add(bit)


for i in range(H):
    for bit in ws:
        # 高さi、左からj本目の縦棒にいるとき、どう移動するか。
        for j in range(W):
          

            # 右に移る棒がある時に、右に行ってから下へ移動する場合
            if j != W-1 and bit & (1 << (W-2-j)): # j=0 の時に左端に1が立っているか確認したい、
                    dp[i+1][j+1] += dp[i][j]
                    dp[i+1][j+1] %= MOD

            # 左に移る棒があるときに、左に行ってから下へ移動する場合
            elif j != 0 and bit & (1 << (W-1-j)): # j=W-1 のときに、右端に1が立っているか確認したい。
                dp[i+1][j-1] += dp[i][j]
                dp[i+1][j-1] %= MOD

            else:
                  # そのまま下への移動
                dp[i+1][j] += dp[i][j]
                dp[i+1][j] %= MOD
                #print(i,bin(bit),j,dp)



print(dp[-1][K-1])
#print(dp)
#print(ws)

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int dp[3100][3100] = {0};

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

  string s, t;
  cin >> s >> t;
  rep(i, s.length()){
    rep(j, t.length()){
      if(s[i]==t[j]){
        chmax(dp[i+1][j+1], dp[i][j]+1);
      }
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }


  string res = "";
  int i = (int)s.size();
  int j = (int)t.size();

  while(i > 0 && j > 0){

    if(dp[i][j] == dp[i-1][j]){
      --i;
    }else if(dp[i][j] == dp[i][j-1]){
      --j;
    }else{
      res = s[i-1]+ res;
      --i, --j;
    }
  }

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 37120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            String a;
            a = scan.next();
            if(a.equals("0"))break;
            int ans = 0;
            int i=0;
            while (i < a.length()) {
                char x =a.charAt(i);
                i++;
                int y = Character.getNumericValue(x);
                ans = ans+y;
            }
            System.out.println(ans);
            ans = 0;
        }
        scan.close();
        return;
    }
}


Measured memory_bytes: 26456
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string ss[4]={"AC","WA","TLE","RE"};
int n;
int cnt[4];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		for(int j=0;j<4;j++){
			if(ss[j]==s){
				cnt[j]++;
			}
		}
	}
	for(int i=0;i<4;i++){
		cout << ss[i] << " x " << cnt[i] << endl; 
	}
	return 0;
}


Measured memory_bytes: 3620
""" Created by Jieyi on 9/20/16. """


def block(board, w, h, direction, color):
    # horizontal.
    if direction == 0:
        for i in range(2):
            for j in range(4):
                board[h + i][w + j] = color
    # vertical.
    elif direction == 1:
        for i in range(2):
            for j in range(4):
                board[h + j][w + i] = color


def print_board(board):
    for i in range(len(board)):
        print(board[i])


def go_maze(board, s_w, s_h, g_w, g_h):
    place = board[s_h][s_w]
    if place == 0:
        return 'NG'
    w, h = s_w, s_h
    stack = []

    while True:
        board[h][w] = place + 1
        if h + 1 < len(board) and board[h + 1][w] == place:
            h += 1
            stack.append((w, h))
        elif w + 1 < len(board[h]) and board[h][w + 1] == place:
            w += 1
            stack.append((w, h))
        elif h - 1 > 0 and board[h - 1][w] == place:
            h -= 1
            stack.append((w, h))
        elif w - 1 > 0 and board[h][w - 1] == place:
            w -= 1
            stack.append((w, h))
        else:
            if len(stack) == 0 and board[h + 1][w] != place and board[h][w + 1] != place and board[h - 1][w] != place and board[h][w - 1] != place:
                return 'NG'
            (w, h) = stack.pop()

        if w == g_w and h == g_h:
            return 'OK'


def main():
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break

        board = [[0 for _ in range(110)] for _ in range(110)]
        s_w, s_h = map(int, input().split())
        g_w, g_h = map(int, input().split())
        for _ in range(int(input())):
            color, direction, w, h = map(int, input().split())
            block(board, w, h, direction, color)

        # print_board(board)
        print(go_maze(board, s_w, s_h, g_w, g_h))


if __name__ == '__main__':
    main()

Measured memory_bytes: 8084
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let nx: Vec<u32> = read_vec();
  let ls: Vec<u32> = read_vec();

  let mut dist: u32 = 0;
  let mut bound: u32 = 1;

  if nx[1] == 0 {
    println!("{}", 0);
    return
  }

  while bound <= nx[0] && dist + ls[(bound - 1) as usize] <= nx[1] {
    dist += ls[(bound - 1) as usize];
    bound += 1;
  }

  println!("{}", bound);
}


Measured memory_bytes: 4352
n, k = map(int, input().split(" "))
s = input()
l = []
if s[0] == "0":
    l.append((0, 0))
i = 0
while i < n:
    if s[i] == "1":
        b = i
        while i < n and s[i] == "1":
            i += 1
        l.append((b, i))
    i += 1
if s[n-1] == "0":
    l.append((n, n))
if len(l)-1 <= k:
    print(n)
else:
    maximum = 0
    for i in range(len(l)-k):
        maximum = max(maximum, l[i+k][1]-l[i][0])
    print(maximum)

Measured memory_bytes: 43504
object Main {
  import scala.io.StdIn._
  import scala.annotation.tailrec
  import scala.collection.mutable.Queue
  def main(args: Array[String]): Unit = {
    var lunlunQueue = Queue((1L to 9L):_*)
    var k = readLine().toInt
    @tailrec
    def loop(i: Int): Unit =
      if (i == 1) println(lunlunQueue.head)
      else {
        val h = lunlunQueue.dequeue()
        val l = h % 10L
        for {
          i <- Seq(l - 1, l, l + 1)
          if i >= 0L && i < 10L
        } {
          lunlunQueue.enqueue(h * 10L + (i))
        }
        loop(i - 1)
      }
    loop(k)
  }
}


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

const int mod=1e9+7;
const int N=2005;
int gt[N],igt[N];

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

int C(int k,int n)
{
    if(k<0||k>n) return 0;
    if(k==0) return 1;
    return gt[n]*igt[n-k]%mod*igt[k]%mod;
}

main()
{
    gt[0]=1;
    for(int i=1;i<=N-5;i++) gt[i]=gt[i-1]*i%mod;
    igt[N-5]=Power(gt[N-5],mod-2);
    for(int i=N-5-1;i>=0;i--) igt[i]=igt[i+1]*(i+1)%mod;
    int s;
    cin>>s;
    int res=0;
    for(int i=1;i<=1000000;i++)
    {
        if(s-i*3<0) break;
        int val=s-(i*3);
        (res+=C(i-1,i+val-1))%=mod;
    }
    cout<<res;
}


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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}
const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

bool d[100010];
void calc(){
	d[1] =true;

	for(int i=2; i<=50000;  i++){
		if(d[i])continue;
		for(int k=i+i; k<=100010; k +=i){
			d[k] = true;
		}
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int x;cin>>x;

	calc();


	for(int i=x; i<=100010; i++){
		if(!d[i]){cout<<i<<endl;
		return 0;
		}
	}



}




Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int a[114514];
int b[114514];
int c[114514];
signed main(){
	ic(n)
	int sum=0;
	rep(0,i,n){
		cin>>a[i];
		if(a[i]==i+1){
			b[sum]=i;
			sum++;
		}
	}
	int ans=sum;
	rep(0,i,sum){
		c[i]=ans;
		if(b[i+1]-b[i]==1&&(c[i]==c[i-1]||i<1))ans-=1;
	}
	c(c[sum-1])
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <limits.h>
#include <algorithm>

using namespace std;

long long int sum = 0;


void merge(int A[],int left,int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1],R[n2+1];
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] =  INT_MAX;

	int i = 0, j = 0;
	for(int k = left;k < right; k++){
		if(L[i] < R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			sum += n1 - i;
		}
	}
}

void mergeSort(int A[],int left,int right){
	if(left+1 < right){
		int mid = (left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int A[n];
	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	mergeSort(A,0,n);

	printf("%lld\n",sum);

}



Measured memory_bytes: 4244
N = int(input())
a = []
b = []
c = []
for _ in range(N):
    abc = list(map(int, input().split()))
    a.append(abc[0])
    b.append(abc[1])
    c.append(abc[2])

dp = [[a[0], b[0], c[0]]]

for i in range(1, N):
    dp += [[0, 0, 0]]
    dp[i][0] = max(
            dp[i-1][1] + a[i],
            dp[i-1][2] + a[i])
    dp[i][1] = max(
            dp[i-1][0] + b[i],
            dp[i-1][2] + b[i])
    dp[i][2] = max(
            dp[i-1][0] + c[i],
            dp[i-1][1] + c[i])

print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))


Measured memory_bytes: 34632