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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi C(n), S(n), F(n);
    rep(i,n-1) cin >> C[i] >> S[i] >> F[i];
    F[n-1]=1;
    rep(i,n) {
        int t=S[i];
        for ( int j=i; j<n; j++ ) {
            if ( j==n-1 ) {
                cout << t << '\n';
            }
            else {
                t+=C[j]; // reach j+1
                if ( t<=S[j+1] ) {
                    t=S[j+1];
                } else {
                    t=S[j+1]+(t-S[j+1]+F[j+1]-1)/F[j+1]*F[j+1];
                }
            }
        }
    }
    return 0;   
}












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

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  int n; cin >> n;
  int ans = 1, a;
  for (int i = 0; i < n; i ++) {
    cin >> a;
    ans = ans * a / gcd(ans, a);
  }

  cout << ans << endl;
}



Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n, k;
    scan(n, k);
    auto s = readln.chomp.to!(char[]);
    s[k - 1] = (s[k - 1] - 'A' + 'a').to!char;
    writeln(s);
}























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (x, a, b): (i32, i32, i32) = read();
    if (x-a).abs() < (x-b).abs() {
        println!("A");
    } else {
        println!("B");
    }
}


Measured memory_bytes: 4352
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
problems = list()
counter = 0

for i in range(n):
    problems.append(list(map(int,input().split())))
    
for problem in problems:
    judge = 0
    for i in range(len(problem)):
        judge += problem[i]*b[i]
    if judge + c > 0:
        counter+= 1
        
print(counter)

Measured memory_bytes: 3064
// ABC 157-C
// 2020.3.1 bal4u

#include <stdio.h>

int C[10], N;

int check(int n) {
	int i;
	for (i = 0; n; ++i) {
		if (C[i] >= 0) {
			if (C[i] != n % 10) return 0;
		}
		n /= 10;
	}
	return 1;
}

int main()
{
	int i, s, c, K, M, ans;

	scanf("%d%d", &N, &M);
	for (i = 0; i < N; ++i) C[i] = -1;
	for (i = 0; i < M; ++i) {
		scanf("%d%d", &s, &c);
		if (C[N-s] < 0) C[N-s] = c;
		else if (C[N-s] != c) goto NG;
	}
	if (N == 1 && C[0] <= 0) { puts("0"); return 0; }
	if (N == 1) i = 1, K = 10;
	else if (N == 2) i = 10, K = 100;
	else i = 100, K = 1000;
	for ( ; i < K; ++i) {
		if (check(i)) {
			printf("%d\n", i);
			return 0;
		}
	}
NG:	puts("-1");
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;

    int field[5][n];
    memset(field, 0, sizeof(field));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 5; j++) {
	cin >> field[j][i];
      }
    }

    int ans = 0;
    int memo[5][n];
    while (true) {
      bool change = false;
      for (int y = 0; y < n; y++) {
	int l, r;
	l = r = -1;
	for (int x = 0; x < 5-1; x++) {
	  while (field[x][y] != 0 && field[x][y] == field[x+1][y] && x+1 < 5) {
	    if (l == -1) {
	      l = x;
	      r = x+1;
	    }else {
	      r = x+1;
	    }
	    x++;
	  }
	  // std::cout << "(" << x << "," << y << ") = " << l << " " << r << std::endl;
	  if (r-l+1 >= 3) {
	    for (int i = l; i <= r; i++) {
	      ans += field[i][y];
	      change = true;
	      field[i][y] = 0;
	    }
	  }
	  l = r = -1;
	}
      }
      if (!change) break;

      memset(memo, 0, sizeof(memo));
      for (int x = 0; x < 5; x++) {
	int cnt = 0;
	for (int y = n-1; y >= 0; y--) {
	  cnt += field[x][y] == 0;
	  memo[x][y] = cnt;
	}
      }

      for (int x = 0; x < 5; x++) {
	for (int y = n-1; y >= 0; y--) {
	  if (field[x][y] == 0) continue;
	  if (memo[x][y] == 0) continue;
	  field[x][y+memo[x][y]] = field[x][y];
	  field[x][y] = 0;
	}
      }

    }
    std::cout << ans << std::endl;
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
using namespace std;
vector<int>a[100004];
int V[100003][11],v[100004],d[100003],clr[100003],c[100003],z[100003];
void color(int v,int d,int c,int p)
{
    if(V[v][d]==1)return ;
    if(z[v]==0){clr[v]=c;z[v]=1;}

    for(int i=0;i<=d;i++)V[v][d]=1;
    if(d==0)return ;
    for(int j=0;j<a[v].size();j++)
    {
        if(a[v][j]!=p)
        {
            color(a[v][j],d-1,c,v);
        }
    }
}
int main()
{
    ios;
    int n,m,q;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        cin>>v[i]>>d[i]>>c[i];
    }
    for(int i=q;i>=1;i--)
    {
        color(v[i],d[i],c[i],0);
    }
    for(int i=1;i<=n;i++)cout<<clr[i]<<endl;


}


Measured memory_bytes: 12792
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
typedef  long long ll;

int main() {
	ll n = 0, s = 0;
	ll count = 0;
	bool kiyomaru = false;
	std::vector<int> v;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> s;
		v.push_back(s);
	}
	v.push_back(0);
	if (v[0] != 0) {
		std::cout << -1 << std::endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		count += v[i];
		if (v[i + 1] == v[i] + 1) {
			count -= v[i];
		}
		if (v[i + 1] - v[i] > 1) {
			std::cout << -1 << std::endl;
			return 0;
		}
	}
	std::cout << count << std::endl;
}


Measured memory_bytes: 2032
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int d ;
    cin >> d ;
    vector<int> c (26,0) ;
    for (int i = 0; i < 26; i++)
    {
        cin >> c.at(i) ;
    }
    vector<vector<int> > s(d,vector<int>(26)) ;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26 ; j++)
        {
            cin >> s.at(i).at(j) ;
        }
        
    }
    vector<int>ans(0) ;
    for (int i = 0; i < d; i++)
    {
        int num = 1 ;
        int temp = s.at(i).at(0) ;
        for (int j = 0; j < 26; j++)
        {
            if (temp < s.at(i).at(j))
            {
                temp = s.at(i).at(j) ;
                num = j+1 ;
            }
            
        }
        ans.push_back(num) ;
    }
    for (int i = 0; i < d; i++)
    {
        cout << ans.at(i) << endl ;
    }
    
}

Measured memory_bytes: 3684
N = int(input())
A = [int(a) for a in input().split()]

print(*A)
for i in range(1, N):
    j = i-1
    key = A[i]
    while j >= 0 and key <= A[j]:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print(*A)


Measured memory_bytes: 5980
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	cout<<(ll)((n - m) * 100 + m * 1900)*pow(2, m) << endl;
}


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

long long m[200005];
//long long in[200005];

int main()
{
    long long n;
    cin >> n;
    long long a[n];
    long long mx = 0;
    for (long long i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
        //in[m[a[i]]]++;
        mx = max(mx, a[i]);
    }
    long long ans = 0;
    for (long long k = 1; k <= mx; k++) {
        if (m[k]) {
            ans += (m[k] - 1) * m[k] / 2;
        }
    }
    for (long long k = 1; k <= n; k++) {
        if (m[a[k - 1]] > 1) {
            long long x = ans;
            long long u = m[a[k - 1]];
            x -= u * (u - 1) / 2;
            x += (u - 1) * (u - 2) / 2;
            cout << x << "\n";
        }
        else cout << ans << "\n";
    }
}


Measured memory_bytes: 4736
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    Map<Character, Character> map1 = new HashMap<>();
    Map<Character, Character> map2 = new HashMap<>();
    String ans = "Yes";
    for(int i = 0; i < S.length(); i++){
      char c1 = S.charAt(i);
      char c2 = T.charAt(i);
      if(map1.containsKey(c1)){
        if(map1.get(c1) != c2){
          ans = "No";
          break;
        }
      }else if(map2.containsKey(c2)){
        if(map2.get(c2) != c1){
          ans = "No";
          break;
        }
      }
      map1.put(c1, c2);
      map2.put(c2, c1);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 28912
a,b,c=map(int,input().split())
ans=0
[a,b,c]=sorted([a,b,c],reverse=True)
d,e,f=a%2,b%2,c%2
if d==e and e==f:
  case=0
  print((2*a-b-c)//2)
elif (d!=e or d!=f) and e==f:
  case=1
  print((2*a-b-c)//2)
else:
  case=2
  print(1+((a+1)*2-1-b-c)//2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mp make_pair
#define int long long

const int N = 1e6+2;
int a[N], cnt=0, nxt[N];
void solve_case()
{
    int n,x,i,j;
    cin >> n;
    for(i=1; i<=n; i++) cin >> a[i];
    for(i=1; i<=n; i++) nxt[a[i]]++;
    for(i=1; i<=n; i++)
    {
        int pos = 1;
        for(j=2; j*j<=a[i]; j++)
        {
            if(a[i]%j) continue;
            if(nxt[j] || nxt[a[i]/j])
            {
                pos = 0;
                break;
            }
        }
        if(nxt[1]-(a[i]==1) > 0) pos = 0;
        if(nxt[a[i]]-1) pos = 0;
        //cout << i << " " << a[i] << " "  << pos << "\n";
        cnt += pos;
    }
    cout << cnt << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int T = 1;
    //cin >> T;
    while(T--)
    {
        solve_case();
    }
    return 0;
}


Measured memory_bytes: 12980
import collections as co
n,m=map(int,input().split())
l=[]
for i in range(n):
    j,*k=map(int,input().split())
    l.extend(k)
count_num=0
for p,q in co.Counter(l).items():
    if q==n:count_num+=1
print(count_num)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    for(unsigned int i=0;i<s.size();i++)
    {
        char x=s[i];
        cout<<string(1,'A'+(n+x-13)%26);
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;

long long MOD = 1e9 + 7;

void dfs(int thisNode, int parent, vector<vector<int>>& graph, vector<int>& c) {
    for (auto nextNode : graph[thisNode]) {
        if (nextNode == parent) {
            continue;
        }
        c[nextNode] += c[thisNode];
        dfs(nextNode, thisNode, graph, c);
    }
}

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

    int n, q;
    cin >> n >> q;
    vector<vector<int>> graph(n, vector<int>());

    for (size_t i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--; // 0 indexed
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    vector<int> c(n, 0);
    for (size_t i = 0; i < q; i++)
    {
        int p, x;
        cin >> p >> x;
        p--; // 0 indexed

        c[p] += x;
    }

    // 根から足しこむ
    dfs(0, -1, graph, c);

    for (auto result : c) {
        cout << result << " ";
    }
    return 0;
}

Measured memory_bytes: 29696
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

float x[10];
int u[10];
int n;

int main()
{
	FAST;

	cin >> n;
	rep(i,n) {
		string t;
		cin >> x[i] >> t;
		if (t == "JPY") u[i] = 1;
		if (t == "BTC") u[i] = 380000;
	}

	float ans = 0;
	rep(i,n) {
		ans += (float)x[i] * (float)u[i];
	}
	cout << ans <<"\n";

	return 0;
}

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

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

    int A[n], B[n];
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }
    sort(A, A + n);
    sort(B, B + n);
    
    int cnt = 0, idx = n - 1;
    bool f = true;
    while(true){
        if(f and idx >= 0){
            h -= B[idx];
            if(idx >= 1 and B[idx - 1] <= A[n - 1]) f = false;
            else idx--;
        }else{
            cnt += (h + A[n - 1] - 1)/ A[n - 1];
            break;
        }
        cnt++;
        if(h <= 0) break;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0;i<x; i++)
typedef long long  ll;
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  
  int ans=0;
  for(int i=1;i<N;i++){
  	ans+=N-i;
  }
  for(int j=1;j<M;j++){
  	ans+=M-j;
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void ABC094D();

int main()
{
	ABC094D();
	fflush(stdout);
	return 0;
}

static void ABC094D()
{
	int N;
	getint(N);

	LLONG maxa = 0;
	std::set<LLONG> an;
	for (int i = 0; i < N; i++) {
		LLONG ai;
		getint(ai);
		an.insert(ai);
		maxa = std::max(maxa, ai);
	}
	LLONG goal = maxa / 2LL;
	LLONG smaller = 0;
	auto target = an.lower_bound(maxa / 2LL);
	if (*target == maxa) {
		smaller = *(--an.lower_bound(maxa / 2LL));
	}
	else {
		smaller = *target;
		if (abs(goal - *target) > abs(goal - *(--target))) {
			smaller = *(target);
		}
	}
	printf("%lld %lld\n", maxa, smaller);
}


Measured memory_bytes: 8400
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define SET(a,c) memset(a,c,sizeof(a))
#define PB push_back
using namespace std;

const int MAX_N = 1e6;
const int INF = 0x3f3f3f3f;

int dp[MAX_N], dp_odd[MAX_N];

void solve(int n)
{
	vector<int> m;

	SET(dp, INF);
	SET(dp_odd, INF);
	
	REP(i, MAX_N) {
		m.PB((i + 1) * (i + 2) * (i + 3) / 6);
		if (m.back() > MAX_N) break;
	}
	
	dp[0] = 0; dp_odd[0] = 0;
	REP(i, m.size()) {
		REP(j, n + 1) {
			if (j < m[i]) continue;
			dp[j] = min(dp[j], dp[j - m[i]] + 1);
			if (m[i] % 2) dp_odd[j] = min(dp_odd[j], dp_odd[j - m[i]] + 1);
		}
	}	
}

int main()
{
	int n;
	solve(MAX_N);
	while (1) {
		scanf("%d", &n);
		if (!n) break;
		printf("%d %d\n", dp[n], dp_odd[n]);
	}

	return 0;
}

Measured memory_bytes: 8868
#include <cstdio>
#include <vector>
using namespace std;

int read_int() {
	int x;
	scanf("%d", &x);
	return x;
}

typedef long long i64;
const i64 MOD = 998244353;

int main() {

	const int N = read_int();
	const int S = read_int();
	vector<int> AS(N);
	for(int i = 0; i < N; i++) {
		AS[i] = read_int();
	}

	vector<vector<i64>> dp(N * 2);
	for(auto& d : dp) {
		d.resize(S + 1, 0);
	}

	if(AS[0] <= S) {
		dp[0][AS[0]] = 1;
	}

	for(int pos = 1; pos < N; pos++) {
		const int a = AS[pos];
		for(int i = 1; i <= S - a; i++) {
			dp[pos][i + a] = (dp[pos - 1][i] + dp[pos - 1 + N][i]) % MOD;
		}
		for(int i = 1; i <= S; i++) {
			dp[pos + N][i] = (dp[pos - 1][i] + dp[pos - 1 + N][i]) % MOD;
		}
		if(a <= S) {
			dp[pos][a] = pos + 1;
		}
	}

	i64 ans = 0;
	for(int pos = 0; pos < N; pos++) {
		ans = (ans + dp[pos][S] * (N - pos)) % MOD;
	}

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

	return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;


int main(){
  int n;
  cin >> n;
  int mi = 10010, ma = -1;
  rep(i, 0, n){
    int p;
    cin >> p;
    ma = max(ma, p);
    mi = min(mi, p);
  }
  cout << ma-mi << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
 vector<int> x(5);
 rep(i,5) cin>>x[i];
 rep(i,5){
    if(x[i]==0) {
      cout<<i+1<<endl;
    return 0;
  } 
  }
return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int64_t A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  
  if(V<=W){
    cout<<"NO"<<endl;
  }
  else if(A<B && V>W){
    if((long double)(B-A)/(V-W)<=T){
      cout<<"YES"<<endl;
    }
    else if((long double)(B-A)/(V-W)+1>T){
      cout<<"NO"<<endl;
    }
  }
  else if(A>B && V>W){
    if((long double)(A-B)/(V-W)<=T){
      cout<<"YES"<<endl;
    }
    else if((long double)(A-B)/(V-W)+1>T){
      cout<<"NO"<<endl;
    }
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n)
{
    KAKA
    vl h(n);
    pragi(0,n)
    {
        cin>>h[i];
    }
    vector<ll> dp(n);
    tie(dp[n-1],dp[n-2]) = MT(0,llabs(h[n-1] - h[n-2]));
    pragk(n-3,0)
    {
      dp[k] = min((llabs(h[k] - h[k+1]) + dp[k+1]),(llabs(h[k] - h[k+2]) + dp[k+2]));
    }
    cout<<dp[0]<<"\n";
}
int main()
{
    KAKA
    ll n;
    cin>>n;
    Compute(n);

}

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

int main() {
	string S;
	cin >> S;
	vector<char>w(S.size());
	int n = 0;
	for (int i = 0;i < S.size();i++) {

		if (S[i] == 'B') {
			if (n != 0) {
				w[n - 1] = '\0';
				n--;
			}
		}
		else {
			w[n] = S[i];
			n++;
		}
	}
	for (int i = 0;i < n;i++) {
		cout << w[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int N, C; cin >> N >> C;
	vector<vector<int>> imos(30, vector<int>(101010, 0));
	rep(i, 1, N)
	{
		int s, t, c; cin >> s >> t >> c;
		--s; --c;
		++imos[c][s];
		--imos[c][t];
	}
	rep(i, 0, C - 1)rep(j, 1, 100010) imos[i][j] += imos[i][j - 1];
	rep(i, 0, C - 1)rep(j, 0, 100010)if (imos[i][j] > 0)imos[i][j] = 1;
	int ans = 0;
	rep(i, 0, 100010)
	{
		int count = 0;
		rep(j, 0, C - 1) count += imos[j][i];

		ans = max(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 14196
def Input(b, f, rn, h):
    A[b][f][rn] += h

def Output():
    for b in range(4):
        for f in range(4):
            for rn in range(10):
                if f < 3:
                    print(' ' + str(A[b][f][rn]), end = '')
                if f == 3 and b != 3:
                    print('##', end = '')
            if b == 3 and f == 3:
                break
            print()

n = int(input())

A = [[[0 for rn in range(10)] for f in range(3)] for b in range(4)]

for idx in range(n):
    R = input().split()
    B = int(R[0]) - 1
    F = int(R[1]) - 1
    RN = int(R[2]) - 1
    H = int(R[3])
    Input(B, F, RN, H)
Output()

Measured memory_bytes: 7732
#!/usr/bin/python3

def search(i, fc):
    cur = i
    while fc[cur] != cur:
        cur = fc[cur]

    #fc[i] = cur
    return cur

def union(i, j, fc, fcn):
    if fcn[i] > fcn[j]:
        fc[j] = i
        fcn[i] += fcn[j]
    else:
        fc[i] = j
        fcn[j] += fcn[i]
        

(n, m, k) = map(int, input().split())

dfn = [ 0 for i in range(n + 1) ]
tbn = [ 0 for i in range(n + 1) ]
fc = [ i for i in range(n + 1) ]
fcn = [ 1 for i in range(n + 1) ]

for i in range(m):
    (a, b) = map(int, input().split())
    dfn[a] += 1
    dfn[b] += 1
    ag = search(a, fc)
    bg = search(b, fc)
    if ag != bg:
        union(ag, bg, fc, fcn)

for i in range(k):
    (c, d) = map(int, input().split())
    if search(c, fc) == search(d, fc):
        tbn[c] += 1
        tbn[d] += 1

#print('fc', fc)
#print('fcn', fcn)
#print('dfn', dfn)
#print('tbn', tbn)
        
print(' '.join((str(fcn[search(i, fc)] - dfn[i] - tbn[i] - 1) for i in range(1, n + 1))))
    


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

int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n)cin>>d[i];
    sort(d.begin(),d.end());
    cout<<d[n/2]-d[n/2-1];

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <set>
#include <map>
#define ll long long
using namespace std;


map<int,char> val;

int main() {
    ll N,M;
    cin>>N>>M;
    string A,B;
    cin>>A>>B;
    
    ll L = (N*(M/__gcd(N,M)));
    
    
    // 0,a,2a,...
    // 0,b,2b,...
    
    
    int p1=0;
    int p2=0;
    
    
    
    for(int i=0;i<N;i++) {
        val[i*(L/N)]=A[i];
    }
    
    bool ok = true;
    for(int j=0;j<M;j++) {
        int pos = j*(L/M);
        if (val.find(pos)!=val.end() && val[pos] != B[j]) {
            ok=false;
        }
    }
    
    if (ok) {
        cout << L << endl;
    } else {
        cout << -1 << endl;
    }
    
}

Measured memory_bytes: 4736
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
typedef long long ll;

int
main(int arg, char *argv[])
{
  char s[200000];
  scanf("%s", s);
  int f = 0, l = strlen(s) - 1, cnt = 0, flag = 0;
  while(l - f >= 0){
    if(s[f] == 'x' && s[l] != 'x'){
      f++;
      cnt++;
    }
    else if(s[f] != 'x' && s[l] == 'x'){
      l--;
      cnt++;
    }
    else if(s[l] == s[f]){
      f++;
      l--;
    }
    else{
      printf("-1\n");
      return 0;
    }
  }
  
  printf("%d\n", cnt);

  return 0;
}
 


Measured memory_bytes: 256
import numpy as np
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))
rd = [(0,1,0), (1,0,1)]
move_records = []
if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            if i == H-1 and j == W-1:
                continue
            if i == H-1 and j == W-2:
                # import ipdb; ipdb.set_trace()
                if (field[H-1][W-1] + field[H-1][W-2]) % 2 != 0:
                    continue
                else:
                    field[H-1][W-2] -= 1
                    field[H-1][W-1] += 1
                    move_records.append([i+1,j+1,i+1,j+2])
            elif j != W-1:
                field[i][j] -= 1
                field[i][j+1] += 1
                move_records.append([i+1,j+1,i+1,j+2])
            else:
                field[i][j] -= 1
                field[i+1][j] += 1
                move_records.append([i+1,j+1,i+2,j+1])
M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))

Measured memory_bytes: 38824
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
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; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int n, m;
vector<vector<int>> G;
vector<bool> visited;
int ans = 0;
int cnt = 0;

void dfs(int v) {
    bool all_visited = true;
    rep(i,n) {
        if (!visited[i]) all_visited = false;
    }
    if (all_visited) {
        ans++;
        return;
    }

    for (int u : G[v]) {
        if (visited[u]) continue;
        visited[u] = true;
        dfs(u);
        visited[u] = false;
    }
    return;
}

int main() {
    cin >> n >> m;
    G.resize(n); visited.resize(n);
    visited[0] = true;
    int u,v;
    rep(i,m) {
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(0);

    cout << ans << endl;

}

Measured memory_bytes: 3488
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	llong n; cin >> n;
	vector<llong> h;
	llong ans = 0;

	h.resize(n);
	loop(i, n)
	{
		cin >> h[i];
	}

	llong h_max = h[0];
	loop(i, n)
	{
		if (h[i] < h_max)
			ans++;

		h_max = max(h[i], h_max);
	}

	cout << n-ans;
	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;

void Main() {
  string s;
  cin >> s;
  int K;
  cin >> K;

  forr(c, s) {
    if (c == 'a') continue;
    int n = ('z' - c) + 1;
    if (K >= n) {
      K -= n;
      c = 'a';
    }
  }
  K %= 26;

  char &las = s[SZ(s)-1];
  las += K;

  cout << s << endl;
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


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

 int main()
 {
     string strang;
     getline(cin, strang);

     if(strang.size() > 2)
     {
         for(int i = 2; i > -1; i--)
         {
             cout << strang[i];
         }
     } else {
         for (int i = 0; i < 2; i++)
         {
             cout << strang[i];
         }
     }
 }


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main(void)
{
  unsigned short *A, *B;
  
  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  
  for(i=0;i<=VMAX;i++) C[i] = 0;
  
  for(i=0;i<n;i++) {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  
  for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];
  
  for(j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for(i=1;i<=n;i++) {
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 9720
import sys
def S(): return sys.stdin.readline().rstrip()

def Main():
    s = S()
    n = len(s)
    times = 10**100
    ans = [0]*n
    i = 0
    while i<n:
        if s[i]=='L':
            i += 1
            continue
        save = [i]
        while s[i+1]!='L':
            i += 1
            save.append(i)
        flg = save.pop()
        ans[flg] += 1
        for j in range(len(save)):
            tmp = save.pop()
            ans[flg+abs(flg-tmp)%2] += 1
        i += 1
    
    i = n-1
    while 0<=i:
        if s[i]=='R':
            i -= 1
            continue
        save = [i]
        while s[i-1]!='R':
            i -= 1
            save.append(i)
        flg = save.pop()
        ans[flg] += 1
        for j in range(len(save)):
            tmp = save.pop()
            ans[flg-abs(flg-tmp)%2] += 1
        i -= 1
    print(*ans)
    return

if __name__=='__main__':
    Main()

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

int main(){
  int N; cin>>N;
  int ans=0;
  for(int i=1;i<=N;i++){
    int A; cin>>A;
    if(i%2&&A%2) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()


ll calc(vll B, ll b) {
	ll ans = 0;
	rep(i, B.size()) ans += abs(b - B[i]);
	return ans;
}

int main() {

	ll N;
	cin >> N;
	vll A(N), B(N);
	rep(i, N) {
		cin >> A[i];
		B[i] = A[i] - (i + 1);
	}

	sort(all(B));
	ll ave = B[N / 2];

	cout << min(calc(B, ave), calc(B, ave + 1)) << endl;

}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  int m,k;
  cin>>m>>k;
  if(k>=(1<<m)||(m==1&&k==1)){
    cout<<-1<<endl;
    return 0;
  }
  if(k==0){
    for(int i=0;i<1<<m;i++){
	 if(i)cout<<" ";
	 cout<<i<<" "<<i;
    }
    cout<<endl;
    return 0;
  }
  vector<int> ans;
  for(int i=1;i<1<<m;i++){
    if(k==i)continue;
    ans.pb(i);
  }
  ans.pb(k);
  for(int i=(1<<m)-1;i>=1;i--){
    if(k==i)continue;
    ans.pb(i);
  }
  ans.pb(0);
  ans.pb(k);
  ans.pb(0);
  for(int i=0;i<ans.size();i++){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

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

#define X first
#define Y second

const int N=1e6+10;
const int inf=1e9;
const int MOD=1e9+7;


ll cal(int xa,int ya,int xb,int yb,int xc,int yc){
    ll sa=1LL*xa*ya,sb=1LL*xb*yb,sc=1LL*xc*yc;
    return max(max(abs(sa-sb),abs(sb-sc)),abs(sc-sa));
}
int main(){
    int n,m;
    cin>>n>>m;
    ll ans=min(1LL*(n%3>0)*m,1LL*(m%3>0)*n);
    ans=min(ans,cal(n/3,m,n-n/3,m/2,n-n/3,m-m/2));
    ans=min(ans,cal((n+2)/3,m,n-(n+2)/3,m/2,n-(n+2)/3,m-m/2));
    ans=min(ans,cal(n,m/3,n/2,m-m/3,n-n/2,m-m/3));
    ans=min(ans,cal(n,(m+2)/3,n/2,m-(m+2)/3,n-n/2,m-(m+2)/3));
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(void) {
	
	int a,b,c;
	cin >> a >> b >> c ;
	if(a + b == c || b + c == a || c + a == b) 
			cout << "Yes" << endl;
	else
			cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

l = []
pre = ""
cnt = 0
for x in a:
    if pre == x:
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1
        pre = x

l.append(cnt)
l = l[1:]

print( sum(list(map(lambda x: x//2, l))) )

Measured memory_bytes: 38384
#include <iostream>
#include <sstream>
#include <bitset>
#include <vector>
using namespace std;

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

  bool ans = true;
  for (int i = 0; i < N - 1; i++){
    if(a[i]<a[i+1])
      a[i + 1]--;
    else if (a[i]!=a[i+1])
      ans = false;
  }

  if(ans)
    cout << "Yes";
  else
      cout << "No";
}

Measured memory_bytes: 640
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

string s;
int K;

void init()
{
}

void solve()
{
    set<string> ss;
    int l = s.size();
    REP(i, l){
        FOR(j, 1, l-i+1){
            string sub = s.substr(i, j);
            if(ss.size() > K){
                auto it = ss.begin();
                advance(it, K-1);
                if(sub >= *it) break;
            }
            ss.insert(s.substr(i, j));
        }
    }
    auto it = ss.begin();
    advance(it, K-1);
    cout << *it << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s >> K;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
// In the name the Allah the Most Merciful.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;

int main(void)
{
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    for(auto &x : v){
        scanf("%d",&x);
    }
    vector<int>dp(n , INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){

        for(int j :{i+1 , i+2}){

            if(j<n){

                dp[j] = min(dp[j] , dp[i]+abs(v[i]-v[j]));
            }
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1024
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"YES\n"
#define no cout<<"NO\n"

#define MOD 998244353
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vvi dp(600,vi(600));
	dp[0][0]=1;
	loop(x,1,m+1)for(int i=n-1;i>=0;i--)rep(j,512)if(dp[i][j]){
		(dp[i+1][j^x]+=dp[i][j])%=MOD;
	}
	int out=0;
	rep(i,n+1)if(dp[i][m]){
		int a=(n-i)/2,b=dp[i][m];
		(out+=b*nCr(a+m,a)%MOD)%=MOD;
	}
	cout<<out<<endl;
}








Measured memory_bytes: 13436
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  String s = sc.next();
	  char [] str = s.toCharArray();
	  int c=0;
out:	  for(int i=0;i<str.length-1;i++) {
	    	   for(int j=i+1;j<str.length;j++) {
	    		   if(str[i]==str[j]) {
	    			   c++;
	    			   break out;
	    		   }
	    	   }
	  }

	 if(c==0)System.out.print("yes");
	 else System.out.print("no");
	 sc.close();
    }
}

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

int MAX_DP = 18000;
int CENTER = 9000;
bool dp[3002][18000];
bool dp2[3002][18000];

int main()
{
	int N;
	cin >> N;
	int Ai[N];
	rep(i, N) {
		cin >> Ai[i];
	}
	int count = 0;
	while (true) {
		bool allEven = true;
		rep(i, N) {
			if (Ai[i] & 1) {
				allEven = false;
				break;
			}
			Ai[i] = Ai[i] / 2;
		}
		if (!allEven) {
			break;
		}
		count += 1;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256