akhauriyash/Code-Regression huggingface dataset:
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> X, Y;
  
  REP(i, X+1) {
    if (i * 2 + (X-i) * 4 == Y)
      return "Yes";
  }


  return "No";
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



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

#define INF 1e9

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

    ll sum = 0;
    for(int i = 0; i < n; i++)
        sum += v[i];

    ll dp[n+5][sum+5];

    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= sum; j++)
            dp[i][j] = INF;
    }

    for(int i = 0; i <= n; i++)
        dp[i][0] = 0;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= sum; j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= v[i-1])
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + wt[i-1]);
        }
    }

    for(int i = sum ; i >= 0 ; i--)
    {
        if(dp[n][i] <= w)
        {
            cout << i << "\n";
            return 0;
        }
      //cout << dp[n][i] << " " << i << "\n";
    }

    return 0;
}



Measured memory_bytes: 80768
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <set>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  int n; cin>>n;
  int b[n], mx=0; fill(b,b+n,0);
  for(int i=0;i<n;i++) {
    int a; cin>>a; b[a]++;
    mx=max(mx,a);
  }
  if (mx==1) {
    if (n==2) return puts("Possible")*0;
    else return puts("Impossible")*0;
  }
  if (mx%2==0) {b[mx/2]--; if (b[mx/2]<0) return puts("Impossible")*0;}
  //cout<<3<<endl;
  for(int i=mx/2+1; i<=mx; i++) {
    b[i]-=2; if (b[i] < 0) return puts("Impossible")*0;
  }
  for(int i=1;i<=mx/2+(mx%2);i++) {
    if (b[i] != 0) return puts("Impossible")*0;
  }
  cout<<"Possible"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n,k,cnt=1,sum,a;
  scanf ("%d %d",&n,&k);
  scanf ("%d",&sum); cnt += (sum <= k);
  for (int x = 0; x < n-1; x++) {
    scanf ("%d",&a);
    sum += a;
    cnt += (sum <= k);
  }
  printf ("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 256
#S,T = input().split()
A,B,C= map(int,input().split())
#U = input()

#print(A,B,C)
##print(T)
#print(A)
#print(U)

if A == B:
    if B == C:
        print('No')
    else:
        print('Yes')
elif A == C:
    if A == B:
        print('No')
    else:
        print('Yes')
elif B == C:
    if A == B:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define rep(i,beg,end)   for (auto i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define rall(cont)           rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string ans = "Yes";
	string wrong("LR");
	rep(i, 0, s.length()) {
		if (wrong[i % 2] == s[i]) {
			ans.assign("No");
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(){
	int n, q, x, i, j;
	
	cin >> n;
	vector<int> S;
	for (i=0; i<n; ++i){
	    cin >> x;
	    S.push_back(x);
	}
	
	cin >> q;
	vector<int> T;
	for (i=0; i<n; ++i){
	    cin >> x;
	    T.push_back(x);
	}
	
	int ans = 0;
	for (i=0; i<q; ++i) {
		x = T[i];
		S[n] = x;
		j = 0;
		while (S[j] != x) ++j;
		if (j != n) ++ans;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3260
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 16 20:49:48 2018
ABC100D
@author: maezawa
"""

import itertools as itr

n, m = list(map(int, input().split()))
x = [0]*n
y = [0]*n
z = [0]*n
v = [0]*n
for i in range(n):
    x[i], y[i], z[i] = list(map(int, input().split()))

signs = (-1, 1)
max_value = -1
for s_ar in itr.product(signs, repeat=3):
    for i in range(n):
        v[i] = s_ar[0]*x[i] + s_ar[1]*y[i] + s_ar[2]*z[i]
        #print(s_ar)
    v.sort(reverse=True)
    value = sum(v[:m])
    if value > max_value:
        max_value = value
print(max_value)

    

Measured memory_bytes: 3188
import math
x, y, r, l, s = [], [], [], [], []
while True:
    try:
        a, b = map(float, raw_input().split(","))
        x.append(a); y.append(b)
    except:
        break
    
for i in range(len(x)-1):
    r.append(math.sqrt((x[i+1] - x[0])**2 + (y[i+1] - y[0])**2))
for i in range(1,len(x)-1):
    l.append(math.sqrt((x[i+1] - x[i])**2 + (y[i+1] - y[i])**2))
for i in range(len(x)-2):
    s.append((r[i]+r[i+1]+l[i])/2)

sum = 0.0
for i in range(len(x)-2):
    sum += math.sqrt(s[i]*(s[i]-r[i])*(s[i]-r[i+1])*(s[i]-l[i]))
    
print sum

Measured memory_bytes: 4460
#include <stdio.h>


int main(){

  int i, j, n, k;
  k = 0;

  scanf("%d", &n);

  //1 origin
  int *a;
  int *b;
  a = malloc(sizeof(int) * (n+1));
  b = malloc(sizeof(int) * (n+1));

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

  int c[k+1];
  for(i = 0; i < k+1; i++)
    c[i] = 0;

  for(j = 1; j < n+1; j++)
    c[ a[j] ]++;

  for(i = 1; i < k+1; i++)
    c[i] = c[i] + c[i-1];

  for(j = n; j > 0; j--){
    b[ c[ a[j] ] ] = a[j];
    c[ a[j] ]--;
  }

  for(i = 1; i < n; i++)
    printf("%d ", b[i]);
  printf("%d\n", b[i]);

  free(a);
  free(b);

  return 0;
}

Measured memory_bytes: 16124
N = int(input())
h = list(map(int,input().split()))
ans = 0
for i in range(1,max(h)+1):
    jud = False
    for j in range(N):
        if h[j]>=i:
            if not jud:
                ans += 1
            jud = True
        else:
            jud = False
print(ans)


Measured memory_bytes: 2940
using System;
using System.Linq;
public class Test{
  public static void Main(){
    int n=int.Parse(System.Console.ReadLine());
    int[] x=System.Console.ReadLine().Trim().Split(' ').Select(z=>int.Parse(z)).ToArray();
    int count=2000000000;
    int _c;
    for(int i=0;i<n;i++){
      _c=0;
      while(x[i]%2==0){
        x[i]=x[i]/2;
        _c++;
      }
      if(_c<count) count=_c;
    }
    System.Console.WriteLine(count);
  }
}

Measured memory_bytes: 13268
N,K=map(int,input().split())
A=list(map(int,input().split()))
DP=dict()
if K==1:
  print(0)
  exit()
DP[0]=1
P=0
Y=[0]*(N+1)
for i in range(N):
  Y[i+1]=(Y[i]+A[i]-1)%K
  P+=DP.get(Y[i+1],0)
  DP[Y[i+1]]=DP.get(Y[i+1],0)+1
  if i>=K-2:
    DP[Y[i-K+2]]-=1
print(P)

Measured memory_bytes: 125500
def bubbleSort( cards ):
    n = len( cards )
    for i in range( 0, n ):
        for j in range( n-1 , i, -1 ):
            if int( cards[j][1] ) < int( cards[ j-1 ][1] ):
                cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]
 
    print( " ".join( map( str, cards ) ) )
 
def selectionSort( cards ):
	n = len( cards )
	for i in range( 0, n ):
		mini = i
		for j in range( i , n ):
			if int( cards[j][1] ) < int( cards[ mini ][1] ):
				mini = j
		if mini != i:
			cards[i], cards[ mini ] = cards[ mini ], cards[i]

	print( " ".join( map( str, cards ) ) )


n = int( input( ) )
cards = input( ).split( " " )
cards2 = list( cards )
bubbleSort( cards )
print( "Stable" )
selectionSort( cards2 )
if " ".join( map( str, cards2 ) ) == " ".join( map( str, cards ) ):
	print( "Stable" )
else:
	print( "Not stable" )

Measured memory_bytes: 6756
#include <stdio.h>
#include <math.h>
#include <string.h>

#define N	(600000)

char isPrime[N];

int makePrime(void)
{
	int i, j;
	int lim;

	memset(isPrime, 0, sizeof(isPrime));

	lim = sqrt(N);
	for (i = 2; i < lim; i++){
		for (j = i * i; j < N; j += i){
			isPrime[j] = 1;
		}
	}
	return (0);
}

int main(void)
{
	int q;
	int sum, i;

	makePrime();
	while (scanf("%d", &q),q){
		sum = 0; 
		for (i = 2; q; i++){
			if (!isPrime[i]){
				q--;
				sum += i;
			}
		}
		printf("%d\n", sum);
	}

	return (0);
}

Measured memory_bytes: 1192
from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]


def main():
	x,y,z=nextIntList()
	x,y=y,x
	x,z=z,x
	print(x,y,z)


if __name__=="__main__":
	main()


Measured memory_bytes: 3060
r='yuiophjklnm'
while 1:
    s,c=input(),0
    if s=='#':break
    f='r' if s[0] in r else 'l'
    for i in s:
        if i in r:
            if f=='l':c+=1
            f='r'
        else:
            if f=='r':c+=1
            f='l'
    print(c)

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
LL mod=(1E9)+7;
long long  maxProductSubarrayOfSizeK(long long  A[], long long  n, long long  k)
{

    sort(A, A + n);


    long long  product = 1;


    if (A[n - 1] == 0 && (k & 1))
        return 0;

    if (A[n - 1] <= 0 && (k & 1))
    {
        for (long long  i = n - 1; i >= n - k; i--)
        {

            product = ((product%mod)*(A[i]%mod))%mod;
            if(product<0)
                product+=mod;
            product=product%mod;

        }
        return product;
    }


    long long  i = 0;


    long long  j = n - 1;


    if (k & 1)
    {
          product = ((product%mod)*(A[j]%mod))%mod;
        if(product<0)
            product+=mod;
        product=product%mod;
        j--;
        k--;
    }


    k >>= 1;


    for (long long  itr = 0; itr < k; itr++)
    {


        long long  left_product = A[i] * A[i + 1];

        long long  right_product = A[j] * A[j - 1];

        if (left_product > right_product)
        {
              product = ((product%mod)*(left_product%mod))%mod;
            if(product<0)
                product+=mod;
            product=product%mod;
            i += 2;
        }
        else
        {
            product = ((product%mod)*(right_product%mod))%mod;
            if(product<0)
                product+=mod;
            product=product%mod;
            j -= 2;
        }
    }
    if(product<0)
        product+=mod;
    product=product%mod;
    return product;
}


int  main()
{
    long long  n,k;
    cin>>n>>k;

    long long  A[n];
    for(long long  i=0; i<n; i++)
        cin>>A[i];

    cout << maxProductSubarrayOfSizeK(A, n, k);

    return 0;
}


Measured memory_bytes: 5184
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n, k;
    scanf("%d %d", &n, &k);
    int l[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &l[i]);
    }
    std::sort(l, l + n);
    int ans = 0;
    for (int i = n - k; i < n; i++) {
        ans += l[i];
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong r;

	cin >> r;

	cout << r*r << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		boolean[] red = new boolean[n];
		int[] balls = new int[n];
		red[0] = true;
		for(int i = 0; i < n; i++) {
			balls[i] = 1;
		}
		
		for(int i = 0; i < m; i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			balls[x]--;
			balls[y]++;
			if(red[x]) {
				if(balls[x] == 0) {
					red[x] = false;
					red[y] = true;
				} else {
					red[y] = true;
				}
			}
		}
		
		sc.close();
		
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(red[i]) ans++;
		}
		System.out.println(ans);
	}
	
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define sort(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

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

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

int main() {
  int mod = 1e9+7;
  int n, target;
  cin >>target;
  vector<int>c;
  
  for(int i=3;i<=2001;i++)
    c.push_back(i);

  vector<int> dp(target+1,0);
  dp[0] = 1;
  for (int i = 1; i <= target; i++) {
    for (int j = 0; j < c.size(); j++) {
      if (i-c[j] >= 0) {
	(dp[i] += dp[i-c[j]]) %= mod;
      }
    }
  }
  cout << dp[target] << endl;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
using namespace std;
char upper(char C){
  if(C>='a'&&C<='z'){
    C-='a'-'A';
  }else if(C>='A'&&C<='Z')
    C+='a'-'A';
  return C;
}
int main(){
  string str;
  vector<string> pri;
  while(cin>>str){
    for(int i=0;i<str.size();i++)
      str[i]=upper(str[i]);
    pri.push_back(str);
  }
  for(int i=0;i<pri.size();i++){
    cout<<pri[i];
    if(i!=pri.size()-1)
      cout<<" ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();
        int[] a = cin.ArrayInt(n);

        int index = 1;
        int ans = 0;

        for (int i = 0; i < n; ++i)
        {
            if (a[i] == index)
            {
                ++index;
            }
            else
            {
                ++ans;
            }
        }

        if (index == 1)
        {
            ans = -1;
        }

        WriteLine(ans);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S, T;
    cin >> S >> T;
    ll cnt = 0;
    ll pre = -1;

    unordered_map<char, vector<ll>> pos;
    rep(i, S.length()) {
        pos[S[i]].push_back(i);
    }
    rep(i, T.length()) {
        if (pos[T[i]].size() >= 1) {
            auto idx = upper_bound(pos[T[i]].begin(), pos[T[i]].end(), pre);
            if (idx == pos[T[i]].end()) {
                pre = -1;
                cnt++;
                pre = pos[T[i]][0];
            } else {
                pre = pos[T[i]][idx-pos[T[i]].begin()];
            }
        } else {
            cout << -1 << endl;
            return;
        }
    }
    cout << cnt * S.length() + pre +1<< endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 1744
<?php
fscanf(STDIN, '%d %d', $n, $k);
$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
$res = 0;
for ($i = 0; $i < $n; $i++) {
    if ($h[$i] >= $k) $res++;
}
echo $res.PHP_EOL;

Measured memory_bytes: 14836
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long cnt = 0;
		long p = 1;
		
		for(int i=0;i<N;i++){
			if(A[i] == p){
				p++;
				continue;
			}
			if(A[i] < p){
				continue;
			}
			cnt += (A[i] - 1) / p;
			if(i == 0 && p == 1) p++;
		}
		Console.WriteLine(cnt);
		
		
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = new long[N];
		for(int i=0;i<N;i++) A[i] = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 15836
import sys
import math

#sys.setrecursionlimit(10000)

n = int(input())
h = list(map(int, input().split()))

ans = 0

def w(_l):
    if len(_l) == 0:
       return
    zero = [i for i, x in enumerate(_l) if x == 0]
    if len(zero) == 0:
        global ans
        ans += 1
        w(list(map(lambda x: x - 1,_l)))
    elif len(zero) == len(_l):
        return
    else:
        w(_l[:zero[0]])
        w(_l[zero[0] + 1:])

w(h)
print(ans)


Measured memory_bytes: 3188
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll d,g;
  cin >> d >> g;
  ll p[d],c[d];
  REP(i,d){
    cin >> p[i] >> c[i];
  }
  ll min_num = INF;
  REP(i,1<<d){
    ll score = 0;
    ll cnt = 0;
    REP(j,d){
      if((i>>j)&1){
        score += c[j];
        score += 100*(j+1)*p[j];
        cnt += p[j];
      }
    }
    for(ll j = d-1; j>=0; j--){
      if(score>=g){
        break;
      }
      if(((i>>j)&1)==true) continue;
      cnt += min(p[j]-1,(g-score+100*(j+1)-1)/(100*(j+1)));
      score += 100*(j+1)*min(p[j]-1,(g-score+100*(j+1)-1)/(100*(j+1)));
    }
    if(score<g){
      cnt = INF;
    }
    if(min_num>cnt) min_num = cnt;
  }
  cout << min_num << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(long long i=a;i<=a*1000;i+=a)
        if(i%b==c) 
        {
            cout<<"YES";
            return 0;
        }
    cout<<"NO";

    return 0;
}

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

int main() {
    int q;
    vector<int> v;
    cin >> q;
    for(int i=0;i<q;i++){
        int c;
        cin >> c;
        if(c==0){
            int x;
            cin >> x;
            v.push_back(x);
        }
        else if(c==1){
            int p;
            cin >> p;
            cout << v[p] << endl;
        }
        else{
            v.pop_back();
        }
    }
    return 0;
}



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

using namespace std;
int main()
{
    int n,d,x,ai,counter=1,ans=0;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++)
    {
        cin>>ai;
        ans++;
        for(int j=1;j<=d;j++){
        if(j+ai<=d)
        {
            j=j+ai-1;
            ans++;
        }
        }
        //cout<<ans<<endl;
    }
    cout<<ans+x<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define pb push_back
#define vi vector<int>
int32_t main()
{
   
        string s,t;
        cin>>s;
        cin>>t;
        int c=0;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]!=t[i])
            c++;
        }
        cout<<c<<endl;
    return 0;
}

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

#define sz(x) static_cast<int>((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using ld = long double;

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string inp;
	cin >> inp;
	string ans;
	for(int i = 0; i < sz(inp); ++i) {
		if(inp[i] != 'B') ans += inp[i];
		else {
			if(!ans.empty()) ans.pop_back();
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define pb push_back
#define inf 1e9
#define all(x) (x).begin(), (x).end()
vector<int> h;
int dp[100002];
int n;
int minCost(int i)
{
    //cout << i << " ";
    if(i == n - 1) return 0;
    if(dp[i] != -1) return dp[i];
    int min1 = inf, min2 = inf;
    if(i + 1 < n)
        min1 = minCost(i + 1) + abs(h[i] - h[i + 1]);
    if(i + 2 < n)
        min2 = minCost(i + 2) + abs(h[i] - h[i + 2]);
    //cout << i << " " << min1 << " " << min2 << endl;
    return dp[i] = min(min1, min2);
}
int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        h.pb(x);
    }
    h.pb(1e9);
    h.pb(1e9);
    cout << minCost(0) << endl;

}





Measured memory_bytes: 4216
#include <iostream>
#include <string>
#include <cstdlib>

int cket(std::string &str, int i)
{
	int n = 1;

	for ( ; i < str.size(); ++i ) {
		if ( str[i] == '(' ) n++;
		if ( str[i] == ')' ) n--;

		if ( n == 0 ) break;
	}
	return i;
}

int n;
char expand(std::string str)
{
	std::string res;
	for ( int i = 0; i < str.size(); ++i ) {
		if ( isdigit( str[i] ) ) {
			int j = 1;
			while ( isdigit(str[i + j] ) ) j++;
			int num = std::atoi(str.substr(i, j).c_str());
			
			int s, e;
			if ( str[i + j] == '(' ) {
				int k;
				k = cket(str, i + j + 1);
				s = i + j + 1;
				e = k - (i+j+1);
				i = k;
			} else {
				s = i + j;
				e = 1;
				i = i + j;
			}
			for ( int l = 0; l < num; ++l ){
				char a = expand(str.substr(s, e));
				if ( a != '0' ) return a;
			}
		} else {
			if ( n == 0 ) {
				return str[i];
			}
			n--;
		}
	}
	return '0';
}

int main(void)
{
	while ( true ) {
		std::string str;

		std::cin >> str >> n;
		if ( str == "0" && n == 0 ) break;

		std::cout << expand(str) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int p[3];
  for(int i = 0; i < 3; i++)
    cin >> p[i];
 
  sort(p,p+3);
  cout << p[0]+p[1] << endl;
}

Measured memory_bytes: 3632
INF = 1<<29
def solve(jump, i)
  to = (jump == 1) ? i + 1 : i + 2
  (jump == 1 ? $m + 1 : $m).times do |j|
    cnt = (jump == 1) ? j : j + 1
    $s[i].each_with_index do |(x0, d0), k|
      $s[to].each_with_index do |(x1, d1), l|
        v = i == 0 ? 0 : $dp[i][j][$s_index[i][k]] + (x0 - x1).abs * (d0 + d1)
        $dp[to][cnt][$s_index[to][l]] = v if $dp[to][cnt][$s_index[to][l]] > v
      end
    end
  end
end

loop do
  n, $m = gets.split.map(&:to_i)
  break if n == 0
  $s = [[[0, 0]], *n.times.map { gets.split.map(&:to_i)[1..-1].each_slice(2).to_a } ]
  ss = $s.flatten(1).transpose[0]
  ss.sort!.uniq!
  $s_index = (n+1).times.map{ [] }
  (n+1).times do |i|
    $s[i].each do |x, _|
      $s_index[i] << ss.index(x)
    end
  end

  $dp = (n+1).times.map { ($m+1).times.map { [INF] * ss.size } }
  ($m+1).times{ |i| $dp[0][i].fill(0) }

  n.times do |i|
    solve(1, i)
    break if i == n - 1
    solve(2, i)
  end
  p [*$dp[n-1][0,$m].flatten , *$dp[n][$m].flatten].min
end

Measured memory_bytes: 83252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t;cin >> n >> t;
    vector<int> a(n),b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    int dp[n+1][t][2]={};
    REP(i,n){
        REP(j,t){
            REP(k,2){
                chmax(dp[i+1][j][k],dp[i][j][k]);
                if(j+a[i]<t){
                    chmax(dp[i+1][j+a[i]][k],dp[i][j][k]+b[i]);
                }
                if(!k){
                    chmax(dp[i+1][j][1],dp[i][j][0]+b[i]);
                }
            }
        }
    }
    int ans=0;
    REP(i,t){
        REP(j,2){
            chmax(ans,dp[n][i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 73936
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, M) = nextIntList()
    val switches = Array(M) {
        nextIntList().drop(1)
    }
    val conditions = nextIntList()
    println(rec_bit((1..N).toList().toTypedArray(), switches, conditions))
}

fun rec_bit(seeds: Array<Int>, switches: Array<List<Int>>, conditions: List<Int>, pos: Int = 0, patterns: Array<Int> = emptyArray()): Int {
    if (pos < seeds.size) {
        val res1 = rec_bit(seeds, switches, conditions, pos + 1, patterns + seeds[pos])
        val res2 = rec_bit(seeds, switches, conditions, pos + 1, patterns)
        return res1 + res2
    } else {
        for (m in switches.indices) {
            val on = switches[m].intersect(patterns.toList())
            if (on.size % 2 != conditions[m]) {
                return 0
            }
        }
        return 1
    }
}

Measured memory_bytes: 40720
import sys
from collections import Counter

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
sys.setrecursionlimit(10 ** 8)

N = ri()
#一番小さい数をhとして良い
for i in range(N//4, 3501):
    for j in range(i, 3501):
        if 4*i*j-N*i-N*j == 0:
            continue
        w = (N*i*j)/(4*i*j-N*i-N*j)
        if w > 0 and w.is_integer():
            print(i, j, int(w))
            exit()

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

int findSumOfDidits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int sum = findSumOfDidits(N);
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n,m;
    while(cin>>n>>m,n|m){
        int s[1000],t[1000];
        int S = 0,T = 0;
        for(int i = 0;i < n;i++)cin>>s[i],S+=s[i];
        for(int i = 0;i < m;i++)cin>>t[i],T+=t[i];
        int best = 100000,a = -1,b = -1;
        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                int A = S - s[i] + t[j];
                int B = T - t[j] + s[i];
                if(A == B){
                    if(best > s[i] + t[j]){
                        a = i,b = j,best = s[i] + t[j];
                    }
                }
            }
        }
        if(a == -1)cout<<-1<<endl;
        else cout<<s[a]<<" "<<t[b]<<endl;

    }


    return 0;
}

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

const string YES = "Yes";
const string NO = "No";
long long kk = 0;

int solve(long long A, long long B, long long C, long long K){

  if (K < 0) {
      // cout << "NG" << endl;
      return 0;
  }
  // cout << "xx" << A << "-" << B << "-" << C << "@" << K << endl;
  if ( A < B && A < C && B < C && K >= 0)  { 
      cout << YES << endl;
      return 1;
  } else {
      int r ;
        r = solve( A, B, 2*C, K-1);
        if (r >= 1) return 1;
        r = solve( A, 2*B, C, K-1);
        if (r >= 1) return 1;
      if (K == kk) {
          cout << NO << endl;
          return 1;
      } else {
          return 0;
      }
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    // long long 
    kk = K;
    if ( A < B && A < C && B < C)  { 
      cout << YES << endl;
    } else {
      solve(A, B, C, K);
    } 
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int B[200001]; // B[i] : iが現れる位置
int N;

void input() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int tmp;
		cin >> tmp;
		B[tmp] = i;
	}
}

void solve() {
	ll ans = 0;
	set<int> S;
	S.insert(0);
	S.insert(N + 1);

	for (int i = 1; i <= N; i++) {
		set<int>::iterator it = S.upper_bound(B[i]);
		int right = *it;
		it--;
		int left = *it;
		// cout << right << " " << left << endl;
		S.insert(B[i]);
		// left < l && r < right ならmin = i
		ans += ll(B[i] - left)*ll(right - B[i])*i;
	}
	cout << ans << endl;
}


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


	return 0;
}

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

typedef pair<long long, long long> ii;


long long mod = 1000000007;

int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	string arr[7] = {"SAT","FRI","THU","WED","TUE","MON","SUN"};
	
	for(int i = 0;i < 7;i++){
		if(arr[i] == s){
			cout << (i+1);
			return 0;
		}
	}
	
	
}


Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args){
	try{
	    BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	    String st = sc.readLine();
	    System.out.println(st.toUpperCase());
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9364
function Main(input) {
	var N = parseInt(input.split("\n")[0].split(" ")[0]);
  var K = parseInt(input.split("\n")[0].split(" ")[1]);
  var list = input.split("\n")[1].split(" ");
  var hindo = {};
  var youso = [];
  for(var i = 0; i < list.length; i++){
    if(hindo[list[i]] == null){
       hindo[list[i]] = 1;
      youso.push(list[i]);
       }else{
        hindo[list[i]]++; 
       }
  }
  youso.sort(function(a,b){
  	return hindo[a] - hindo[b];
  });
  if(youso.length < K){
     console.log("0");
    return;
     }
  var count = 0;
  var output = 0;
  while(count != youso.length - K){
        output += hindo[youso[count]];
    	count++;
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 42188
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()


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

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 200013;
const int INF = 1000000007;

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int N;
vi edge[MAXN];
int subtree[MAXN], prod[MAXN];
int stor[MAXN];
int pr;
int fact;

void dfs(int u, int p)
{
    subtree[u] = 1;
    prod[u] = 1;
    for (int v : edge[u])
    {
        if (v == p) continue;
        dfs(v, u);
        subtree[u] += subtree[v];
        prod[u] = mul(prod[u], prod[v]);
    }
    prod[u] = mul(prod[u], subtree[u]);
}
void solve(int u, int p)
{
    // cerr << "solve " << u << ' ' << p << ' ' << pr << endl;
    pr = mul(pr, prod[u]);
    stor[u] = pr;
    // cerr << "stor " << u << " = " << pr << endl;
    for (int v : edge[u])
    {
        if (v == p) continue;
        pr = dvd(pr, prod[v]);
        pr = dvd(pr, subtree[u]);
        pr = mul(pr, N - subtree[v]);
        solve(v, u);
        pr = stor[u];
    }
    stor[u] = mul(stor[u], N);
    stor[u] = dvd(stor[u], subtree[u]);
}

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 0, N - 1)
    {
        int u, v;
        cin >> u >> v; u--; v--;
        edge[u].PB(v);
        edge[v].PB(u);
    }
    dfs(0, N);
    pr = 1;
    // cerr << "pr = " << pr << endl;
    solve(0, N);
    fact = 1;
    FOR(i, 1, N + 1) fact = mul(fact, i);
    FOR(i, 0, N)
    {
        // cerr << "stor " << i << " = " << stor[i] << endl;
        cout << dvd(fact, stor[i]) << '\n';
    }
    return 0;
}


Measured memory_bytes: 17336
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
  int A[3][3];
  rep(i,9) cin >> A[i/3][i%3];
  int b0 = A[0][0];
  int b1 = A[0][1];
  int b2 = A[0][2];
  int a1 = A[1][0] - b0;
  int a2 = A[2][0] - b0;
  if (A[1][1] == a1 + b1 &&
      A[1][2] == a1 + b2 &&
      A[2][1] == a2 + b1 &&
      A[2][2] == a2 + b2) {
        cout << "Yes" << endl;
      }  else {
        cout << "No" << endl;
      }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=3005;
const int MOD=1e9+7;

int n, m;
int dp[N][N][2];

int add(int a, int b) {
    return (a+b)%MOD;
}

int rek(int pos, int c, int fl) {
    if (c<0 || c>n) return 0;
//    printf("pos: %d, c: %d, fl: %d, ret: %d\n", pos, c, fl, fl || (c==0));
    if (pos==m) return (fl || (c==0));
    int &ret=dp[pos][c][fl];
    if (ret!=-1) return ret;
    ret=0;
    ret=add(ret, rek(pos+1, c+1, fl || (c==0))); //PP
    ret=add(ret, rek(pos+1, c-1, fl || (c==0))); //CC
    if (c) ret=add(ret, rek(pos+1, c, fl || (c==1))); //CP
    if (c!=n) ret=add(ret, rek(pos+1, c, fl || (c==0))); //PC
//    printf("pos == %d, c == %d, ret == %d\n", pos, c, ret);
    return ret;
}

void load() {
    scanf("%d %d", &n, &m);
}

void solve() {
    memset(dp, -1, sizeof dp);
    int sol=rek(0, 0, 1);
    for (int i=1; i<=n; ++i) {
        sol=add(sol, rek(0, i, 0));
    }
    printf("%d\n", sol);
}

int main() {
    load();
    solve();
	return 0;
}


Measured memory_bytes: 71040
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    while (true) {
        int N, M; readf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) break;
        auto S = readln.chomp.split(" ").map!(to!int).array;
        auto D = readln.chomp.split(" ").map!(to!int).array;
        D.sort;

        auto X = new int[1 << N];
        foreach (int bit; 0 .. (1 << N)) {
            int x = 0;
            foreach (int i; 0 .. N) {
                if (bit & (1 << i)) 
                    x += S[i];
            }
            X[bit] = x;
        }

        const int INF = int.max / 2;

        auto dp = new int[][](M + 1, 1 << N);
        foreach (ref a; dp) a[] = INF;
        dp[M][] = 0;
        auto dp_min = new int[][](M, 1 << N);
        foreach (ref a; dp_min) a[] = INF;
        foreach_reverse (int k; 0 .. M) {
            foreach (int bit; 0 .. 1 << N) {
                dp_min[k][bit] = min(dp_min[k][bit], dp[k + 1][bit] + abs(D[k] - X[bit]));
            }
            foreach_reverse (int j; 1 .. N + 1) {
                int bit = (1 << j) - 1;
                while (bit < (1 << N)) {
                    foreach (int l; 0 .. N) {
                        if (! (bit & (1 << l))) continue;
                        //stderr.writefln("%b", 1<<N);
                        //stderr.writefln("%b", bit - (1 << l));
                        dp_min[k][bit & ~(1<<l)] = min(dp_min[k][bit & ~(1<<l)], dp_min[k][bit]);
                    }
                    int x = bit & -bit, y = bit + x;
                    bit = ((bit & ~y)/ x >> 1) | y;
                }
            }
            foreach (int bit; 0 .. 1 << N) {
                dp[k][bit] = min(dp[k][bit], dp_min[k][bit]);
            }
        }

        writeln(dp[0][0]);
    }
}

Measured memory_bytes: 97384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = 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 PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

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

int N;
string S;
bool dp[30010][11][11][11];

int main(void) {
    cin >> N >> S;

    memset(dp, false, sizeof(dp));
    dp[0][0][0][0] = true;

    REP(i, N) {
        const int d = S[i] - '0' + 1;
        REP(j, 11) REP(k, 11) REP(l, 11) {
            dp[i + 1][j][k][l] |= dp[i][j][k][l];
        }
        dp[i + 1][d][0][0] |= true;
        REP(j, 11) {
            dp[i + 1][j][d][0] |= dp[i][j][0][0];
        }
        REP(j, 11) REP(k, 11) {
            dp[i + 1][j][k][d] |= dp[i][j][k][0];
        }
    }

    int ans = 0;
    REP(i, 10) REP(j, 10) REP(k, 10) {
        ans += dp[N][i + 1][j + 1][k + 1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
	int N;
	cin >> N;
	ll x[N],y[N];
	ll ans = N;
	for(int i=0;i<N;i++)cin >> x[i] >> y[i];
	ll ret = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==j)continue;
			ll s=x[i]-x[j],t=y[i]-y[j];
			if(x==0 && y==0)continue;
			ll cnt = 0;
			for(int a=0;a<N;a++){
				for(int b=0;b<N;b++){
					if(a==b)continue;
					if(x[a]-x[b]==s&&y[a]-y[b]==t)cnt++;
				}
			}
			ret = max(ret,cnt);
		}
	}
	ans -= ret;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin>>n;
    vector<vector<int>> in(n,vector<int>(3));
    rep(i,n) rep(j,3) cin >> in[i][j];
    
    vector<int> vec(6,-INF);
    rep(i,3){
        vec[i] = 0;
    }
    rep(i,n){
        rep(j,3){
            for(int k=3;k<=5;k++){
                if(j%3==k%3) continue;
                vec[k] = max(vec[k],vec[j] + in[i][k%3]);
            }
        }
        rep(j,3){
            vec[j] = vec[j+3];
        }
    }
    int ans=-INF;
    rep(i,3) ans = max(ans,vec[i+3]);
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if (n%2==0) cout<<n<<endl;
    else cout<<n*2<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)

cost = []
cost[0] = 0
cost[1] = (h[0] - h[1]).abs

1.upto(n-2) do |i|
  cost[i+1] = [cost[i]+(h[i+1]-h[i]).abs, cost[i-1]+(h[i+1]-h[i-1]).abs].min
end

puts cost[n-1]

Measured memory_bytes: 11396
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), v.end()
#define rall(x) x.rbegin(), x.rend()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

	string s; cin >> s;
	string ans(s.size(), 'x');

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if((i % 2 == 0 && s[i] == 'L')
                || (i % 2 == 1 && s[i] == 'R')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256