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

using namespace std;

int cnt[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++)
    cin >> A[i];
  vector<string> dp(N + 1, "");
  for (int i = 0; i < N; i++)
    for (int j : A)
      if (i + cnt[j] <= N)
      {
        if (i != 0 && dp[i] == "")
          continue;
        if (dp[i + cnt[j]].size() < dp[i].size() + 1)
          dp[i + cnt[j]] = to_string(j) + dp[i];
        else if (dp[i + cnt[j]].size() == dp[i].size() + 1 && dp[i + cnt[j]] < to_string(j) + dp[i])
          dp[i + cnt[j]] = to_string(j) + dp[i];
      }
  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 32384
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    float p = 0f;
    if(n%2 == 0){
      p = 0.5f;
      System.out.println(p);
    }else{
      p =(float)(n/2 + 1) / n;
        System.out.println(p);
    }

  }
}


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

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

using ll = long long;
using pii = pair<int, int>;

const int inf = 1e9;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int N, M, P; cin >> N >> M >> P;
    vector<vector<pii>> g1(N);
    vector<vector<int>> g2(N);
    for (int i = 0; i < M; ++i) {
        int A, B, C; cin >> A >> B >> C;
        --A, --B;
        C -= P;
        g1[A].pb({B, C});
        g2[B].pb(A);
    }
    // find vertices which can reach N
    vector<bool> reachN(N, false);
    reachN[N - 1] = true;
    queue<int> Q;
    Q.push(N - 1);
    while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (int v : g2[u]) {
            if (!reachN[v]) {
                reachN[v] = true;
                Q.push(v);
            }
        }
    }
    // shortest path from 1 to v (using floyd warshall)
    vector<int> dist(N, -inf);
    dist[0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int u = 0; u < N; ++u) {
            for (auto v : g1[u]) {
                if (dist[u] > -inf) {
                    if (dist[v.first] < dist[u] + v.second) // edge relaxation
                        dist[v.first] = dist[u] + v.second;
                }
            }
        }
    }
    // check for negative weight cycle
    for (int u = 0; u < N; ++u) {
        for (auto v : g1[u]) {
            if (dist[u] > -inf) {
                if (dist[v.first] < dist[u] + v.second && reachN[v.first]) {
                    cout << -1 << "\n";
                    return 0;
                }
            }
        }
    }
    cout << max(0, dist[N - 1]) << "\n";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second

signed main() {

    int n;
    cin >> n;
    int ans = 0LL;
    for(int i = 1; i <= n; i++) {
        int cur = 0, cpy = i;
        while(cpy) {
            cur++; cpy = cpy / 10;
        }
        if(cur % 2 == 1) ans++;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
   int N, M;
   int cnt = 0;
   scanf("%d %d", &N, &M);
   int count[M];
   for(int i = 0; i < M; i++) {
      count[i] = 0;
   }
   for(int i = 0; i < N; i++) {
      int K;
      scanf("%d", &K);
      for(int j = 0; j < K; j++) {
         int A;
         scanf("%d", &A);
         A = A-1;
         count[A]++;
      }
   }
   int allcount = 0;
   for(int i = 0; i < M; i++) {
      if(count[i] == N) {
         allcount++;
      }
   }
   printf("%d\n", allcount);
}


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

int main() {
	int n;cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	int i,j,k;
	long long ans=0;
	k=0;
	long long bcount[n];
	for(j=0;j<n;j++){
		while(k<n){
			if(b[j]<c[k])break;
			k++;
		}
		bcount[j]=n-k;
		if(j)bcount[j]+=bcount[j-1];
	}
	j=0;
	for(i=0;i<n;i++){
		while(j<n){
			if(a[i]<b[j])break;
			j++;
		}
		if(j!=n){
			ans+=bcount[n-1];
			if(j){
				ans-=bcount[j-1];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2176
n, m = map(int, input().split())
ship1 = set()
ship2 = set()
for _ in range(m):
	a, b = map(int, input().split())
	if a==1:
		ship1.add(b)
	if b==n:
		ship2.add(a)
if len(ship1&ship2) != 0:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Measured memory_bytes: 19024
Imports System
Module Module1

    Sub Main()

        Dim n As Integer = Console.ReadLine
        Dim a As String = Console.ReadLine
        Dim b As String = Console.ReadLine
        Dim c As String = Console.ReadLine

        Dim cnt As Integer = 0

        Dim a1 As String
        Dim b1 As String
        Dim c1 As String
        For i As Integer = 1 To n
            a1 = Strings.Mid(a, i, 1)
            b1 = Strings.Mid(b, i, 1)
            c1 = Strings.Mid(c, i, 1)

            If a1 = b1 AndAlso b1 = c1 Then
            ElseIf a1 = b1 OrElse b1 = c1 OrElse c1 = a1 Then
                cnt += 1
            Else
                cnt += 2
            End If
        Next i

        Console.WriteLine(cnt)

    End Sub

End Module


Measured memory_bytes: 21968
import bisect

n,q = [int(x) for x in input().split()]
s = input()
questions = [list(map(lambda x: int(x),input().split())) for x in range(q)]

index = 0
findIndexes = []
while(index != -1):
    index = s.find('AC',index)
    if index > -1:
        findIndexes.append(index+1)
        index += 1

for q in questions:
    left_index = bisect.bisect_left(findIndexes,q[0])
    right_index = bisect.bisect_right(findIndexes,q[1]-1)
    print(right_index-left_index)


Measured memory_bytes: 30312
#include <stdio.h>

int main(void) {
  int alf[30] = {0};
  char str[30];
  int flag = 1, i;
  
  scanf("%s", str);
  for(i = 0; str[i] != '\0'; i++) {
    if(alf[str[i] - 'a'] == 0) alf[str[i] - 'a']++;
    else flag = 0;
  }
  
  if(flag) printf("yes\n");
  else printf("no\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
using namespace std;
int w,h,mp[8][8];
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
struct po{int x,y,xx,yy;};

po mk(int a,int b,int c,int d){
  po res; res.x=a, res.y=b, res.xx=c, res.yy=d;
  return res;
}

int bfs(po start,po goal,int flg){
  int dis[8][8]={},visited[8][8][8][8]={};
  queue <po> Q;
  Q.push(mk(start.x,start.y,start.xx,start.yy));

  while(!Q.empty()){
    po t=Q.front();Q.pop();
    visited[t.x][t.y][t.xx][t.yy] = 1;
    if(t.x==goal.x && t.y==goal.y) return dis[t.y][t.x];
    for(int i=0;i<4;i++){
      int nx=t.x+dx[i],ny=t.y+dy[i];
      int mx=t.x-dx[i],my=t.y-dy[i];
      po nstart=mk(t.xx,t.yy,t.x,t.y);
      po ngoal = mk(mx,my,0,0);
      if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]==1)continue;
      if((flg==0)&&(mx<0||my<0||mx>=w||my>=h||mp[my][mx]==1||visited[nx][ny][t.x][t.y]==1||(bfs(nstart,ngoal,1))==-1))continue;
      if(flg==1&&(dis[ny][nx]!=0 ||(start.yy==ny&&start.xx==nx))) continue;
      if(flg==1) mx=my=0;
      Q.push(mk(nx,ny,t.x,t.y));
      dis[ny][nx] = dis[t.y][t.x]+1;
    }
  }
  return -1;
}

int main() {
  while(1){
  cin >> w >> h;
  if(w==0 && h==0) break;
  po start,goal;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      cin >> mp[i][j];
      if(mp[i][j]==3) goal.x=j,goal.y=i,mp[i][j]=0;
      if(mp[i][j]==2) start.x=j,start.y=i,mp[i][j]=0;
      if(mp[i][j]==4) start.xx=j, start.yy=i,mp[i][j]=0;
    }
  cout << bfs(start,goal,0) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<utility>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main() {
	string s;
	cin>>s;
  	if(s[5]=='0'){
    	if(s[6]<='4'){
        	cout<<"Heisei"<<endl;
          return 0;
        }
    }
  cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin >>h >>w;
    while(h!=0){
        int a,b;
        for(a=0;a<h;a++){
            for(b=0;b<w;b++){
        if((a%2==0&&b%2==0)||(a%2==1&&b%2==1))
            cout << '#';
        else cout << '.';
            }
        cout << endl;
        }
      cout << endl;
      cin >>h >>w;
    }
    return 0;
}


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

int main() {
    int N, M, a, b;
    cin >> N >> M;
    deque<pair<int, int>> I;
    for(int i = 0; i < M; i++) {
        cin >> a >> b;
        I.emplace_back(make_pair(a, b));
    }

    sort(I.begin(), I.end(), 
    [](const auto &a, const auto &b) {return a.second < b.second;});

    int c = 0;
    int r = -1;
    for (pair<int, int> p : I) {
        if (p.first >= r) {
            c++;
            r = p.second;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
void judge(int a,int b,int c){
	int min,min1,min2;
	if(a<b && a<c){
		min=a;
		if(b>c){
			min1=c;
			min2=b;
		}
		else{
			min1=b;
			min2=c;
		}
	}
	else if(b<a && b<c){
		min=b;
		if(a>c){
			min1=c;
			min2=a;
		}
		else{
			min1=a;
			min2=c;
		}
	}
	else if(c<a && c<b){
		min=c;
		if(a>b){
			min1=b;
			min2=a;
		}
		else{
			min1=a;
			min2=b;
		}
	}
	else if(a==b){
		if(a<c){
			min=min1=a;
			min2=c;
		}
		else{
			min=c;
			min1=min2=a;
		}
	}
	else if(b==c){
		if(a<b){
			min=a;
			min1=min2=b;
		}
		else{
			min=min1=b;
			min2=a;
		}
	}
	else if(a==c){
		if(a>b){
			min=b;
			min1=min2=a;
		}
		else{
			min2=b;
			min=min1=a;
		}
	}
	else if(a==b && a==c){
		min=min1=min2=a;
	}
	printf("%d %d %d\n",min,min1,min2);
}

int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	judge(a,b,c);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void) {
	int i, j, n, m1, m2, c, a[200000];
	m1 = 0;
	m2 = 0;
	c = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n; i++) {
		if (m1 < a[i]) {
			m1 = a[i];
		}
	}
	for (j = 0; j < n; j++) {
		if (m1 != a[j]) {
			c = c + 1;
			if (m2 < a[j]) {
				m2 = a[j];
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (m1 == a[i] && c == n - 1) {
			printf("%d\n", m2);
		}
		else {
			printf("%d\n", m1);
		}
	}
	return 0;
}

Measured memory_bytes: 2304
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;

int main(){

  stack<int> stk;
  string word;
  int first, second, out;
  while(cin >> word){
    if(word == "+"){
      first = stk.top();
      stk.pop();
      second = stk.top();
      stk.pop();
      out = first + second;
      stk.push(out);
    }
    else if(word == "-"){
      first = stk.top();
      stk.pop();
      second = stk.top();
      stk.pop();
      out = - first + second;
      stk.push(out);
    }else if(word == "*"){
      first = stk.top();
      stk.pop();
      second = stk.top();
      stk.pop();
      out = first * second;
      stk.push(out);
    }else{
      int i = stoi(word);
      stk.push(i);
    }
  }
  out = stk.top();
  cout << out << endl;
}

Measured memory_bytes: 1204
module Main where

import Control.Applicative
import Control.Monad
import Data.List

sumd :: Int -> Int
sumd n
    | q == 0    = r
    | otherwise = r + sumd q
  where
    (q, r) = n `divMod` 10

main :: IO ()
main = do
    [n, a, b] <- fmap read . words <$> getLine :: IO [Int]
    let ans = filter ((\i -> a <= i && i <= b) . sumd) [1 .. n]
    print $ sum ans

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;

int n, m;
int Q[128];
int dp[1 << 11][1 << 11];

int dfs(int S, int T) {
	if(dp[S][T] != -1) return dp[S][T];
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if((Q[i] & S) == T) cnt++;
	}
	if(cnt <= 1) return 0;

	int ret = m;
	for(int i = 0; i < m; i++) {
		if(S >> i & 1) continue;
		int a = 0;
		a = max(a, 1 + dfs(S | (1 << i), T));
		a = max(a, 1 + dfs(S | (1 << i), T | (1 << i)));
		ret = min(ret, a);
	}
	return dp[S][T] = ret;
}

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

	while(cin >> m >> n, n | m) {
		for(int i = 0; i < n; i++) {
			Q[i] = 0;
			for(int j = 0; j < m; j++) {
				char c;
				cin >> c;
				if(c == '1') Q[i] |= 1 << j;
			}
		}
		memset(dp, -1, sizeof dp);
		cout << dfs(0, 0) << endl;
	}
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k){
        cout << s << endl;
    }else{
        s.erase(k);
        s = s + "...";
        cout << s << endl;
    }
}

Measured memory_bytes: 3632
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;
int N;
void dfs(string s){
    if(s.size()==N){
        cout<<s<<endl;
        return ;
    }
    map<char,int> m;
    rep(i,s.size())m[s[i]]++;
    for(int i=0;i<m.size()+1;i++){
        dfs(s+string(1,(char)('a'+i)));

    }
    


}

int main(){
cin>>N;
dfs("");
return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

int main() {
	int x;
	int n;

	vector<bool> p(102,false);
	cin >> x >> n;

	rep(i, n) {
		int t;
		cin >> t;
		p[t] = true;
	}
	int min_v = inf;
	int index = 0;

	rep(i, 102) {
		if (p[i] == false) {
			if (min_v > abs(i - x)) {
				min_v =  abs(i - x);
				index = i;
			}
		}
	}
	cout << index << endl;

	return 0;
}


Measured memory_bytes: 3228
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double ans = 0;
        double a = 0;
        double b = 0;
        for(int i = 0; i < n; i++){
            double x = sc.nextDouble();
            String u = sc.next();
            if(u.compareTo("BTC") == 0){
                b += x;
            }
            else{
                a += x;
            }
        }
        ans = a + b * 380000;
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 23124
N, M, L = map(int, input().split())
A = []
B = []

for n in range(N):
    A.append(list(map(int, input().split())))

for m in range(M):
    B.append(list(map(int, input().split())))

for n in range(N):
    print(' '.join(map(str, [sum(A[n][m] * B[m][l] for m in range(M)) for l in range(L)])))


Measured memory_bytes: 6312
use std::io::stdin;

macro_rules! read {
    ($t: ty) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        line.trim().parse::<$t>().unwrap()
    }};
    ($($t: ty), *) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        let mut iter = line.split_whitespace();
        (
            $(iter.next().unwrap().parse::<$t>().unwrap(), )*
        )
    }}
}
macro_rules! reads {
    ($e:expr, $t:ty) => {{
        let mut v = vec![];
        for _ in 0..$e {
            let mut line = String::new();
            stdin().read_line(&mut line);
            v.push(line.trim().parse::<$t>().unwrap());
        }
        v
    }};
}

fn main() {
    let (a, b, c) = read!(u32, u32, u32);
    let mut n = b / a;
    n = if n > c { c } else { n };
    println!("{}", n);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define nl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define trav(x) for(auto& i: x)

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

	ll n;
	cin >> n;
	vector<pair<ll, ll>> v;
	for(ll i = 1; i <= sqrt(n); i++) {
		if(n % i == 0) {
			v.pb(mp(min(n / i, i), max(n / i, i)));
			v.pb(mp(max(n / i, i), min(n / i, i)));
		}
	}
	ll small = 10e15; 
	for(auto i: v) {
		if(i.fi + i.se - 2 < small) {
			small = i.fi + i.se - 2;
		}
	}
	cout << small;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> bookPrice(n, 0);
    vector<vector<int>> skill(n, vector<int>(m, 0));
    rep(_n, 0, n) {
        cin >> bookPrice[_n];
        rep(_m, 0, m) { cin >> skill[_n][_m]; }
    }

    int maxPrice = 12 * 101001;
    int ans      = maxPrice;
    for (int bookBit = 0; bookBit < (1 << n); bookBit++) {
        int totalPrice = 0;
        vector<int> totalSkill(m, 0);
        rep(bitIdx, 0, n) {
            if (bookBit & (1 << bitIdx)) {
                totalPrice += bookPrice[bitIdx];
                rep(_m, 0, m) { totalSkill[_m] += skill[bitIdx][_m]; }
            }
        }

        bool isOver = true;
        for (int skl : totalSkill) {
            if (skl < x) {
                isOver = false;
                break;
            }
        }
        if (!isOver) {
            continue;
        }

        // 最安値段か
        ans = min(ans, totalPrice);
    }

    if (ans == maxPrice) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    int n;
    cin >> n;
    v_int a(n), b(n);

    irep(i, n) {
        cin >> a[i] >> b[i];
    }
    
    ll ans = 2;
    
    ll s = a[0];
    ll t = b[0];

    irep2(i, 1, n) {
        if(s * b[i] != t * a[i]) {
            ll j = max(s/a[i], t/b[i]);
            while(1) { 
                if(s <= a[i] * j && t <= b[i] * j) { 
                    s = a[i] * j;
                    t = b[i] * j;
                    break;
                } else {
                    j++;
                }
            }
        }
    }
    cout << s + t << endl; 
    return 0;
}


Measured memory_bytes: 256
import sys


class SegTreeSet:
    """
    bitフラグで集合を管理するセグメント木

    要素の種類数は特に明示的に与える必要は無いが、まぁ常識の範囲内で
    """

    def __init__(self, n, initial=0):
        """
        :param n: 文字列長
        :param initial: 初期値
        """
        n2 = 1 << (n - 1).bit_length()
        self.offset = n2
        self.tree = [initial] * (n2 << 1)
        self.initial = initial

    def initial_construct(self, s):
        for i, x in enumerate(s, start=self.offset):
            self.tree[i] = x
        for i in range(self.offset - 1, 0, -1):
            self.tree[i] = self.tree[i << 1] | self.tree[(i << 1) + 1]

    def update(self, i, x):
        """
        i番目の値にxをXOR

        :param i: index(0-indexed)
        :param x: Bit flag for operating bitwise_xor on leaf node
        """
        i += self.offset
        self.tree[i] ^= x
        while i > 1:
            self.tree[i >> 1] = self.tree[i] | self.tree[i ^ 1]
            i >>= 1

    def get_size(self, a, b):
        """
        [a, b)の要素種数を得る

        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        result = self.initial

        l = a + self.offset
        r = b + self.offset
        while l < r:
            if r & 1:
                result |= self.tree[r - 1]
            if l & 1:
                result |= self.tree[l]
                l += 1
            l >>= 1
            r >>= 1

        return bin(result).count('1')


char_mappings = {chr(i + 97): 1 << i for i in range(26)}

n = int(input())
s = input()
s = list(s)
st = SegTreeSet(n)
st.initial_construct(map(char_mappings.get, s))
q = int(input())
ans = []
for line in sys.stdin:
    i, j, k = line.rstrip().split()
    if i == '1':
        j = int(j) - 1
        if s[j] == k:
            continue
        b = char_mappings[k] | char_mappings[s[j]]
        st.update(j, b)
        s[j] = k
    else:
        l = int(j) - 1
        r = int(k)
        ans.append(st.get_size(l, r))
print('\n'.join(map(str, ans)))


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	vector< pair<int , int> >vp , vp2 ;
	int taken[n] ;
	memset(taken , 0 , sizeof(taken)) ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		vp.push_back({x , y}) ;
	}
	for(int i = 0 ; i < n ; ++i)
	{
		int x ,y  ;
		cin>>x>>y ;
		vp2.push_back({x , y}) ;
	}
	sort(vp.rbegin() , vp.rend()) ;
	int ans = 0 ;
	for(int i = 0 ; i < vp.size() ; ++i)
	{
		int idx = -1 , MIN = 1e9 ;
		for(int j = 0 ; j < vp2.size() ; ++j)
		{
			if(taken[j])
				continue ;
			if(vp2[j].first > vp[i].first && vp2[j].second > vp[i].second)
			{
				if(vp2[j].second < MIN)
					MIN = vp2[j].second, idx = j ;
			}
		}
		if(idx == -1)
			continue ;
		taken[idx] = 1 ;
		ans++ ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
//#include"big_integers.h"

using namespace std;


int main()
{
	int n, y;
	cin >> n >> y;
	int i, j, k;
	for (i = 0; i <= n; i++) {
		for ( j = 0; j <= n; j++) {
			k = n - i - j;
			if (k < 0)
				continue;
			if (1000 * k + 5000 * j + 10000 * i == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if ((B-1)%(A-1) == 0){
        cout << (B-1)/(A-1) << endl;
    }
    else {
        cout << (B-1)/(A-1) + 1 << endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c\n",c)
int main(void){
  int n,x,a,ans=0;
  scanf("%d %d",&n,&x);
  FOR(n){
    scanf("%d",&a);
    ans+=a;
    if(ans>x){
      PRN(i+1);
      return 0;
    }
  }
  PRN(n+1);
  return 0;
}

Measured memory_bytes: 128
<?php
  fscanf(STDIN,"%d%d",$l,$r);
  if(($r-$l)>2019){
    echo(0);
  }else{
  	$min = 2019;
  	for($i=$l;$i<=$r-1;$i++){
   	 for($j=$i+1;$j<=$r;$j++){
   	   $value = (($i%2019)*($j%2019))%2019;
   	   if($value < $min){
   	     $min = $value;
   	   }
   	 }
 	 }
  	echo($min);
  }

Measured memory_bytes: 3700
n, m = map(int, input().split())
km = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))

ans = 0;
for i in range(2**n):
  flag = True
  for j in range(m):
    c = 0
    for k in km[j][1:]:
      if i & 2**(k-1):
        c += 1
    if (c%2 != p[j]):
      flag = False
  if flag:
    ans += 1
print(ans)

Measured memory_bytes: 40944
Scanf.scanf "%d" (fun n ->
    let r = Array.make n 0 in
    for i = 1 to n do
        Scanf.scanf " %d" (fun p -> r.(p - 1) <- i)
    done;
    for i = 1 to n do
        Printf.printf "%d " (i * 25000)
    done;
    print_newline ();
    for i = 1 to n do
        Printf.printf "%d " ((n + 1 - i) * 25000 + r.(i - 1))
    done;
    print_newline ();
)

Measured memory_bytes: 5120
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, m;
	cin >> n >> m;
	vector<pair<int, int>> t(n);

	rep(i,n){
		lli a, b;
		cin >> a >> b;
		t[i] = make_pair(a, b);
	}
	sort(all(t));
	lli sum=0;
	for(const auto& x : t){
		if(m>0){
			sum += x.first*Min(m, x.second);
			m = m-Min(m, x.second);
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
#%%
INF = 1<<30
dist = [[INF]*W for _ in range(H)]
dist[0][0] = 0

import queue

q = queue.Queue()
q.put([0,0])

dx = [0,1,0,-1]
dy = [1,0,-1,0]

keiro = [[[] for _ in range(W)] for _ in range(H)]

while not (q.empty()):
    cur = q.get()
    y,x = cur[0],cur[1]
    
    for i in range(4):
        nx = x+dx[i]
        ny = y+dy[i]
        d = dist[y][x] + 1
        if nx<0 or nx>=W or ny<0 or ny>=H:
            continue
        elif S[ny][nx] == '#':
            continue
        
        elif dist[ny][nx]>d:
            q.put([ny,nx])
            dist[ny][nx] = d
            keiro[ny][nx] = [y,x]


if dist[H-1][W-1]==INF:
    print(-1)
else:
    white = 0
    for s in S:
        for t in s:
            if t=='.':
                white += 1
    
    ans = white - dist[H-1][W-1] - 1
    print(ans)
        
    
        
    

Measured memory_bytes: 4208
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int main()
{
    fastio();
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

int h, w;
string s[1111];
int data[1111][1111];
typedef pair < int, int > P;
typedef pair < int, P > PP; 
queue < PP > que;

void cnt(int x, int y){

  for(int i=-1;i<2;i++)
    for(int j=-1;j<2;j++)
      if(i+y >= 0 && j+x >= 0) data[i+y][j+x]++;
}

      
int main(){

  cin >> h >> w;
  for(int i=0;i<h;i++) cin >> s[i];

  for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(s[i][j] == '.') cnt(j, i);

  

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j] != '.' && data[i][j] >= s[i][j]-'0')
	que.push( PP(1, P(j, i)) );
      
  int ans = 0;
  while(!que.empty()){
    PP p = que.front(); que.pop();
    int x = p.S.F, y = p.S.S;

    if(s[y][x] == '.') continue;
    ans = max(ans, p.F);

    s[y][x] = '.';
    cnt(x, y);

    for(int i=-1;i<2;i++){
      for(int j=-1;j<2;j++){
	int xx = j+x, yy = i+y;
	if(xx >= 0 && yy >= 0 && s[yy][xx] != '.' && data[yy][xx] >= s[yy][xx]-'0')
	  que.push( PP(p.F+1, P(xx, yy)) );
      }
    }

  }

  cout << ans << endl;
  
}

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

int main() {
  // ここにプログラムを追記
  string a,b,c;
  cin >> a >> b >> c;
  cout << a.at(0) << b.at(1) << c.at(2) << endl;
  return 0;
  
  
}


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

using namespace std;

const int inf = 1 << 30;

int main()
{
  int n;
  while(cin >> n, n){
    int stay[1000] = {0}, ent[1000] = {0};
    for(int i = 0; i < n; i++){
      int M, D, h, m, p; char e;
      scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &e, &p);
      int now = h * 60 + m;
      if(ent[p]){
	if(p == 0){
	  for(int i = 1; i < 1000; i++){
	    if(ent[i]) stay[i] += now - max(ent[0], ent[i]), ent[i] = now;
	  }
	  ent[p] = 0;
	} else if(ent[0]){
	  stay[p] += now - max(ent[0], ent[p]), ent[p] = 0;
	} else {
	  ent[p] = 0;
	}
      } else {
	ent[p] = now;
      }
    }
    cout << *max_element(stay + 1, stay + 1000) << endl;
  }
  return 0;
}

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

void solve(long long N, long long A, long long B, string S){
	string res;
	int passed = 0;
	int frn = 0;
	for(auto i : S ){
		string r = "No";
		if( i == 'b' ){
			if( passed < A+B and frn < B){
				r = "Yes";
				passed++;
				frn++;
			}
		}else if( i == 'a' ){
			if( passed < A+B ){
				r = "Yes";
				passed++;
			}
		}
		res += r + "\n";
	}
	cout << res;
}



int main(){	
	ios::sync_with_stdio(false);
	long long A;
	long long N;
	string S;
	long long B;
	cin >> N;
	cin >> A;
	cin >> B;
	cin >> S;
	solve(N, A, B, S);
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    int a,b,c;
    Scd(N);
    int dp[2][3] = {};
    // dp[ni%2][0a,1b,2c]
    Rep(ni,N){
        Scd3(a,b,c);
        dp[(ni+1)%2][0] = 0;
        dp[(ni+1)%2][1] = 0;
        dp[(ni+1)%2][2] = 0;
        dp[(ni+1)%2][1] = max( dp[(ni+1)%2][1] , dp[ni%2][0] + b );
        dp[(ni+1)%2][2] = max( dp[(ni+1)%2][2] , dp[ni%2][0] + c );
        dp[(ni+1)%2][2] = max( dp[(ni+1)%2][2] , dp[ni%2][1] + c );
        dp[(ni+1)%2][0] = max( dp[(ni+1)%2][0] , dp[ni%2][1] + a );
        dp[(ni+1)%2][0] = max( dp[(ni+1)%2][0] , dp[ni%2][2] + a );
        dp[(ni+1)%2][1] = max( dp[(ni+1)%2][1] , dp[ni%2][2] + b );
    }

    printf ("%d\n", max( dp[N%2][0] , max( dp[N%2][1] , dp[N%2][2] ) ));

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,k;
int a[105],sum[100005],dp[100005];
void mplus(int& a,int b){
	a+=b;
	if(a>=mod){
		a-=mod;
	}
}
void Minus(int& a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
}
void sub(){
	int prev=0;
	for(int i=0;i<=k;++i){
		mplus(prev,sum[i]);
		mplus(dp[i],prev);
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	dp[0]=1;
	for(int i=1;i<=n;++i){
		memset(sum,0,sizeof(sum));
		for(int j=k;j>=0;--j){
			int val=dp[j];
			int L=j+1;
			int R=j+min(k-j,a[i]);
			if(L<=R){
				mplus(sum[L],val);
				if(R<k){
					Minus(sum[R+1],val);
				}
			}
		}
		sub();
	}
	cout<<dp[k]<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
using namespace std;
char a[12][12];
void irand(int i,int j){
  a[i][j]='0';
    if(i>0&&a[i-1][j]=='1')irand(i-1,j);
    if(j>0&&a[i][j-1]=='1')irand(i,j-1);
    if(i<11&&a[i+1][j]=='1')irand(i+1,j);
    if(j<11&&a[i][j+1]=='1')irand(i,j+1);
  return;
}
int main(){
  while(scanf("%s",a[0])!=EOF){
    int cnt=0;
     for(int i=1;i<12;i++)scanf("%s",a[i]);
    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	if(a[i][j]=='1'){
	  cnt++;
	  irand(i,j);
	}
      }
    }
    printf("%d\n",cnt);
  }
}

Measured memory_bytes: 1140
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using G = vector<vector<ll>>;
#define G(i, j) i, vector<ll>(j)
#define Gv(i, j, k) i, vector<ll>(j, k)
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
#define END(ans) ANS(ans); return
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(std::string S){
  ANS(S.substr(0, 3));
}

// clang-format off
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3620
/*
 * 2575.cc: D's Ambition
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int SN = 8;
const string SRC_S("AIDUNYAN"), DST_S("AIZUNYAN");

/* typedef */

/* global variables */

int sps[26], ps[26];

/* subroutines */

bool same(int ps0[], int ps1[]) {
  for (int i = 0; i < 26; i++)
    if (ps0[i] != ps1[i]) return false;
  return true;
}

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < SN; i++) sps[SRC_S[i] - 'A']++;

  int pi = 0;
  for (int i = 0; i < n;) {
    ps[s[i++] - 'A']++;
    if (i - pi == SN) {
      if (same(sps, ps)) {
	s.replace(pi, SN, DST_S);
	pi = i;
	for (int j = 0; j < 26; j++) ps[j] = 0;
      }
      else {
	ps[s[pi++] - 'A']--;
      }
    }
  }

  cout << s << endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;

    long long int ans=0;
    for (int i=0;i < 1<<(s.size()-1);i++){
        long long int t=0;
        for (int j=0;j<s.size();j++){
            t=10*t+(s[j]-'0');
            if ((i&1<<j) || j==s.size()-1) {
                ans+=t;
                t=0;
            }
        }
    }
   printf("%lld\n",ans);
}

Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
// Time Complexity: build O(N), query O(logN)
template <typename T>
struct SegmentTree {
    // T should be Monoid (Associativity, Identity element)
    using Func = function<T(T, T)>;
    int sz;          // size of array
    vector<T> data;  // 1-indexed(size: sz*2)
    T identity;      // identity element
    Func f;          // binary operation
                     // node k: parent k/2, children (2*k, 2*k+1)
    SegmentTree(int n, const T &identity, Func f) : identity(identity), f(f) {
        sz = 1;
        while (sz < n) sz <<= 1;
        data.assign(2 * sz, identity);
    }
    void set(int idx, const T &val) {
        data[idx + sz] = val;
    }
    void build() {
        for (int idx = sz - 1; idx > 0; idx--) {
            data[idx] = f(data[2 * idx], data[2 * idx + 1]);
        }
    }
    void update(int idx, const T &x) {
        idx += sz;
        data[idx] = x;
        while (idx >>= 1) {
            data[idx] = f(data[2 * idx], data[2 * idx + 1]);
        }
    }
    // [a, b)
    // recursive implementation
    T query(int a, int b) { return query(a, b, 1, 0, sz); }
    T query(int a, int b, int idx, int l, int r) {
        if (r <= a || b <= l) return identity;
        if (a <= l && r <= b)
            return data[idx];
        else {
            T vl = query(a, b, idx * 2, l, (l + r) / 2);
            T vr = query(a, b, idx * 2 + 1, (l + r) / 2, r);
            return f(vl, vr);
        }
    }
    // ToDo: for-loop implementation
    // T query(int l, int r)
    T operator[](const int &idx) const {
        return data[idx + sz];
    }
};
#pragma endregion library
int f(int a, int b) {
    return max(a, b);
}
int main() {
    int MX = 300006;
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    SegmentTree<int> sg(MX, 0, f);
    rep(i, n) {
        int l = max(0, a[i] - k);
        int r = min(MX - 1, a[i] + k) + 1;
        int now = sg.query(l, r) + 1;
        sg.update(a[i], now);
    }
    cout << sg.query(0, MX) << '\n';
}


Measured memory_bytes: 8488
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,a,b;
    cin>>n>>a>>b;
    ll x[n];
    rep(i,n){cin>>x[i];}
    ll res=0;
    rep(i,n-1){
        ll walk = a*(x[i+1]-x[i]);
        res += (walk > b) ? b : walk;
    }
    cout << res << endl;
    return 0;
}


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

typedef long long ll;

ll n,cur;
ll a[100005];
ll x[100005];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        cur=a[i]-cur;
    }
    x[1]=(a[n]-cur)/2;
    for(int i=2;i<=n;i++){
        x[i]=a[i-1]-x[i-1];
    }
    for(int i=1;i<=n;i++){
        cout<<x[i]*2<<' ';
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


template<class Int> V<Int> sieve(Int a, Int b) {
  a = max<Int>(2, a); V<Int> res; Int q = ceil(sqrt(b));
  V<bool> mem(b - a, true), sub(q - 2, true);
  for (Int i = 2; i < q; ++i) {
    if (sub[i - 2]) {
      for (Int j = max(i, (a + i - 1) / i) * i; j < b; j += i) mem[j - a] = false;
      for (Int j = i * i; j < q; j += i) sub[j - 2] = false;
    }
  }
  for (Int i = a; i < b; ++i) if (mem[i - a]) res.push_back(i);
  return res;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n, p; cin >> n >> p, --p;
    if (n == -1) break;
    auto ps = sieve<int>(n + 1, 1e6);
    assert(ps.size() > p);
    V<> v;
    for (int i = 0; i <= p; ++i) for (int j = 0; j <= i; ++j) {
      v.push_back(ps[i] + ps[j]);
    }
    sort(begin(v), end(v));
    cout << v[p] << '\n';
  }
}


Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long 
#define pb push_back
int main(){	
	fast;
		string s; cin>>s;
		ll n=s.length();
		for(ll i=0;i<n;i++) cout<<"x";
		}
	
	
	
		
		
	
	
		
	
	 	
	 	

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

int main()
{
    long n,i,j;
    cin>>n;
    long a[n+1],ans=0;
    map<long,long> mlo,mle;
    multimap<long,long> elo,ele;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(i&1)
            mlo[a[i]]++;
        else
            mle[a[i]]++;
    }
    for(auto it: mlo)   elo.insert({it.second,it.first});
    for(auto it: mle)   ele.insert({it.second,it.first});
    auto it = elo.rbegin(),jt = ele.rbegin();
    
    if(it->second==jt->second)
    {
       if(long(elo.size())==1L && long(ele.size())==1L)   ans = n/2;
       else if(long(elo.size())==1L)
       {
           jt++;
       }
       else if(long(ele.size())==1L)
       {
           it++;
       }
       else
       {
           auto it1 = it, jt1 = jt;
           it1++;jt1++;
           if((it->first+jt1->first)>(it1->first+jt->first))
            jt++;
           else
            it++;
       }
    }
    cout<<n/2 - long(it->first)+n/2 - long(jt->first)+ans;
    return 0;
}


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

int main(){
    
    int x,y;
    int tmp;

    
	for(;;){
        cin>>x>>y;
        if(x==0&&y==0)break;
        if(x>y){
            tmp=x;
            x=y;
            y=tmp;
        }
        
        cout<<x<<" "<<y<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int main()
{
  int n=0,i=0,j=0,k=0,flag=0,max=0;
  int A[100000];

  //入力
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&j);
      A[j]++;
      if(max-j < 0)max=j;
    }

  //出力
  for(i=0;i<=max;i++)
    {
      for(k=0;k<A[i];k++)
	{
	  if(flag==0)
	    {
	      printf("%d",i);
	      flag++;
	    }
	  else if(1<=A[i])printf(" %d",i);
	}
    }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2080
#include<stdio.h>

int main (void){
  int N,R,I;//Iは内部レーティング
  //入力
  scanf("%d %d",&N ,&R);
  //参加回数が９回以下のとき
  if(N < 10){
    I = R + 100 * (10 - N);
  	//参加回数が１０回以上のとき
  }else{
    I = R;
  }
  printf("%d", I);
   return 0;
}

  
    
  

Measured memory_bytes: 128
#include <stdio.h>

void day(int sum);
int main(void)
{
	int lastday[15] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int m, d, sum;
	int i, j;
	
	while (scanf("%d%d", &m, &d), m != 0){
		sum = 0;
		for (i = 0; i < m - 1; i++){
			sum += lastday[i];
		}
		sum += d;
		day(sum);
	}
	
	return (0);
}

void day(int sum)
{
	switch (sum % 7){
		case (6):
		  printf("Tuesday\n");
		  return;
		  
		case (0):
		  printf("Wednesday\n");
		  return;
		  
		case (1):
		  printf("Thursday\n");
		  return;
		  
		case (2):
		  printf("Friday\n");
		  return;
		  
		case (3):
		  printf("Saturday\n");
		  return;
		  
		case (4):
		  printf("Sunday\n");
		  return;
		  
		case (5):
		  printf("Monday\n");
		  return;
		  
	}
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io
    
    int a,b,c;
    cin>>a>>b>>c;
    int M=max(a, b);
    M=max(M, c)*3;
    int diff=M-(a+b+c);
    int ans=diff/2;
    if(diff%2!=0){
        ans+=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  string op;
  while (cin >> a >> op >> b) {
    if (op == "?") break;
    if (op == "+")
      cout << a + b << endl;
    else if (op == "-")
      cout << a - b << endl;
    else if (op == "*")
      cout << a* b << endl;
    else
      cout << a / b << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,cnt;
	int k[10000];
	bool f;
	while(scanf("%d",&n)&&n){
		cnt=0;
		f=false;
		for(int i=0;i<n;i++)scanf("%d",&k[i]);
		for(int i=0;i<n;i++){
			if(k[i]>0){
				cnt++;
			}
			if(k[i]>1){
				f=true;
			}
		}
		if(f)printf("%d\n",cnt+1);
		else printf("NA\n");
	}
}

Measured memory_bytes: 1232