akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct _node {
	int key;
	struct _node **parent;
	struct _node *left;
	struct _node *right;
} node;

typedef void(*FUNCP)(node *);

node *allocNode(int key) {
	node *p = (node *)malloc(sizeof(node));
	p->key = key;
	p->parent = NULL;
	p->left = NULL;
	p->right = NULL;

	return p;
}

void terminate(node *p) {
	if (p == NULL) return;
	terminate(p->left);
	terminate(p->right);
	free(p);
}

node *insert(node *p, node *c) {
	if (p == NULL) return c;
	if (c->key < p->key) {
		p->left = insert(p->left, c);
		p->left->parent = &(p->left);
	}
	else {
		p->right = insert(p->right, c);
		p->right->parent = &(p->right);
	}
	return p;
}

node *find(node *p, int key) {
	if (p != NULL && p->key != key) {
		if (key < p->key) p = find(p->left, key);
		else p = find(p->right, key);
	}
	return p;
}

void delete(node **root, int key) {
	node *next, *p;
	node **right, **pp;

	p = find(*root, key);
	if (p == NULL) return;
	pp = p->parent;
	if (p->right == NULL)	next = p->left;
	else if (p->left == NULL)	next = p->right;
	else {
		right = p->right->parent;
		while ((*right)->left != NULL)
			right = (*right)->left->parent;
		next = *right;
		*right = next->right;
		next->left = p->left;
		next->right = p->right;
	}
	if (pp != NULL)	*pp = next; else *root = next;
	if (next != NULL) next->parent = pp;
	free(p);
}

void inParse(node *p) {
	if (p == NULL) return;
	inParse(p->left);
	printf(" %d", p->key);
	inParse(p->right);
}

void preParse(node *p) {
	if (p == NULL) return;
	printf(" %d", p->key);
	preParse(p->left);
	preParse(p->right);
}

void dump(node *p, FUNCP funcp) {
	(funcp)(p);
	printf("\n");
}

int main() {
	int n, i, key;
	char order[7];
	node *p;
	node *root = NULL;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", order);
		switch (order[0])
		{
		case 'i':
			scanf("%d", &key);
			p = allocNode(key);
			root = insert(root, p);
			break;
		case 'p':
			dump(root, &inParse);
			dump(root, &preParse);
			break;
		case 'f':
			scanf("%d", &key);
			if (find(root, key) != NULL) printf("yes\n");
			else printf("no\n");
			break;
		case 'd':
			scanf("%d", &key);
			delete(&root,key);
			break;
		}
	}
	terminate(root);

	return 0;
}



Measured memory_bytes: 20484
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) { 
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x); 
    int ry = find(y); 
    if (rx == ry) return; 
    if (sizes.at(rx) < sizes.at(ry)) swap(rx,ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);    
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x){
    return sizes.at(find(x));
  }

  int num_of_connected_components(){
    int ret = 0;
    for(int i = 0; i < par.size(); i++){
      if(find(i) == i) ret++;
    }
    return ret;
  }
};

typedef pair<ll,ll> P;

int main(){
  ll n,k,l; cin >> n >> k >> l;
  UnionFind road(n), line(n);
  REP(i,k){
    ll p,q; cin >> p >> q;
    p--; q--;
    road.unite(p,q);
  }
  REP(i,l){
    ll r,s; cin >> r >> s;
    r--; s--;
    line.unite(r,s);
  }
  map<P,ll> mp;
  REP(i,n) mp[{road.find(i), line.find(i)}]++;
  
  REP(i,n){
    cout << mp[{road.find(i), line.find(i)}];
    if(i==n-1) cout << endl;
    else cout << " ";
  }
}



Measured memory_bytes: 15104
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

using namespace std;

int vs[103];

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }
  int mini = 1e9;
  REP(i, n) {
    int s1 = 0;
    int s2 = 0;
    REP(j, n) {
      if(j <= i) {
        s1 += vs[j];
      } else {
        s2 += vs[j];
      }
    }
    mini = min(mini, abs(s1-s2));
  }
  cout << mini << endl;
  return 0;
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if (a+b >= a-b && a+b >= a*b)
  {
    cout << a + b;
  }
  else if (a-b >= a+b && a-b >= a*b)
  {
    cout << a - b;
  }
  else if (a*b >= a-b && a*b >= a+b)
  {
    cout << a * b;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[1000001];int sz;}Template;
struct T{int fact[1000001],inv[1000001];};
Template P;struct T MODINV;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x)P.Primes[P.sz++]=x;
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
static inline void init(void)
{
  MODINV.fact[0]=1;rep(i,MAX)MODINV.fact[i+1]=1l*MODINV.fact[i]*(i+1)%MOD;
  MODINV.inv[MAX]=MPow(MODINV.fact[MAX],MOD-2);
  rep(i,MAX)MODINV.inv[MAX-1-i]=1l*MODINV.inv[MAX-i]*(MAX-i)%MOD;
}
int main(void)
{
  int N=IN(),A=0,flag=1,invsum=0,k=0,lcm=1,x=0,temp[10000],box[168]={};ready();init();
  rep(i,N)
  {
    A=IN();invsum=(invsum+1l*MODINV.fact[A-1]*MODINV.inv[A]%MOD)%MOD;
    rep(j,168){x=0;while(A%P.Primes[j]==0){A/=P.Primes[j];if(box[j]<++x)box[j]=x;}}
    if(A!=1){rep(j,k){if(temp[j]==A)flag=0;continue;}if(flag)temp[k++]=A;}flag=1;
  }
  rep(i,168){rep(j,box[i]){lcm=1l*lcm*P.Primes[i]%MOD;}}
  rep(i,k){lcm=1l*lcm*temp[i]%MOD;}
  x=1l*lcm*invsum%MOD;return printf("%d\n",x),0;
}

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

int match(char a, char b){
    
    if(a==b || a=='?'||b=='?'){
        return true;
    }else{
        return false;
    }
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    string a,b,c;
    cin>>a>>b>>c;
    ll A = a.length();
	ll B = b.length();
	ll C = c.length();
    bool ab[20000],ac[20000],bc[20000];
    rep(i,A){
        rep(j,B){
            if(!match(a[i],b[j])){
                ab[i-j+10000] = true;
            }
        }
    }
    rep(i,A){
        rep(j,C){
            if(!match(a[i],c[j])){
                ac[i-j+10000] = true;
            }
        }
    }
    rep(i,B){
        rep(j,C){
            if(!match(b[i],c[j])){
                bc[i-j+10000] = true;
            }
        }
    }
    ll M = 2000;
    ll ans = M*3;
    for (int i= -2*M;i<=2*M;i++){
        for(int j= -2*M;j<=2*M;j++){
            if(!ab[i+10000]&& !ac[j+10000]&&!bc[j-i+10000]){
                ll L = min(0,min(i,j));
                ll R = max(A,max(B+i,C+j));
                ans = min(ans,R-L);
            }
        }
    }

    cout<<ans<<"\n";

    return 0;
}

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

using namespace std;

using int64 = long long;
const int MAX_N = 100000;
const int INF = 1 << 30;

struct edge {
  int to, cost;

  operator int() { return to; }
};

vector< edge > g[MAX_N];
int sub[MAX_N], centroid_sz;
bool v[MAX_N];
vector< int > centroid;

int build_dfs(int idx, int par) {
  sub[idx] = 1;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    if(v[to]) continue;
    sub[idx] += build_dfs(to, idx);
  }
  return (sub[idx]);
}


void build_centroid(int idx, int par, const int all) {
  int connect = all - sub[idx];
  for(auto &to : g[idx]) {
    if(to == par) continue;
    if(v[to]) continue;
    build_centroid(to, idx, all);
    connect = max(connect, sub[to]);
  }
  if(connect < centroid_sz) {
    centroid_sz = connect;
    centroid.clear();
  }
  if(connect == centroid_sz) {
    centroid.emplace_back(idx);
  }
}

vector< int > get_centroid(int root) {
  centroid.clear();
  centroid_sz = INF;
  build_centroid(root, -1, build_dfs(root, -1));
  return (centroid);
}

int64 dfs(int idx, int64 dist, int par) {
  int64 ret = 0;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    ret += dfs(to, dist + to.cost, idx);
  }
  return ret + 2 * dist;
}

int main() {
  int N;
  cin >> N;
  for(int i = 1; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    g[a].emplace_back((edge) {b, c});
    g[b].emplace_back((edge) {a, c});
  }
  auto centroid = get_centroid(0);
  auto ret = dfs(centroid[0], 0, -1);
  int sub = INF;
  if(centroid.size() == 1) {
    for(auto &to : g[centroid[0]]) sub = min(sub, to.cost);
  } else {
    for(auto &to : g[centroid[0]]) if(to == centroid[1]) sub = to.cost;
  }
  cout << ret - sub << endl;
}


Measured memory_bytes: 12800
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N = I()
X = LMI()

p = sum(X) // N
ans1 = sum([(x - p) ** 2 for x in X])
ans2 = sum([(x - p - 1) ** 2 for x in X])
print(min(ans1, ans2))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  int l=0;
  cin>>s;
  for(int i=0;i<s.size()/2;++i){
    if(s[i]!=s[s.size()-i-1]){
      ++l;
    } 
  }
  cout<<l;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int pow(int x, int n) {
  if(n == 0) return 1;
  else return x * pow(x, n-1);
}

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

  int m = max({a, b, c});
  int s = a + b + c;

  cout << s - m + m * pow(2, k) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    x=1;y=1;
    while(x>0&&y>0){
        int a,b;
        cin>>a>>b;
        if(a==0&&b==0){
            break;
        }
        else{
            if(a>b){
                swap(a,b);
            }
            cout<<a<<' '<<b<<endl;
        }
        
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    ll s[n], t[m];

    rep(i, n) { cin >> s[i]; }
    rep(j, m) { cin >> t[j]; }

    ll dp[n + 1][m + 1];

    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i <= m; i++) {
        dp[0][i] = 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            } else {
                dp[i + 1][j + 1] =
                    (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[n][m] << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int arr[1111];
int main(void){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	sort(arr,arr+n);
	int tot = 0;
	for(int e=0;e<k;e++) tot += arr[e];
	cout << tot;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string K;
int d;
const int mod=1000000007;
ll dp[10001][2][101];
int main(){
    cin>>K>>d;
    int n=K.size();
    dp[0][0][0]=1;
    rep(i,n)rep(j,2)rep(k,d){
        int ulim=j?9:K[i]-'0';
        rep(l,ulim+1){
            dp[i+1][j||l<ulim][(k+l)%d]+=dp[i][j][k];
            dp[i+1][j||l<ulim][(k+l)%d]%=mod;
        }
    }
    ll ans=0;
    rep(i,2) ans+=dp[n][i][0];
    cout<<(ans-1+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 16000
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string a,b;
	bool ans = true;
	cin >> a >> b;
	rep(i, 0, a.size()) {
		if (a[i] != b[i])ans = false;
	}

	if (b.size() - a.size() != 1)ans = false;

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

Measured memory_bytes: 3624
s = gets.chomp.split("")
k = gets.to_i
as = ('a'..'z').to_a
alps = Hash[as.map.with_index{ |a,i| [a,i] }]
(0...s.size).each{ |i|
  v = alps[s[i]]
  c = (26 - v) % 26
  if c <= k
    k -= c
    s[i] = 'a'
  end
}
#$stderr.puts s,k
s[-1] = as[(alps[s[-1]] + k) % 26]
puts s.join("")

Measured memory_bytes: 12156
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and a[i+1]-1 == a[i]:
        ans += c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
let (n,m,q) = cin.triple
/// 111, 112, 113, 114
/// 222, 223, 224
/// 333, 334
/// 444

let X = (1...q).map {_ in cin.array}

var mmax = 0

func calc(_ A: [Int]) {
    var sum = 0
    for x in X {
        if A[x[1]-1] - A[x[0]-1] == x[2] {
            sum += x[3]
        }
    }
    mmax = max(mmax, sum)
}

func dfs(_ A: inout [Int]) {
    if A.count == n {
        calc(A)
        // print(A)
        return
    }

    let last = A.last ?? 1

    for v in (last...m) {
        A.append(v)
        dfs(&A)
        A.removeLast()
    }
}

var _A = [Int]()
dfs(&_A)

print(mmax)

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // 12 23 34 45
    static var quadro: (Int, Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!, Int(line[3])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

/// ヘルパー関数ライブラリ
/// https://github.com/ankurp/Dollar
/// https://github.com/ankurp/Cent
extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


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

int main() {
  int N, K; cin >> N >> K;
  vector<double> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  double ans = 0.0;
  double tmp = 0.0;
  for (int i = 0; i < K; i++) {
    tmp += (P.at(i) + 1) * P.at(i) / (2.0 * P.at(i));
  }
  ans = max(ans, tmp);
  for (int i = 0; i < N-K; i++) {
    double minus = (P.at(i) + 1) * P.at(i) / (2.0 * P.at(i));  // 引く
    double add = (P.at(i+K) + 1) * P.at(i+K) / (2.0 * P.at(i+K));
    tmp = tmp - minus + add;
    ans = max(ans, tmp);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<string>
#include<cctype>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    while (1) {
        string text;
        cin >> text;
        
        if ( text == "-" ) break;

        int shuf;
        cin >> shuf;
        rep (i, shuf) {
            int h;
            cin >> h;
            string a = text.substr(0, h);
            string del = text.substr(h, text.size() - h);
            text = del + a;            
        }
        cout << text << endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll k,n,i,a,b,c,r,m;
  cin>>k>>n;
  ll arr[n+1];
  for(i=1;i<=n;i++)
    cin>>arr[i];
  c=0;
  for(i=2;i<=n;i++)
  {
      a=arr[i]-arr[i-1];
      c=max(c,a);
      if(i==n)
      {
          a=(k-arr[i])+arr[1];
          c=max(a,c);
      }
  }
  c=k-c;
  cout<<c<<endl;
}


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


int main()
{
	int n, a[5001];
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		int maxseq = -100001;
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = 0; i + j < n; j++){
				sum += a[i + j];
				maxseq = max(maxseq, sum);
			}
		}
		cout << maxseq<<endl;
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i)
    std::cin >> a.at(i);

  int count = 0;
  for (int i = 1; i <= n; ++i) {
    if (i == a.at(a.at(i)) && a.at(i) == a.at(a.at(a.at(i))))
      ++count;
  }
  std::cout << count / 2 << std::endl;
}


Measured memory_bytes: 640
/* #region template */
#![allow(unused_imports)]
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n = io.ru();
    let m = io.r();
    let q = io.ru();
    let abcd: Vec<(usize, usize, isize, usize)> =
        repeat_with(|| (io.ru(), io.ru(), io.r(), io.ru()))
            .take(q)
            .collect();

    let mut a = [0isize; 11];
    a[0] = 1;
    let max = re(1, n, m, &abcd, &mut a);
    io.w(max);
}

fn re(
    i: usize,
    n: usize,
    m: isize,
    abcd: &Vec<(usize, usize, isize, usize)>,
    a: &mut [isize; 11],
) -> usize {
    if i <= n {
        let mut max = 0;
        for k in a[i - 1]..=m {
            a[i] = k;
            max = std::cmp::max(max, re(i + 1, n, m, abcd, a));
        }
        max
    } else {
        let mut sum = 0;
        for q in abcd {
            if a[q.1] - a[q.0] == q.2 {
                sum += q.3;
            }
        }
        sum
    }
}


Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	int INF = (int)1 << 50;
	vector<vector<int> > A(N, vector<int>(M, -INF));
	priority_queue<pair<int, pair<int, int> > > pq;
	int x, y, z;
	for (int i = 0; i < K; i++) {
		cin >> x >> y >> z;
		x--; y--;
		A[x][y] = z;
		pq.emplace(z, make_pair(x, y));
	}
	while (pq.size()) {
		x = pq.top().second.first;
		y = pq.top().second.second;
		z = pq.top().first;
		pq.pop();
		for (int i = x - 1; i <= x + 1; i++) {
			for (int j = y - 1; j <= y + 1; j++) {
				if (abs(i - x) + abs(j - y) == 1) {
					if (i >= 0 && i < N && j >= 0 && j < M) {
						if (A[i][j] == -INF) {
							A[i][j] = z - 1;
							pq.emplace(z - 1, make_pair(i, j));
						}
					}
				}
			}
		}
	}
	int res = 0;
	bool ok = true;;
	for (int x = 0; x < N; x++) {
		for (int y = 0; y < M; y++) {
			res += A[x][y];
			for (int i = x - 1; i <= x + 1; i++) {
				for (int j = y - 1; j <= y + 1; j++) {
					if (abs(i - x) + abs(j - y) == 1) {
						if (i >= 0 && i < N && j >= 0 && j < M) {
							if (abs(A[x][y] - A[i][j]) > 1) {
								ok = false;
							}
						}
					}
				}
			}
		}
	}
	if (ok) {
		cout << res << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main() {
    vector<int> a(101);
    int tmp;
    int maxv = 0;
    while (cin >> tmp) {
        a.at(tmp)++;
        maxv = max(maxv, a.at(tmp));
    }

    set<int> st;
    for (int i = 1; i < 101; i++) {
        if (a.at(i) == maxv)
            st.insert(i);
    }

    for (auto a : st) {
        cout << a << endl;
    }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    string s;
    if(a>=b) s="delicious";
    else if(b<=x+a) s="safe";
    else s="dangerous";
    cout << s << endl;
}


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


int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for(int i =1;i < n ;i++) {
		for(int j =1; j<= (n/i) ;j++) {
			if(i * j < n) cnt++;
			else break;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
    int x = 0;

    char S[9];
    scanf("%s", S);
    
    if (S[1] == 'B') {
        S[1] = 'R';
    } else {
        S[1] = 'B';
    }
    
    printf("%s\n", S);
    return 0;
}

Measured memory_bytes: 1644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int T;
int N,D;
int check(int val1, int val2){
    for (int i = 6; i >= 0; i--){
        int b1 = (val1 >> i) & 1;
        int b2 = (val2 >> i) & 1;
        if (b1 < b2){
            return true;
        }
        if (b1 > b2){
            return false;
        }
    }
    return true;
}
void solve(){
    cin >> N >> D;
    int sum = D;

    priority_queue<int, vector<int>, greater<int>> cookies;
    cookies.emplace(D);
    while (N--){
        if (N <= 0)break;
        int tmp = 0;
        int res = cookies.top();
        cookies.pop();
        // cout << "res = " << res << endl;
        for (int i = 0; i < 7; i++){
            if ((res & (1 << i))){//bit 1
            //pass
            }else{
                tmp |= 1 << i;
            }
        }
        sum -= res;
        sum += tmp + (tmp ^ res);
        cookies.emplace(tmp);
        cookies.emplace(tmp ^ res);
    }

    cout << sum << endl;
}
int main() {
    cin >> T;
    for (int i = 0; i < T; i++){
        solve();
    }

   return 0;
 }


Measured memory_bytes: 256
#!/usr/bin/env python3
from queue import Queue


def main(h, w, a):
    visited = [[False] * w for _ in range(h)]
    visited[0][0] = True
    #print(visited)
    cur = [[0, 0]]
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    cnt = 0
    dis = -1
    while len(cur) > 0:
        cnt += 1
        nex = []
        for pos in cur:
            for i in range(4):
                tx = pos[0] + dx[i]
                ty = pos[1] + dy[i]
                #print(tx, ty)
                if 0 <= tx < w and 0 <= ty < h and a[ty][tx] != '#' and  not visited[ty][tx]:
                    if tx == w - 1 and ty == h - 1:
                        dis = cnt
                    nex.append([tx, ty])
                    visited[ty][tx] = True
        #print(cur)
        #print(nex)
        cur = nex
    if dis < 0:
        print(-1)
        return
    tmp = 0
    for R in a:
        for c in R:
            if c == '#':
                tmp += 1
    ret = h * w - tmp - dis - 1
    print(ret)
    return

if __name__ == '__main__':
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    main(h, w, a)


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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

ll mem[3005][3005];
ll ara[3005];

ll dp(ll ara[], int i, int j)
{
    if (i > j)
    {
        return 0;
    }

    if (mem[i][j] != -1)
    {
        return mem[i][j];
    }

    mem[i][j] = max(ara[i] - dp(ara, i + 1, j), ara[j] - dp(ara, i, j - 1));

    return mem[i][j];
}

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

    memset(mem, -1, sizeof(mem));

    for (int i = 1; i <= n; i++)
    {
        cin >> ara[i];
    }

    cout << dp(ara, 1, n) << endl;

    return 0;
}

Measured memory_bytes: 74392
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    int N;
    string S;
    cin >> N >> S;
    ll r=0, g=0, b=0, mns=0;
    for(int i=0; i<N; ++i){
        if(S[i]=='R') ++r;
        else if(S[i]=='G') ++g;
        else ++b;
    }
    for(int i=1; i*2<N; ++i){
        for(int j=0; j+i*2<N; ++j){
            if(S[j]!=S[j+i] && S[j]!=S[j+i*2] && S[j+i]!=S[j+i*2]){
                ++mns;
            }
        }
    }
    cout << r*g*b-mns << endl;
    return 0;
}


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

using namespace std;

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

const int N = 1e5 + 100;
int a[N];

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

	ll ans = 0;
	ans += a[0] / 2;
	a[0] %= 2;
	for (int i = 1; i < n; i++){
		int x = min(a[i], a[i - 1]);
		ans += x;
		a[i] -= x;

		x = a[i] / 2;
		ans += x;
		a[i] -= 2 * x;
	}

	cout << ans << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> c(9);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x < 3200) c[x / 400]++;
		else c[8]++;
	}
	int ans = 0;
	for (int i = 0; i < 8; i++) {
		if (c[i] > 0)ans++;
	}
	if(ans!=0)cout << ans << " " << ans + c[8] << endl;
	else cout << 1 << " " << ans + c[8] << endl;

	return 0;
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, k, h, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> h;
		ans += h >= k;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,min;
    std::deque<int> deq;
    int long max = -9999999999;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    min = deq[0];
    
    for (int j=1;j<=n-1;j++) {
        //cout << j << " " << max << " " << min << endl;
        if (deq[j]-min>max) {
            max = (deq[j]-min);
        }
        if (min>deq[j]) {
            min = deq[j];
        }
    }
    cout << max << endl;
    //cout << min << endl;
}



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


int main() {
	string s;
	cin>>s;
	int an=0;
	for(int i=0;i<4;i++)
	{
		if(s[i]=='+')
		an+=1;
		else
		an-=1;
	}
  cout<<an<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <string>
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
    string S;
    
    int C[26];
    
    memset(C, 0, sizeof(C));
    
    while(getline(cin, S))
    {
        for(unsigned i = 0; i < S.size(); i++)
        {
            if(isalpha(S[i]))
            {
                if(S[i] < 91)
                {
                    C[S[i] - 65]++;
                }
                else
                {
                    C[S[i] - 97]++;
                }
            }
        }
    }
    
    for(int i = 0; i < 26; i++)
    {
        cout << (char)(i + 97) << " : " << C[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//エラトステネスの篩
bool is_prime[ 1000000 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}
int main()
{
	long long a,b,c,d;
  	cin>>a>>b>>c;
  	if(a-c>=0){
		cout<<a-c<<" "<<b<<endl;
    }
  	else{
		if(b-(c-a)>=0){
			cout<<0<<" "<<b-(c-a)<<endl;
        }
        else{
			cout<<0<<" "<<0<<endl;
        }    }
}


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

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

using namespace std;

int main(){
	int h,w,k; scanf("%d%d%d",&h,&w,&k);
	rep(i,h+1) rep(j,w+1) if(i*(w-j)+j*(h-i)==k) return puts("Yes"),0;
	puts("No");
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <deque>

using namespace std;

int n, a, b;

int main() {
	cin >> n >> a >> b;
	cout << min(n * a, b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b,c;
	cin>>a>>b>>c;
	a=abs(a);
if(a>0&&a/c>=b)
cout<<a-b*c<<endl;
else
{
long long int f=a/c;
a-=f*c;
b-=f;
if(b%2==0)
cout<<abs(a)<<endl;
else
cout<<min(abs(a+c),abs(a-c))<<endl;;
}
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];

int main()
{
    ll t;

    cin>>t;

    if(t==0)cout<<1<<endl;
    else cout<<0<<endl;

}


Measured memory_bytes: 3632
class UnionTree
  def initialize
    @tree = []
  end
  
  def root(a)
    fetch(a)
    return a if @tree[a] == a
    @tree[a] = root(@tree[a])
  end
  
  def union(a, b)
    return if root(a) == root(b)
    @tree[root(a)] = root(b)
  end
  
  private 
  
  def fetch(a)
    @tree[a] = a if @tree[a].nil?
  end
end

n, m = gets.chomp.split.map(&:to_i)
@a = [0] + gets.chomp.split.map(&:to_i)
count = 0

ut = UnionTree.new
m.times do
  x, y = gets.chomp.split.map(&:to_i)
  ut.union(x, y)
end

(1..n).each do |i|
  count += 1 if ut.root(@a[i]) == ut.root(i)  
end

puts count

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

int N,A,B;
int num;

vector<int> ans;

int main()
{
    scanf("%d%d%d",&N,&A,&B);

    if(A + B - 1 > N)
    {
        printf("-1\n");
        return 0;
    }

    if(A == 1)
    {
        if(B != N)printf("-1\n");
        else
        {
            for(int i = 0; i < B; i++)
            {
                printf("%d",N - i);
                if(i != B - 1)printf(" ");
            }printf("\n");
        }
        return 0;
    }

    num = N + 1;
    for(int i = 0; i < (N - B) / (A - 1); i++)
    {
        num -= A;
        for(int j = 0; j < A; j++)
        {
            ans.push_back(num + j);
        }
    }
    if(num < 0)
    {
        printf("-1\n");
        return 0;
    }
    if((N - B) % (A - 1))
    {
        num -= (N - B) % (A - 1) + 1;
        for(int i = 0; i < (N - B) % (A - 1) + 1; i++)
        {
            ans.push_back(num + i);
        }
    }
    num--;
    while(num >= 1)
    {
        ans.push_back(num);
        num--;
    }
    if(ans.size() > N)
    {
        printf("-1\n");
        return 0;
    }
    for(int i = 0; i < ans.size(); i++)
    {
        printf("%d",ans[i]);
        if(i != ans.size() - 1)printf(" ");
    }printf("\n");
    return 0;
}


Measured memory_bytes: 3440
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    IN(ll, S);
    vi A(N);
    REP(i, N)
    {
        if (i < K)
        {
            A[i] = S;
        }
        else if (S == 1e9)
        {
            A[i] = 1;
        }
        else
        {
            A[i] = 1e9;
        }
    }
    JOUT(ALL(A)) << endl;
}

Measured memory_bytes: 2048
#include<stdio.h>

int main (void){

    int MofY[12]={31,29,31,30,31,30,31,31,30,31,30,31};

    int month,day;
    int past;

    char weeks[7][16]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
    int w_num;

    int i,j;

    while(scanf("%d",&month),month){
        scanf("%d",&day);

        past=0;
        for(i=0;i<month-1;i++){
            past+=MofY[i];
        }
        past+=day;
        w_num=past%7;

        printf("%s\n",weeks[w_num]);
    }


    return 0;
}

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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;
    vector<int> sizes;

    Unionfind(int n) : par(n), sizes(n, 1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return sizes[root(x)];
    }

};

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> c(n-1);
    vector<int> s(n-1);
    vector<int> f(n-1);

    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

    rep(i, n) {
        int t = 0;
        for(int j = i; j < n-1; ++j) {
            if(t < s[j]) t = s[j];
            else if(t % f[j] == 0);
            else t = t+f[j]-(t%f[j]);
            t += c[j];
        }
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	ans := 1
	for i := 0; i < N; i++ {
		if ans*2 < ans+K {
			ans = ans * 2
		} else {
			ans = ans + K
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int n,t,a;
  cin>>n>>t>>a;
  vi h(n);
  rep(i,n)cin>>h[i];

  double diff=1000000;
  int ans=0;
  rep(i,n){
    double tmp=t-h[i]*0.006;
    double diff_tmp=abs(a-tmp);
    if(diff>diff_tmp){
      ans=i+1;
      diff=diff_tmp;
    }
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
import sys

H,W,A,B = map(int, input().split())

if A > -(-W//2) or B > -(-H//2):
	print("No")
	sys.exit()

orig_x = []
orig_y = []
for i in range(W):
	if i < A:
		orig_x.append(1)
		orig_y.append(0)
	else:
		orig_x.append(0)
		orig_y.append(1)

ans = []
for i in range(H):
	if i < B:
		ans.append(orig_x)
	else:
		ans.append(orig_y)

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end="")

Measured memory_bytes: 5492
#include <iostream>

using namespace std;

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H%h == 0 && W%w == 0){
        cout << "No" << endl;
    }else if(H%h != 0){
        cout << "Yes" << endl;
        int tmp = 1;
        while(tmp <= 500){
            tmp = tmp*h+1;
        }
        int large = (h-1)*tmp+1;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i+1)%h != 0) cout << tmp;
                else cout << -large;
                if(j != W-1) cout << ' ';
            }
            cout << endl;
        }
    }else{
        cout << "Yes" << endl;
        int tmp = 1;
        while(tmp <= 500){
            tmp = tmp*w+1;
        }
        int large = (w-1)*tmp+1;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((j+1)%w != 0) cout << tmp;
                else cout << -large;
                if(j != W-1) cout << ' ';
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1920