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

int H;
vector<int> A;

void MaxHeapi(int i) {
  int l = 2 * i, r = 2 * i + 1, largest;
  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    MaxHeapi(largest);
  }
}

void BuildMaxHeap() {
  for (int i = H / 2; i >= 1; --i)
    MaxHeapi(i);
}

int main() {
  cin >> H;
  A.resize(H + 1);
  for (int i = 1; i <= H; ++i)
    cin >> A[i];

  BuildMaxHeap();

  for (int i = 1; i <= H; ++i)
    cout << ' ' << A[i];
    cout << endl;
}



Measured memory_bytes: 4560
#include<stdio.h>
int main()
{
  long long int s=0,a,b,c[1000],i,j;
  scanf("%lld",&a);
  for(i=0;i<a;i++)
  {scanf("%lld",&c[i]);}
  for(i=0;i<a;i++)
  {
    for(j=i+1;j<a;j++)
    {
      s=s+c[i]*c[j];
    }
  }
  printf("%lld\n",s);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "data"
using namespace std;
typedef long long LL;
typedef double DB;
typedef pair <LL, LL> pLL;
const int NMAX = 1e5+3;

int n, res, type1, type2, type3;
string s;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> s;
        for(int i = 0; i < (int)s.size()-1; ++i) 
            if(s[i] == 'A' && s[i+1] == 'B') res++;
        if(s[0] == 'B' && s[(int)s.size()-1] == 'A') type1++;
        else if(s[0] == 'B') type2++;
        else if(s[(int)s.size()-1] == 'A') type3++;
    }
    if(type1 <= min(type2, type3)) res += type1*2 + min(type2, type3) - type1;
    else res += min(type2, type3) * 2 + type1 - min(type2, type3);
    if(type2 == type3 && type2 == 0 && type1 > 0) res--;
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int k, n; cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int m = a[0] + k-a[n-1];
    repf(i,1,n) {
        chmax(m, a[i]-a[i-1]);
    }
    cout << k-m << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    string s;
    cin>>s;
    int d=s.size();
    vstr subs(100);
    vin as(100);
    int l=0;
    rep(i,d){
        for(int j=1;i+j-1<d;j++){
            subs[l]=s.substr(i,j);
            bool acgt=true;
            rep(k,subs[l].size()){
                if((subs[l])[k]!='A'&&(subs[l])[k]!='C'&&(subs[l])[k]!='G'&&(subs[l])[k]!='T'){
                    acgt=false;
                    break;
                }
            }
            if(acgt)as[l]=subs[l].size();
            else as[l]=0;
            l++;
        }
    }
    sort(as.begin(),as.end(),greater<int>());
    cout<<as[0]<<endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
anslist = []
for i in range(0, K):
	if A+i in anslist or B < A+i:
		break
	anslist.append(A+i)
	if B-i in anslist or B-i < A:
		break
	anslist.append(B-i)
anslist.sort()
for i in range(0, len(anslist)):
	print(anslist[i])

Measured memory_bytes: 38356
#include<iostream>
#include<string>
using namespace std;
int main()
{
    // 整数の入力
    int a, b, c, d;
    cin >> a >> b >> c >> d;
 
  
  	// 出力
	int start = a;
    int stop = b;
  	if(c > a) start = c;
	if(d < b) stop = d;
  	int ret = stop - start;
  	if(ret < 0) ret = 0;
	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(ll i = 0;i < n;i++)
#define FOR(i,a,b) for(ll i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

struct edge { ll from, to, cost; };

bool isPrime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x % i == 0)return false;
	}
	return true;
}

int main() {
	IOS;
	int n;
	cin >> n;
	int cnt = 0;
	for (int j = 11; j < 55555 && cnt < n; j += 10) {
		if (isPrime(j)) {
			cout << j << ' ';
			cnt++;
		}
	}	
	cout << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
const int maxn = 100001;
int n;
vector<int> loc[maxn];
int g[maxn], ch[maxn], col[maxn], check[maxn];
int find(int i){
	return g[i] == i ? g[i] : g[i] = find(g[i]);
}
void merge(int a, int b){
	a = find(a), b = find(b);
	if(ch[a] < ch[b])swap(a, b);
	if(a != b){
		ch[a] += ch[b];
		col[a] += col[b];
		g[b] = g[a];
	}
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0, x, y;i < n;++i){
		cin >> x >> y;
		ch[y] = 1;
		g[y] = y;
		loc[x].push_back(y);
	}
	for(int i = 1;i < maxn;++i){
		for(int j = 1;j < loc[i].size();++j)merge(loc[i][0], loc[i][j]);
		if(loc[i].size()){
			++col[find(loc[i][0])];
		}
	}
	ll res = 0;
	for(int i = 1;i < maxn;++i){
		if(ch[i] and !check[find(i)]){
			check[find(i)] = true;
			res += col[find(i)] * 1ll * ch[find(i)];
		}
	}
	cout << res - n << '\n';
}

Measured memory_bytes: 5504
# A
if __name__=='__main__':
    S = input()
    ans = False
    if S[0]==S[1] and S[0]!=S[2] and S[2]==S[3]: ans = True
    if S[0]==S[2] and S[0]!=S[3] and S[3]==S[1]: ans = True
    if S[0]==S[3] and S[0]!=S[1] and S[1]==S[2]: ans = True
    print('Yes' if ans else 'No')

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(200000)


N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0


def rec(i):

    if dp[i] < float('inf'):
        return dp[i]

    a = rec(i-1) + abs(h[i] - h[i-1])
    if i > 1:
        a = min(a, rec(i-2) + abs(h[i] - h[i-2]))

    dp[i] = a
    return a


print(rec(N-1))


Measured memory_bytes: 95764
#include <stdio.h>
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

int main(void) {
	int n,k,x,y,ans;
	
	scanf("%d %d %d %d",&n,&k,&x,&y);
	
	ans = MIN(n,k)*x+MAX(n-k,0)*y;

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

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;


ll h,w;
vector<vector<ll>> buffer(1400,vector<ll>(1400,0));
vector<vector<ll>> T(1400,vector<ll>(1400,0));
struct Rectangle{
    ll height;
    ll pos;
};

ll getLargestRectangle(ll size,vector<ll> vec){
  stack<Rectangle>  S;
  ll maxv = 0;
  vec[size] = 0;
  rep(i,size+1){
    Rectangle rect;
    rect.height = vec[i];
    rect.pos = i;
    if(S.empty()){
      S.push(rect);
    }else{
      if(S.top().height < rect.height){
        S.push(rect);
      }else if(S.top().height > rect.height){
        ll target = i;
        while(!S.empty() && S.top().height >= rect.height){
          Rectangle pre = S.top();
          S.pop();
          ll area = pre.height * (i-pre.pos);
          chmax(maxv,area);
          target = pre.pos;
        }
        rect.pos = target;
        S.push(rect);
      }
    }
  }
  return maxv;
}
ll getLargestRectangle(){
  rep(i,h){
    rep(j,w){
      if(buffer[i][j]){
        T[i][j] = 0;
      }else{
        if(i > 0){
          T[i][j] = T[i-1][j] + 1;
        }else{
          T[i][j] = 1;
        }
      }
    }
  }

  ll maxv = 0;
  rep(i,h){
    chmax(maxv,getLargestRectangle(w,T[i]));
  }

  return maxv;
}

int main(){
  cin >> h >> w;
  rep(i,h){
    rep(j,w){
      cin >> buffer[i][j];
    }
  }
  cout << getLargestRectangle() << endl;
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          double[] a = Input.ScanDoubleArray();
          Console.WriteLine(a[0]/a[1]);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main(){
  string s;
  cin>>s;
 if(s=="a"||s=="e"||s=="i"||s=="o"||s=="u"){
   cout<<"vowel"<<endl;
 }
 else{
   cout<<"consonant"<<endl;
 }
  return 0;
}


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

using namespace std;

#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define pb push_back
#define all(c) (c).begin(), (c).end()

const int N = 1e6;

int n, spf[N + 1];
ll ans, extra;

void findSPF(int limit = N) {
	for (int i = 2; i <= N; ++i) {
		if (!spf[i]) {
			for (int j = i; j <= N; j += i)
				spf[j] = i;
		}
	}
}

vi primeFactorize(int x) {
	vi ret;

	while (x != 1) {
		ret.pb(spf[x]);
		x /= spf[x];
	}

	sort(all(ret));
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n;
	findSPF(n);

	for (int c = 1; c < n; ++c) {
		if (n - c == 1) {
			++ans;
			continue;
		}

		vi v = primeFactorize(n - c);
		extra = 1;

		for (int occ = 2, i = 0; i < v.size(); ++i) {
			if (i == v.size() - 1) {
				extra *= occ;
			}
			else if (v[i] == v[i + 1]) {
				++occ;
			}
			else {
				extra *= occ;
				occ = 2;
			}
		}

		ans += extra;
	}

	cout << ans;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define SZ(v)       (ll)(v).size()
#define ALL(v)      (v).begin(),(v).end()
#define UNIQ(v)     sort(ALL(v));(v).erase(unique(ALL(v)),(v).end())
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define BIT(n)      (1LL<<(n))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>
#define SHOW(x)     cout<<#x<<" = "<<x<<endl

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

ll d[202][202];
ll V;

void init() {
    fill((ll *)d, (ll *)d + 202 * 202, inf);
    REP(i, 202) d[i][i] = 0;
}

void add_edge(ll v1, ll v2, ll c) {
    d[v1][v2] = d[v2][v1] = c;
}

void warshall_floyd() {
    REP(k, V) REP(i, V) REP(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
    ll N, M, R; cin >> N >> M >> R;
    vector<ll> r(R); REP(i, R) cin >> r[i], r[i]--;
    
    V = N;
    init();
    REP(i, M) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        add_edge(a, b, c);
    }
    warshall_floyd();
    
    ll ans = inf;
    vector<ll> v(R);
    iota(ALL(v), 0);
    do {
        ll sum = 0;
        REP(i, R-1) sum += d[r[v[i]]][r[v[i+1]]];
        ans = min(ans, sum);
    } while (next_permutation(ALL(v))); 
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;ll a[n];ll m;cin >> m;ll sm=0;
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];sm+=a[i];
    }
    sort(a, a+n, greater<ll>());
    ll ans=0;
    for (int i = 0; i < m; ++i)
    {
    	if(a[i]*4*m>=sm)continue;
    	else {cout << "No";return 0;}
    }
    cout << "Yes\n";
    }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<math.h>
#define lli long long int
#include<bits/stdc++.h>
int main(){
  lli l,r,i,j,mini=2019;
  cin>>l>>r;
  if(r-l>1e4){
    cout<<"0";
    return 0;
  }
  for(i=l;i<r;i++){
    for(j=i+1;j<=r;j++){
      mini=min(mini,(i*j)%2019);
    }
  }
  cout<<mini;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int top=-1,i,j=0;
    int arr[10];
    char in[10];
    scanf("%s",in);
    for(i=0;i<strlen(in);i++)
    {
        if(in[i]=='0'||in[i]=='1')
            arr[j++]=in[i];
        if(in[i]=='B'&&j!=0)
            j=j-1;
    }
    for(i=0;i<j;i++)
        printf("%c",arr[i]);

}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main()
{
    char c;
    cin >>c;
    
    if((c=='a') || (c=='i') || (c=='u') || (c=='e') || (c=='o')){
        cout << "vowel" << endl;
    }else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r ;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(H>=y+r&&W>=x+r&&x-r>=0&&y-r>=0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    vector<string> s(3);
    for(int i = 0; i < 3; i++){
        cin >> s[i];
    }
    
    string ans = "";
    
    for(int i = 0; i < 3; i++){
        ans += s[i][i];
    }
    
    cout << ans << endl;
}

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

using namespace std;

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

//#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define cl(x, v) memset((x), (v), sizeof(x))
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define MOD 1000000007LL
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

bool memo[100010];
bool calc[100010];
int vet[110];
int n, k;

bool dp(int v){
	if(v == 0)
		return false;
		
	if(calc[v])
		return memo[v];
	
	calc[v] = true;
	
	memo[v] = false;
	
	for(int i=0; i<n; i++)
		if(vet[i] <= v)
			memo[v] |= !dp(v - vet[i]);
		
	return memo[v];
}

int main() {	
	cin.sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> vet[i];
	}
	
	if(dp(k))
		cout << "First" << endl;
	else
		cout << "Second" << endl;

	return 0;	
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

bool solve() {
	string s; cin >> s;
	if (sz(s)%2) return false;

	FOR(i,0,sz(s)) if (s[i]-'h' != i%2) return false;
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << (solve() ? "Yes" : "No") << endl;
}



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

a = [0]*n
a[-1] = b[-1]
tmp1 = b.pop()
for i in range(n-2,-1,-1):
  if i == 0:
    a[i] = tmp1
  else:
    tmp2 = b.pop()
    a[i] = min(tmp1, tmp2)
    tmp1 = tmp2
print(sum(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);



int main(){
	ll H,N;
	cin >> H >> N;

	vector<ll> A(N+1),B(N+1);
	FOR(i,1,N+1) cin >> A[i] >> B[i];
	ll maxb = *max_element(B.begin(), B.end());

	ll dp[N+1][H+1+maxb];
	FOR(i,0,N+1)FOR(j,0,H+1+maxb) dp[i][j] = INF;

	FOR(i,0,N+1)dp[i][0] = 0;


	FOR(i,1,N+1){
		FOR(h,0,H+1+maxb){
			if(h-A[i]<0){
				dp[i][h] = dp[i-1][h];
			}else{
				dp[i][h] = min(dp[i-1][h],dp[i][h-A[i]]+B[i]);
			}
		}
		ll minc = INF;
		FORR(h,0,H+1+maxb){
			dp[i][h] = min(dp[i][h],minc);
			minc = min(dp[i][h],minc);
		}
	}
	cout << dp[N][H] << endl;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b ;
  int c;
  c = a % 500;
  if( c > b){
    cout << "No" << endl; 
  }
  else{
    cout << "Yes" << endl;     
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
set <char> se;
int arr[MAX][30];
vector<char> ans;
string s;
int dp[MAX];
void rec(int l,int x)
{
	if(l==0)
	{
		for(int i=0;i<26;i++)
		{
			int y=arr[x][i];
			if(y==-1)
			{
				ans.pb(i+'a');
				//rec(l-1,y+1);
				return;
			}
		}
	}
	for(int i=0;i<26;i++)
	{
		int y=arr[x][i];
		if(y==-1||dp[y+1]==l-1)
		{
			ans.pb(i+'a');
			rec(l-1,y+1);
			return;
		}
	}
}
int main()
{
	cin>>s;
	int cnt=0;
	for(int i=0;i<30;i++)
	arr[s.length()][i]=-1;
	for(int i=s.length()-1;i>=0;i--)
	{
		se.insert(s[i]);
		if(se.size()==26)
		{
			se.clear();
			cnt++;
		}
		dp[i]=cnt;
		for(int j=0;j<27;j++)
		arr[i][j]=arr[i+1][j];
		arr[i][s[i]-'a']=i;
	}
	//cnt++;
	int l=cnt;
	rec(l,0);
	for(int i=0;i<ans.size();i++)
	cout<<ans[i];
}

Measured memory_bytes: 28292
module Main where

import Data.Functor
import Data.Bool

main :: IO ()
main = do
  { [n] <- getInts
  ; print =<< loop 0 n
  }

loop :: Int -> Int -> IO Int
loop c 0 = return c
loop c n = do
  { [m] <- getInts
  ; loop (bool c (c+1) (isPrime m)) (n-1)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

isPrime :: Int -> Bool
isPrime k = null [x | x <- [2..isqrt k], k `mod` x == 0]

isqrt :: Int -> Int
isqrt = floor . sqrt . fromIntegral

Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back


void solve(){
    int a,b,s; cin >> a >> b; s = a+b;
    if(s%2!=0)
      cout << "IMPOSSIBLE";
    else
      cout << s/2;
} 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
    





Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	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
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int h=sc.nextInt();
    int result=(a+b) * h/2;
    
    System.out.println(result);
  }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
  int n;
  cin >> n;
  int a = n / 100;
  if(a * 100 + a * 10 + a < n){
    cout << (a + 1) * 100 + (a + 1) * 10 + (a + 1) << endl;
  }
  else {
    cout << a * 100  + a * 10 + a << endl;;
  }
}

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

int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = 1e9;
    for (int i=1; i<=100; i++) {
        int cost = 0;
        rep(j,n) {
            int t = x[j]-i;
            cost += t*t;
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int x; std::cin >> x;
    int ans = 1;
    for(int i=2; i<=x; i++)
    {
        for(int j=i*i; j<=x; j*=i)
        {
            ans = std::max(ans, j);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = [*map(int, input().split())]
P, M = [], [] # plus, minus
for a in A:
    if a < 0: M.append(a)
    else: P.append(a)

def mix():
    len_p = len(P); len_m = len(M)
    P.sort(reverse=True); M.sort()
    P.append(-1); M.append(1) # add endpoint
    pa, ma = [], []
    while len(pa) + len(ma) < k:
        if P[len(pa)] < -M[len(ma)]: ma.append(M[len(ma)])
        else: pa.append(P[len(pa)])
    if len(ma)%2 == 0: return pa + ma
    exist_pa = len(pa) > 0; exist_ma = len(ma) > 0
    remain_p = len_p > len(pa); remain_m = len_m > len(ma)
    if exist_pa & exist_ma & remain_p & remain_m:
        if abs(pa[-1] * P[len(pa)]) < abs(ma[-1] * M[len(ma)]):
            pa.pop(); ma.append(M[len(ma)])
        else: ma.pop(); pa.append(P[len(pa)])
    elif exist_ma & remain_p: ma.pop(); pa.append(P[len(pa)])
    elif exist_pa & remain_m: pa.pop(); ma.append(M[len(ma)])
    return pa + ma

ans_list = []
if k==n: ans_list = A
# elif len(P) == n: ans_list = sorted(P, reverse=True)[:k]
elif len(M) == n: ans_list = sorted(M, reverse=k%2)[:k]
else: ans_list = mix()
MOD = 10**9 + 7
ans = 1
for a in ans_list: ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 31724
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> clrs(9, 0);
    rep(i, N){
        int tmp;
        cin >> tmp;
        int index = min(tmp / 400, 8);
        clrs[index] ++;
    }
    int min_ans = 0;
    rep(i, 8){
        min_ans += (clrs[i] ? 1 : 0);
    }
    int max_ans = min_ans + clrs[8] ;
    min_ans = max(min_ans, 1);
    cout << min_ans << " " << max_ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:[x[1]])
ans = 'Yes'
s = 0
for i in range(N):
    A,B = AB[i]
    s += A
    if s > B:
        ans = 'No'
print(ans)

Measured memory_bytes: 66332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int count(vector<string> s, int h, int w){
  int ans = 0;
  rep(i,h){
    rep(j,w){
      if(s.at(i).at(j)=='#'){
        ans++;
      }
    }
  }
  //cout << ans << endl;
  return ans;
}
int main() {
  cout << fixed << setprecision(10);
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i,h) cin >> c[i];
  int ans = 0;
  for(int bit1 = 0; bit1 < (1<<h); bit1++){
    for(int bit2 = 0; bit2 < (1<<w); bit2++){
      vector<string> d(h);
      rep(i,h){
        d[i]=c[i];
      }
      rep(i,h){
        if(bit1&(1<<i)){
          rep(j,w){
            d.at(i).at(j)='0';
          }
        }
      }
      rep(j,w){
        if(bit2&(1<<j)){
          rep(i,h){
            d.at(i).at(j)='0';
          }
        }
      }

      if(count(d,h,w)==k){
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define mod 1000000007;

using namespace std;
using ll = long long int;

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<vector<char>> grid(n, vector<char>(m, ' '));
  vector<vector<ll>> dp(n, vector<ll>(m, 0));
  vector<ll> prev(m, 0), curr(m, 0);
  prev[0] = 1;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> grid[i][j];
    }
  }
  for (int i = 1; i < m; i++)
  {
    if (grid[0][i] == '#')
    {
      prev[i] = 0;
    }
    else
    {
      prev[i] = prev[i - 1];
    }
  }
  // for (int i = 1; i < n; i++)
  // {
  //   if (grid[i][0] == '#')
  //   {
  //     dp[i][0] = 0;
  //   }
  //   else
  //   {
  //     dp[i][0] = dp[i - 1][0];
  //   }
  // }
  for (int i = 1; i < n; i++)
  {
    curr[0] = grid[i][0] == '#' ? 0 : prev[0];
    for (int j = 1; j < m; j++)
    {
      if (grid[i][j] == '#')
      {
        curr[j] = 0;
      }
      else
      {
        curr[j] = (prev[j] + curr[j - 1]) % mod;
      }
    }
    prev = curr;
  }
  cout << prev[m - 1] << "\n";
}


Measured memory_bytes: 9088
#include <iostream>

class Baseball{
private:
	int score,out,runner,inning;
public:
    Baseball();
    ~Baseball()=default;
    void checkEvent(std::string event);
    void hit();
    void homerun();
    void countOut();
    int getInning();
};

Baseball::Baseball(){
	score=0,out=0,runner=0,inning=0;
}

void Baseball::checkEvent(std::string event){
    if(event=="HIT"){
        this->hit();
    }
    else if(event=="OUT"){
        this->countOut();
    }
    else if(event=="HOMERUN"){
        this->homerun();
    }
}

void Baseball::hit(){
	runner<3?++runner:++score;
}
	
void Baseball::countOut(){
	if(out<2){
		++out;
	}
	else{
	std::cout << score << std::endl;
	runner=0,out=0,score=0;++inning;
	}
}
	
void Baseball::homerun(){
	score+=runner+1;
	runner=0;
}	

int Baseball::getInning(){
	return inning;
}

int main() {
	Baseball game;
	int num;
	std::cin >> num;
	while(game.getInning()<num){
		std::string event;
		std::cin >> event;
		game.checkEvent(event);
	}
	return 0;
}

Measured memory_bytes: 1224
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

sl=list(input())
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]

#print(l)

count=0
isR=False
from collections import deque
sl=deque(sl)
for i in range(q):
    order=l[i]
    if order[0]=="1":
        count+=1
        #反転
    if count%2==0:
        isR=False
    else:
        isR=True
    if order[0]!="1":
        f=order[1]
        c=order[2]
        temp_f=f
        if isR:
            if temp_f=="1":
                temp_f="2"
            else:
                temp_f="1"
        if temp_f=="1":
            #tempq=deque(sl)
            sl.appendleft(c)
            #tempq.appendleft(c)
            #sl=list(tempq)
        else:
            sl.append(c)
sl=list(sl)
ln=len(sl)
ansl=[]
if isR:
    for i in range(ln-1,-1,-1):
        ansl.append(sl[i])
else:
    ansl=sl
ans=''.join(ansl)
print(ans)



Measured memory_bytes: 46436
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

/*
1. 得点の総数 N通り
2. 得点2倍 1/2
*/
int main() {
    int n, k; cin >> n >> k;
    vector<int> cnt(n, 0); // コインを投げる回数
    int maxCnt = -1; // その最大値
    rep(i,n)
    {
        int point = i+1;
        cnt[i] = 0;
        while (point < k)
        {
            point *= 2;
            cnt[i]++;
        }
        maxCnt = max(cnt[i], maxCnt);
    }

    int numerator = 0; // 通分後の分子
    int denominator = n*pow(2, maxCnt); // 通分後の分母
    rep(i,n) {
        int tmp = pow(2,maxCnt) / pow(2,cnt[i]);
        //cout << tmp << endl;
        numerator += tmp;
    }
    long double ans = (long double) numerator / denominator;
    cout << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 105
#define MOD 1000000007
#define MAX_BIT 35
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    swap(A,B);
    swap(A,C);
    printf("%d %d %d",A,B,C);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

struct point{
  double x;
  double y;
};

void divide(int n, point p1, point p2 ){
  if(n == 0) return;
  
  point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0*p1.x + p2.x) / 3.0;
  s.y = (2.0*p1.y + p2.y) / 3.0;

  t.x = (p1.x + 2.0*p2.x) / 3.0;
  t.y = (p1.y + 2.0*p2.y) / 3.0;

  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
 
  divide(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  
  divide(n-1,s,u);
  printf("%f %f\n",u.x,u.y);

  divide(n-1,u,t);
  printf("%f %f\n",t.x,t.y);

  divide(n-1,t,p2);

}

int main()
{
  int n;
  point p1, p2;
  
  cin >> n;

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y  = 0;

  printf("%.8f %.8f\n", p1.x, p1.y);
  divide(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
  
}




Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			if (a > b + c) {
				System.out.println("0");
			} else {
				System.out.println(b + c - a);
			}
		}
	}
}


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

int main()
{
	string s,a;
	int c = 0, c2=0;
	cin >> s;
	a.push_back(s[0]-1);
	c += s[0]-1-'0';
	c2 += s[0]-'0';
	for (int i=1;i<s.size();++i) {
		c += 9;
		c2 += s[i]-'0';
	}
	cout << max(c, c2) << 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 H;
		int W;
		
		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			
			//0 0?????????
			if (H ==0 && W ==0) {
				break;
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					//??????????????¶??°??????
					if(i%2 == 0){
						if(j%2 == 0){
							sb.append("#");
						}
						else {
							sb.append(".");
						}
					}
					//?????????????\???°??????
					if(i%2 != 0){
						if(j%2 == 0){
							sb.append(".");
						}
						else {
							sb.append("#");
						}
					}

				}
				//?¬??????????????????????
				sb.append("\n");
			}
			//??????
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 21084
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int mn = 1e18;
    for(int i=0;i<1000;i++){
        int ans = 0;
        for(int j=0;j<n;j++){
            ans += (abs(a[j] - i) * abs(a[j] - i));
        }
        mn = min(ans,mn);
    }
    cout<<mn<<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();
		sc.close();
		int cnt = 0;
		for(int i = 1;i <= N;i++){
			if((i <= 9) || (i >= 100 && i < 1000) || (i >= 10000 && i < 100000)){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23124
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

S = input()
L = deque()
for i in range(len(S)):
    L.append(S[i])
Q = int(input())
rev = False
for _ in range(Q):
    q = input()
    if q[0]=='1':
        rev = not rev
    else:
        _,f,c = q.split()
        if rev==(f=='1'):
            L.append(c)
        else:
            L.appendleft(c)
L = list(L)
if rev:
    L = L[::-1]
print(''.join(L))

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, X; cin >> N >> X;
  ll x[N]; rep(i,N) cin >> x[i];
  ll sum[N+1] = {}; rep(i,N) sum[i+1] = x[i]+sum[i];
  ll result = LLINF;
  repr(i,1,N+1) {
    ll now = X * (N+i);
    for (int count=0, j=N-1; j>=0; count++, j-=i) {
      now += (3+2*max(1,count)) * (sum[j+1]-sum[max(0,j+1-i)]);
      if (now>=result) break;
    }
    // cout << i << "->" << now << endl;
    result = min(result, now);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, h, w;
  cin >> n >> h >> w;

  cout << (n - h + 1) * ( n - w + 1) << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][20];
    for(int i = 0; i < n; i++) {
      int A = sc.nextInt();
      for(int j = 0; j < 20; j++) {
        a[i][j] = (A % 2);
        A /= 2;
      }
    }
    long ans = 0;
    int right = 0;
    int[] b = new int[20];
    for(int i = 0; i < n; i++) {
      if(i > right) {
        right = i;
      }
      while(right < n) {
        int p = 0;
        for(int j = 0; j < 20; j++) {
          if((b[j] + a[right][j]) > 1) {
            p++;
            for(int k = 0; k < j; k++) {
              b[k] -= a[right][k];
            }
            break;
          }
          b[j] += a[right][j];
        }
        if(p > 0) break;
        right++;  
      }
      ans += (long)(right - i);
      for(int j = 0; j < 20; j++) { 
        b[j] -= a[i][j];
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 112128
#include<iostream>
using namespace std;
int main(){
	bool nn[128]={0},mm[128]={0},flg;
	int n,m,in;
	int sum_n,sum_m;
	while(cin>>n>>m,n){
		//初期化開始
		for(int i=0;i<128;i++){
			nn[i]=false; mm[i]=false;
		}
		sum_n=0; sum_m=0; flg=false;
		//初期化終了
		for(int i=0;i<n;i++){//n入力
			cin>>in;
			nn[in]=true;
			sum_n+=in;
		}
		for(int i=0;i<m;i++){//m入力
			cin>>in;
			mm[in]=true;
			sum_m+=in;
		}
		if((sum_n-sum_m)%2!=0){cout<<"-1"<<endl;}//差が奇数の場合どうあがいてもムリ
		else if(sum_n<=sum_m){//mの合計の方が大きい場合or等しい場合
			int diff=sum_m-sum_n;//diff>=0(非負)
			for(int i=1;i<=100-diff/2;i++){//範囲適当。超えても被害ないし.
				if(nn[i]&&mm[i+diff/2]){
					cout<<i<<' '<<i+diff/2<<endl;
					flg=true;
					break;
				}
			}
			if(!flg)cout<<"-1"<<endl;
		}
		else{
			int diff=sum_n-sum_m;//diff>0(非負)
			for(int i=1;i<=100-diff/2;i++){//範囲適当。超えても被害ないし.
				if(nn[i+diff/2]&&mm[i]){
					cout<<i+diff/2<<' '<<i<<endl;
					flg=true;
					break;
				}
			}
			if(!flg)cout<<"-1"<<endl;
		}
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e+9
#define mp make_pair
using namespace std;

struct edge{ int to,cost; };
typedef pair<int,int> POS;//x,y
typedef pair<int,POS> FOOT;//foot
typedef pair<int,FOOT> P;//cost

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

int main(){
	int w,h;
	while(cin >> w >> h,w){
		int field[60][30],d[60][30][2];
		priority_queue<P,vector<P>,greater<P> > que;
		vector<POS> t;
		for(int i = 0;i < 60;i++){
			for(int j = 0;j < 30;j++) {
				d[i][j][0] = INF;
				d[i][j][1] = INF;
			}
		}
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				char c;
				cin >> c;
				if(c != 'X'){
					if(c == 'S'){
						d[i][j][0] = 0;
						d[i][j][1] = 0;
						field[i][j] = 0;
						que.push(mp(0,mp(-1,mp(i,j))));
						que.push(mp(0,mp(1,mp(i,j))));
					}else if(c == 'T'){
						t.push_back(mp(i,j));
						field[i][j] = 0;
					}else field[i][j] = c - '0';
				}else field[i][j] = INF;
			}
		}
		while(!que.empty()){
			P p = que.top();que.pop();
			int cost = p.first,foot = p.second.first,x = p.second.second.first,y = p.second.second.second;
			int fa = (foot + 1) / 2,_fa = (1 - foot) / 2;
			if(d[x][y][fa] < cost) continue;
			for(int i = 0;i < 9;i++){
				int nx = x + foot * dx[i],ny = y + foot * dy[i];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] != INF && d[nx][ny][_fa] > d[x][y][fa] + field[nx][ny]){
					d[nx][ny][_fa] = d[x][y][fa] + field[nx][ny];
					que.push(mp(d[nx][ny][_fa],mp(-foot,mp(nx,ny))));
				}
			}
		}
		int mi = INF;
		for(int i = 0;i < t.size();i++){
			for(int j = 0;j < 2;j++){
				mi = min(mi,d[t[i].first][t[i].second][j]);
			}
		}
		if(mi != INF) cout << mi << endl;
		else cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
//stack<int> st;
// cout << << endl;
// cin >> ;

int main(){
    ll x=0,y=0,d=0,n,h,w,k,max=-100000,min=1000000,ans=0,count=0,sum=0;
    string s;
    cin >> n >> k;
    if(n>9||k>9)
        cout << -1 << endl;
    else cout << n*k << endl;
    return 0;
}


Measured memory_bytes: 256