akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	string s;
	cin >> s;
	
	int n = s.size();
	int alphabet[26] = {};
	REP(i,n){
		alphabet[(int)s[i]-(int)'a'] = 1;
	}
	
	REP(j,26){
		if(alphabet[j]==0){
			cout << s << (char)((int)'a'+j) << endl;
			return 0;
		}
	}
	for(int i=n-2; i>=0; --i){
		int now = (int)s[i]-(int)'a';
		int a[26] = {};
		for(int j=0; j<i; ++j){
			a[(int)s[j]-(int)'a'] = 1;
		}
		for(int k=now+1; k<26; ++k){
			if(a[k]==0){
				cout << s.substr(0,i) << (char)((int)'a'+k) << endl;
				return 0;
			}
		}
	}
	
	cout << "-1" << endl;
	
	return 0;
}


Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn rolling_agg_find<T: Copy>(ai: Vec<T>, k: usize, calc: fn(T, T) -> T, calc_rev: fn(T, T) -> T, cmp: fn(T, T) -> bool) -> T {
    let mut res: Option<T> = None;
    let mut tmp_res: Option<T> = None;
    let mut index: usize = 0;
    let mut cache: Vec<T> = Vec::new();

    for i in 0..ai.len() {
        let a = ai[i as usize];

        if tmp_res.is_none() {
            tmp_res = Some(a);
        } else {
            tmp_res = Some(calc(tmp_res.unwrap(), a));
        }

        if cache.len() < k {
            cache.push(a);
        } else {
            if cache.len() < k + 1{
                cache.push(a);
            } else {
                cache[index] = a;
            }

            index = (i + 1) % (k + 1);
            tmp_res = Some(calc_rev(tmp_res.unwrap(), cache[index]));
        }

        if res.is_none() {
            res = Some(tmp_res.unwrap());
        }

        if cmp(tmp_res.unwrap(), res.unwrap()) {
            res = Some(tmp_res.unwrap());
        }
    }

    return res.unwrap();
}

fn add<T: std::ops::Add<Output=T>>(a: T, b: T) -> T {
    return a + b;
}

fn sub<T: std::ops::Sub<Output=T>>(a: T, b: T) -> T {
    return a - b;
}

fn gt<T: std::cmp::PartialOrd>(a: T, b: T) -> bool {
    return a > b;
}

fn calc_e(n: u64) -> f64 {
    return ((n as f64) + 1.0) / 2.0
}

fn main() {
    let n: u64 = read();
    let k: usize = read();
    let pi: Vec<u64> = (0..n).map(|_| read()).collect();
    let ei: Vec<f64> = pi.into_iter().map(|p| calc_e(p)).collect();

    let ans = rolling_agg_find(ei, k, add, sub, gt);
    println!("{:.12}", ans);
}


Measured memory_bytes: 10492
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

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

    vector<vector<int>> v(n, vector<int>(2));
    int x;
    int y;
    vector<int> order;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        v.at(i).at(0) = x;
        v.at(i).at(1) = y;
        order.push_back(i);
    }

    double sum = 0.0;
    double count = 0.0;
    do{
        for(int i = 1; i < n; i++){
            int prev = order.at(i - 1);
            int now = order.at(i);
            int x0 = v.at(prev).at(0);
            int y0 = v.at(prev).at(1);
            int x1 = v.at(now).at(0);
            int y1 = v.at(now).at(1);
            sum += sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
        }
        count++;
    }while(next_permutation(order.begin(), order.end()));

    double ans = sum / count;
    cout << setprecision(15) << ans << endl;
  	return 0;
}


Measured memory_bytes: 3812
#include<cstdio>

using namespace std;

int main(){
    char s[101];
    scanf("%s", s);
    int num = 0;
    while (s[num] != 0){
        num++;
    }
    int l = 0, r = num - 1;
    int ans = 0;
    while (l < r){
        if (s[l] != s[r]){
            ans++;
        }
        l++;
        r--;
    } 
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n,m,s,c;
	cin>>n>>m;
	int num[n]={0},vis[n]={0},flag=0;
	for(int i=0;i<m;i++)
	{
		cin>>s>>c;
		s--;
		if(!vis[s])
		{
			num[s]=c;
			vis[s]=1;
		}
		else
		{
			if(num[s]!=c)
			  flag=1;
		}
	}
	if(!vis[0]&&n>1)
	  num[0]=1;
	if(num[0]==0&&n>1)
	  flag=1;
	if(flag==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	  cout<<num[i];
	cout<<endl;
	return 0;
}

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

s = []
for i in range(n):
    s.append(False)

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        s[a[j]-1] = True

cnt = 0
for i in range(n):
    if not s[i] :
        cnt += 1

print(cnt)









Measured memory_bytes: 9180
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n=int(input())
ar=lis()
from collections import Counter
C=Counter(ar)
s=sum(ar)
q=int(input())
for _ in range(q):
    b,c=sep()
    s-=(C[b]*(b-c))
    C[c]+=C[b]
    C[b]=0
    print(s)


Measured memory_bytes: 94100
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
string s;
int ct;
bool ok=0;
int main()
{//ifstream cin("string.in");
 cin>>s;
 ct=1;
 for(int i=1;i<s.length();i++)
    {if(ok==0&&s[i-1]!=s[i]){ct++;}
     else if(ok==0&&s[i-1]==s[i]&&i<s.length()-1){ct++;i++;ok=1;}
     else if(ok==0)break;
     else if(ok==1){ct++;ok=0;}
    }
 cout<<ct;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;

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

	int n, a;
	cin >> n >> a;

	int ans = n*n - a;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	n := nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	res := "Yes"
	for i := 0; i < n-1; i++ {
		if h[n-1-i] >= h[n-i-2] {
			continue
		}
		if h[n-1-i]+2 <= h[n-i-2] {
			res = "No"
			break
		}
		h[n-i-2]--
	}
	fmt.Fprint(writer, res)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int N, i, s = INF;
	scanf("%d", &N);
	while (N--) {
		int t;
		scanf("%d", &t);
		
		int c = 0;
		while (t % 2 == 0) {
			c++;
			t /= 2;
		}
		s = min(s, c);
	}
	return !printf("%d\n", s);
}

Measured memory_bytes: 256
A = int(input())#500
B = int(input())#100
C = int(input())#50
X = int(input())

count = 0

for i in range(A + 1):
    temp = X - i * 500
    if temp == 0:
        count = count + 1
        continue
    elif temp > 0:
        for j in range(B + 1):
            tempB = temp - j * 100
            if tempB == 0:
                count = count + 1
                continue
            elif tempB > 0:
                for k in range(C + 1):
                    tempC = tempB - k * 50
                    if tempC == 0:
                        count = count + 1
                        continue
                    else:
                        continue
            else:
                continue
    else:
        continue

print(count)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {

	int n;
	cin >> n;

	int a = 0;
	if (n % 3 <= 2) {
		cout << n / 3 << endl;
	}
	else {
		cout << n / 3 - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <fstream>
const int MAX = 1e5+10;
const int INF = 1e6;

using namespace std;

int n,m;
int par[MAX];
bool mak[MAX];//是否被标记过 

//查询 
int Find(int x){
	int r=x;
	while(r!=par[r])
	{
		r=par[r];
	}
	return r;
}

//测试函数 
int main(){
	/*ifstream cin ("D:\\钢铁程序员\\程序数据\\061标记父节点.txt");//从文件读取数据流，省去手动输入的麻烦 
	if(!cin){//读取如果失败 
		cout << "ERROR" << endl;
	}*/
	while(cin >> n >> m,n&&m){
		fill(mak,mak+n,false);
		mak[1] = true;//初始只有根节点标记 
		par[1] = 1;
		for(int i=2; i<=n; i++)
			cin >> par[i];//i节点的父节点 
		//opra
		long long sum = 0;
		while(m--){
			char c;
			int x;
			cin >> c >> x;
			//M 
			if(c == 'M'){
				par[x]=x;
			}
			//Q 
			else{
				sum += Find(x);
			}
		}
		cout << sum << endl;
	}
//	cin.close();//打开文件以后要关闭 
	return 0;
} 


Measured memory_bytes: 3592
N,Q=map(int, input().split())


class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    # k: index , x: value
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])

    def get(self, k):
        return self.query(k,k+1)
    
    # rightは開区間  l<=x<r
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res



"""
     .
 ####.
 ####.
 ####.
 ####.
......

"""
#到達したところまでをxに変える

segW=SegmentTree([N-2]*N, min, 10**18)
segH=SegmentTree([N-2]*N, min, 10**18)
ans=(N-2)**2
for i in range(Q):
    q,x=map(int, input().split())
    if q==1:
        res=segW.query(x-1,N)
        #now=segH.get(res-1)
        segH.update(res, min(x-2, segH.query(res,N)))
        ans-=res
    else:
        res=segH.query(x-1,N)
        now=segW.get(res-1)
        segW.update(res, min(x-2, segW.query(res,N)))
        ans-=res
    #print(res, ans, res-1, x-1, q[0])


print(ans)

Measured memory_bytes: 91048
ss =  input()

ans = "Yes"
r = ["R", "U", "D"]
l = ["L", "U", "D"]

for i, s in enumerate(ss):
  if (i+1) % 2 == 0 and s in l:
    continue
  if (i+1) % 2 == 1 and s in r:
    continue
  ans = "No"
    
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n,m;
  while(scanf("%d%d",&n,&m), n+m){
    int a[n], b[m];
    REP(i,n) scanf("%d",a+i);
    REP(i,m) scanf("%d",b+i);

    int suma = accumulate(a, a+n, 0);
    int sumb = accumulate(b, b+m, 0);
    int diff = suma - sumb;

    int ansa = -1;
    int ansb = -1;
    REP(i,n) REP(j,m){
      if(diff == 2*(a[i] - b[j])){
        if((ansa == -1) || (ansa + ansb > a[i] + b[j])){
          ansa = a[i];
          ansb = b[j];
        }
      }
    }

    if(ansa == -1) puts("-1");
    else printf("%d %d\n",ansa,ansb);

  }
  return 0;
}

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

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  rep(i,a+1)rep(j,b+1)rep(k,c+1)
    if(x == i*500+j*100+k*50) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

vector<ll> yakusu(ll X){
    vector<ll> R;
    for(ll i=1;i*i<=X;i++){
        if(X%i==0){
            R.push_back(i);
            if(i*i!=X){
                R.push_back(X/i);
            }
        }
    }
    return R;
    
}

	
int main(void){
    ll N,a;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(),A.end());
    
    
    
    /*vector<ll> Z  = yakusu(1);
    REP(i,Z.size()){
        cout << Z[i] << " ";
    }cout << endl;*/
    
    vector<ll> B(1000100,0),C(1000100,0);
    ll Ans=0;
    
    REP(i,N){
        C[A[i]]++;
    }
    
    REP(i,A.size()){
        vector<ll> Y = yakusu(A[i]);
        
        bool ok = true;
        REP(j,Y.size()){
            if(B[Y[j]]==1){
                ok=false;
                break;
            }
        }
        
        if(ok){
            if(C[A[i]]==1){
                Ans++;
            }
            //cout << A[i] << endl;
        }
        
        
        B[A[i]]=1;
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 20660
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	// defer writer.Flush()
	n := scanInt()

	tmp, ans := 1, 0
	for i := 0 ; i < n ; i++ {
		a := scanInt()
		if a == tmp {
			tmp++
		} else {
			ans++
		}
	}

	if tmp == 1 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}


Measured memory_bytes: 2304
N, K = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

ans = max(a) * N

for i in range(pow(2, N)):
    candidate = bin(i)[2:].zfill(N)
    if candidate.count("1") != K:
        continue

    cost = 0
    local_min = a[0] - 1
    for j, build in enumerate(a):
        if candidate[j] == "1":
            cost += max(0, local_min + 1 - build)
            local_min = max(build, local_min + 1)
        else:
            local_min = max(build, local_min)

    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 74320
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	int a[n+1];
	for (int i=1; i<=n; i++) cin >> a[i];
	for (int i=k+1; i<=n; i++){
		if (a[i]>a[i-k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

public class Main {	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		int K = ni();
		int result = 1;
		while(N >= K) {
			N /= K;
			result++;
		}
		System.out.println(result);
	}
	


	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 21332
#include "bits/stdc++.h"

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()


using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	cout << (A - 1) * (B - 1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const ll mod = 1e9+7;
int main(){
    ll n,k;
    cin>>n>>k;
    ll st = 0;
    ll en = n;
    ll sts = 0;
    ll sen = 0;
    ll ans = 1;
    for(int i=1;i<=n;i++){
        sts+=st;
        sen+=en;
        st++;
        en--;
        if(i>=k){
            ans+=(sen-sts+1ll);
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<iostream>

int main()
{
	int r, c;
	int ans[101][101] = { 0 };
	std::cin >> r >> c;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			std::cin >> ans[i][j];
			int point = ans[i][j];
			ans[i][c] += point;
			ans[r][j] += point;
			ans[r][c] += point;
		}
	}


	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			std::cout << ans[i][j];
			if (j != c)
				std::cout << " ";
		}
		std::cout << std::endl;
	}
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	unsigned long long p = 1;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		/*if (i >= numeric_limits<unsigned long long>::max() / p) {

		}*/
		p = (p*i) % 1000000007;
		//cout << "p:" << p << endl;
	}

	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using ti3 = tuple<int, int, int>;
using vti3 = vector<ti3>;
template<class T, int s>using va = vector<array<T, s>>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define rrep(i,a) for(int i=a-1;i>=0;i--)
#define rrep1(i,a) for(int i=a;i;i--)
const ll mod = 1000000007;
#define REP rep
template<class T>using heap = priority_queue<T, vector<T>, greater<T>>;
template<class T>using pque = priority_queue<T, vector<T>, function<T(T, T)>>;
template <class T>
inline void hash_combine(size_t & seed, const T & v) {
	hash<T> hasher;
	seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
namespace std {
	template<typename S, typename T> struct hash<pair<S, T>> {
		inline size_t operator()(const pair<S, T> & v) const {
			size_t seed = 0;
			hash_combine(seed, v.first);
			hash_combine(seed, v.second);
			return seed;
		}
	};
	// Recursive template code derived from Matthieu M.
	template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
	struct HashValueImpl{
		static void apply(size_t& seed, Tuple const& tuple){
			HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
			hash_combine(seed, std::get<Index>(tuple));
		}
	};
	template <class Tuple>
	struct HashValueImpl<Tuple, 0>{
		static void apply(size_t& seed, Tuple const& tuple){
			hash_combine(seed, std::get<0>(tuple));
		}
	};
	template <typename ... TT>
	struct hash<std::tuple<TT...>>{
		size_t operator()(std::tuple<TT...> const& tt) const{
			size_t seed = 0;
			HashValueImpl<std::tuple<TT...> >::apply(seed, tt);
			return seed;
		}
	};
}
template<class T>int id(vector<T> &a, T b) {
	return lower_bound(ALL(a), b) - a.begin();
}
//end of lib
int main() {
	int s;
	cin >> s;
	while (s--) {
		vll in(9);
		rep(i, 9)cin >> hex >> in[i];
		ll key = 0;
		int c = 0;
		rep(i, 32) {
			ll a = c;
			rep(j, 8)a += in[j] >> i;
			if ((a^in[8] >> i) & 1) {
				key |= 1ll << i;
				rep(j, 9)in[j] ^= 1ll << i;
			}
			c = 0;
			rep(j, 8)c += in[j] & (2 << i) - 1;
			c = c >> i + 1;
		}
		cout << hex << key << endl;
	}
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 1005;

int T[MAX_N], A[MAX_N];
ll NT[MAX_N], NA[MAX_N];
int main()
{
	memset(T, 0, sizeof(T));
	memset(A, 0, sizeof(A));
	memset(NT, 0LL, sizeof(NT));
	memset(NA, 0LL, sizeof(NA));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	rep (i, N) cin >> T[i] >> A[i];

	NT[0] = (ll)T[0]; NA[0] = (ll)A[0];
	
	for (int i = 1; i < N; ++i){
		NT[i] = NT[i-1], NA[i] = NA[i-1];
		ll lo = 1LL;
		ll hi = (ll)1e18 / (ll)max(T[i],A[i]);
		ll candT = 0LL, candA = 0LL;
		while(lo <= hi){
			ll mid = (hi - lo) / 2LL + lo;
			ll currT = mid*(ll)T[i];
			ll currA = mid*(ll)A[i];
			if (NT[i] <= currT && NA[i] <= currA){
				candT = NT[i] + (currT - NT[i]);
				candA = NA[i] + (currA - NA[i]);
				hi = mid - 1LL;
			}else{
				lo = mid + 1LL;
			} // end if
		} // end while
		NT[i] = candT;
		NA[i] = candA;
	} // end for

	ll res = NT[N-1] + NA[N-1]; 
	cout << res << endl;
  
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  ll stock = 0, money = 1000;
  rep(i, n) {
    if (i == n - 1) {
      money += stock * a[i];
      continue;
    }
    if (a[i + 1] > a[i]) {
      if (stock == 0) {
        stock = money / a[i];
        money = money % a[i];
      }
    } else if (a[i + 1] < a[i]) {
      money += stock * a[i];
      stock = 0;
    }
  }
  cout << money << '\n';
  return 0;
}


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

int main()
{
    std::string s;
    std::string p;
    bool flag = false;
    int cnt = 0;

    std::cin >> s;
    std::cin >> p;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == p[0]) {
            cnt = i;
            for (int j = 0; j < p.size(); j++) {
                if (s[cnt] != p[j]) break;
                cnt++;
                if (cnt >= s.size() && flag == false) {
                    cnt = 0;
                    flag = true;
                }
                if (j == p.size() - 1) {
                    std::cout << "Yes" << std::endl;
                    return 0;
                }
            }
        }
        if (flag == true) break;
    }
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 3208
#include <stdio.h>

int main(void){
    int n, p;

    while(1){
        scanf("%d %d", &n, &p);
        if(n == 0 && p == 0){
            break;
        }

        int candidate[n];

        int i;
        for(i = 0; i < n; i++){
            candidate[i] = 0;
        }

        int remain = p;
        int j = 0;
        while(1){
            if(remain != 0){
                candidate[j]++;
                remain--;
                if(candidate[j] == p){
                    break;
                }
            }

            else{
                remain = candidate[j];
                candidate[j] = 0;
            }
            if(j != n-1){
                j++;
            }
            else{
                j = 0;
            }
        
        }
        printf("%d\n", j);
    }

    return 0;
}


Measured memory_bytes: 2044
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;

public class Test
{
    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = line1[0];
        var A = line1[1];
        var B = line1[2];

        var M = B - A + 1;

        if (M <= 0)
        {
            Console.WriteLine(0);
            return;
        }
        else if (N == 1 && A != B)
        {
            Console.WriteLine(0);
            return;
        }
        else if (N == 1 && A == B)
        {
            Console.WriteLine(1);
            return;
        }

        // 0 ... M - 1 の中から N - 2 個 取る

        // min = 0 + ... + (N - 1)
        long min = 0;

        // max = ... + (M - 1)
        long max = (M - 1) * (N - 2);

        Console.WriteLine(max - min + 1);
    }
    
}

Measured memory_bytes: 13396
#include<stdio.h>
int main()
{
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  if(A==7&&B==5&&C==5)printf("YES\n");
  else if(A==5&&B==7&&C==5)printf("YES\n");
  else if(A==5&&B==5&&C==7)printf("YES\n");
  else printf("NO\n");
  return 0;  
}

Measured memory_bytes: 128
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;



int main(){
   int n;
   cin >> n;
   vector<int> a(n), b(n);
   vector<P> sum(n);
   rep(i, n){
      cin >> a[i] >> b[i];
      sum[i] = P(a[i] + b[i], i);
   }
   sort(ALL(sum), greater<P>());
   ll taka = 0, aok = 0;
   rep(i, n){
     //cout << sum[i].first << " " << sum[i].second << endl;
      if(i % 2 == 0){
         taka += a[sum[i].second];
      }
      else aok += b[sum[i].second];
   }
   cout << (ll)(taka - aok) << endl;
}


Measured memory_bytes: 5640
n = int(input())
a = list(map(int, input().split()))
t = sum(a)
tmp = 0
m = 0
for item in a:
    if (tmp + item) >= t // 2:
        m = item
        break
    tmp += item

ans1 = abs(t-2*tmp)
tmp += m
ans2 = abs(t-2*tmp)
print(min(ans1,ans2))


Measured memory_bytes: 88016
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;
vector<int> G[100005];
llint ans = 1;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

void dfs(int v, int p)
{
	llint cnt = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		cnt++;
	}
	if(k-2 < cnt) ans *= 0;
	else ans *= comb(k-2, cnt) * fact[cnt] % mod, ans %= mod;
	
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v);
	}
}

int main(void)
{
	cin >> n >> k;
	make_fact();
	
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if(k == 1){
		if(n == 1) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	if(k == 2){
		if(n == 1) cout << 2 << endl;
		if(n == 2) cout << 2 << endl;
		if(n >= 3) cout << 0 << endl;
		return 0;
	}
	if(k < G[1].size()+1){
		ans = 0;
		return 0;
	}
	ans *= comb(k, G[1].size()+1) * fact[G[1].size()+1] % mod, ans %= mod;
	for(int i = 0; i < G[1].size(); i++) dfs(G[1][i], 1);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;



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

	int P, N;
	string S;
	cin >>S;
	N = S.size();
	P = 2019;
	int ans = 0;
	if (P == 2) {
		rep(i, N) {
			if (S[i] == '0' || S[i] == '2' || S[i] == '4' || S[i] == '6' || S[i] == '8') ans += i + 1;
		}
	}
	else if (P == 5) {
		rep(i, N) {
			if (S[i] == '0' || S[i] == '5') ans += i + 1;
		}
	}
	else {
		map<int, int> mp{};
		int num = 0, kai = 1;
		mp[0]++;
		for (int i = N - 1; i >= 0; i--) {
			num += (S[i] - '0') * kai;
			num %= P;
			mp[num]++;
			kai = (kai * 10) % P;
		}
		for (auto p : mp) {
			int n = p.second;
			ans += n * (n - 1) / 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3732
#include <stdio.h>

int main(void) {
	int a, b;
	int i;
	if (scanf("%d%d", &a, &b) != 2) return 1;
	if (a <= b) {
		for (i = 0; i < b; i++) printf("%d", a);
	} else {
		for (i = 0; i < a; i++) printf("%d", b);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 128
ls = list(map(int, input()))

import sys
for bit in range(2 ** 3):
    sum = ls[0]
    ans = str(ls[0])
    for i in range(3):
        if bit >> i & 1:
            sum += ls[i + 1]
            ans += "+" + str(ls[i + 1])
        else:
            sum -= ls[i + 1]
            ans += "-" + str(ls[i + 1])
    if sum == 7:
        print(ans + "=7")
        sys.exit()

Measured memory_bytes: 39856
def main():
    n, m, x = map(int, input().split())
    a = [int(i) for i in input().split()]

    l = 0
    r = 0
    for ai in a:
        if ai < x:
            l += 1
        else:
            r += 1

    print(min(l, r))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// O(n^2)
int perm2i(const V<>& p) {
  int n = p.size();
  static V<> fact{1};
  while (fact.size() < n) {
    fact.push_back(fact.size() * fact.back());
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    for (int j = i + 1; j < n; ++j) {
      cnt += p[i] > p[j];
    }
    res += cnt * fact[n - 1 - i];
  }
  return res;
}
V<> i2perm(int n, int x) {
  static V<> fact{1};
  while (fact.size() < n) {
    fact.push_back(fact.size() * fact.back());
  }
  V<> res(n);
  V<bool> used(n);
  for (int i = 0; i < n; ++i) {
    while (used[res[i]]) ++res[i];
    for (int _ = 0; _ < x / fact[n - 1 - i]; ++_) {
      ++res[i];
      while (used[res[i]]) ++res[i];
    }
    used[res[i]] = true;
    x %= fact[n - 1 - i];
  }
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> p(n); for (auto&& e : p) cin >> e, --e;
  V<> q(n); for (auto&& e : q) cin >> e, --e;
  cout << abs(perm2i(p) - perm2i(q)) << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int sum = 0;
        for(int i = 1; i <= N; i++ ) {
            int n = i;
            int digSum = 0;
            while(n > 0) {
                digSum += n % 10;
                n /= 10;
            }
            if(digSum >= A && digSum <= B) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21204
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]

    AA=Counter(A)
    cnt=0
    for i in AA.values():
        if i%2==1:
            cnt+=1

    print(cnt)

resolve()

Measured memory_bytes: 61400
#include <stdio.h>
int main(void){
   int a,b,i;
   
   scanf("%d%d",&a,&b);
   
   if(a<b){
       for(i=0; i<b; i++){
           printf("%d",a);
       }
   }else{
       for(i=0; i<a; i++){
           printf("%d",b);
       }
   }
    return 0;
    
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINLL= 1e18;

void solve()
{
    int N;
    cin >> N;
    LL K;
    cin >> K;
    map<LL, LL> m;
    REP0(i, N)
    {
        int a;
        cin >> a;
        int b;
        cin >> b;
        m[a] += b;
    }
    LL cnt = 0;
    for (auto kv : m)
    {
        cnt += kv.second;
        if (cnt >= K)
        {
            cout << kv.first << endl;
            return;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int M; cin >> M;
	vector<int> cnt(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		cnt[a - 1]++;
		cnt[b - 1]++;
	}
	rep(i, 0, N) {
		cout << cnt[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n;
vector<ll> ans,ansodd;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<ll> dp(1000001,INF), odddp(1000001,INF);
    dp[0]=0;
    odddp[0]=0;
    ll k=1;
    while(true){
        ll count=k*(k+1)*(k+2)/6;
        if(count>1000000) break;
        for(int i=count;i<=1000000;i++){
            dp[i]=min(dp[i],dp[i-count]+1);
            if(count%2){
                odddp[i]=min(odddp[i],odddp[i-count]+1);
            }
        }
        k++;
    }
    while(cin>>n,n){
        cout<<dp[n]<<" "<<odddp[n]<<"\n";
    }
}



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

int n,m;
int a[9];
int temp[9] = {2,5,5,4,5,6,3,7,6};
int c[9];
int dp[10001];
int inf = 1e9;
int sell[10001];


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

    sort(a,a+m);

    for(int i=0; i<m; ++i){
        c[i] = temp[a[i]-1];
    }

    dp[0] = 0;

    for(int i=1; i<=n; ++i){
        int max = -inf;
        int loc = 0;
        for(int j=0; j<m; ++j){
            if(i-c[j]<0){
            continue;
            }
            if(dp[i-c[j]]+1>=max){
                max = dp[i-c[j]]+1;
                loc = j;
            }
        }
        dp[i] = max;
        sell[i] = loc;
    }

    int iter = n;
    while(iter > 0){
        cout << a[sell[iter]];
        iter -= c[sell[iter]];
 
    }
    cout << endl;

    return 0;

}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int n,A,B,head[N],cnt,dp[N][2];//0Îª°×£¬1ÎªºÚ 
struct edge{int nxt,to;}ed[N<<1];
inline void addedge(int x,int y){
	ed[++cnt].to=y;ed[cnt].nxt=head[x];head[x]=cnt;
	ed[++cnt].to=x;ed[cnt].nxt=head[y];head[y]=cnt;}
inline void Add(int &x,int y){x+=y;x-=x>=mod? mod:0;}
inline int MOD(int x,int y){x+=y;x-=x>=mod? mod:0;return x;}
inline void DFS(int u,int fa){
	dp[u][0]=dp[u][1]=1;
	for(register int i=head[u];i;i=ed[i].nxt){
		int v=ed[i].to;if(v==fa)continue;DFS(v,u);
		dp[u][0]=1ll*dp[u][0]*MOD(dp[v][0],dp[v][1])%mod;
		dp[u][1]=1ll*dp[u][1]*dp[v][0]%mod;
	}
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<n;i++)
		scanf("%d%d",&A,&B),addedge(A,B);
	DFS(1,0);
	printf("%d\n",MOD(dp[1][0],dp[1][1]));
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    int jama = -1, ans = 0;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        ans += (jama <= A);
        jama = max(jama, A);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256