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

const static std::string days[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
const static int months[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    int cnt;
    int month, day;
    int startofMonths[12];
    cnt = 0;
    for (int i = 0; i < 12; i++) {
        startofMonths[i] = cnt;
        cnt += months[i];
    }
    std::cin >> month >> day;
    while (month != 0) {
        cnt = startofMonths[month-1];
        cnt += day -1;
        std::printf("%s\n", days[cnt % 7].c_str());
        std::cin >> month >> day;
    }
    return 0;
}



Measured memory_bytes: 3048
#include<bits/stdc++.h>
typedef long long ll;
const int maxn = int(2e5) + 7;
int n, q, a, b, x[maxn];
ll sum[maxn], f[maxn], ans, inf = 0x7f7f7f7f7f7f7f7f;

struct BitTree {
    ll cost[maxn];
	BitTree() { memset(cost, 0x7f, sizeof(cost)); }
    void update(int pos, ll v) {
        for (; pos <= n; pos += pos & (-pos)) cost[pos] = std::min(cost[pos], v);
    }
    ll query(int x) {
        ll ret = inf;
        for (; x; x -= x & (-x)) ret = std::min(ret, cost[x]);
        return ret;
    }
} tree[2];

void insert(ll v, int pos) {
    tree[0].update(pos, v - pos);
    tree[1].update(n - pos + 1, v + pos);
}

int main() {
    scanf("%d%d%d%d", &n, &q, &a, &b);
    for (int i = 1; i <= q; i++) scanf("%d", x + i);
    for (int i = 2; i <= q; i++) sum[i] = sum[i - 1] + abs(x[i] - x[i - 1]);
    ans = sum[q] + std::min(abs(a - x[1]), abs(b - x[1]));
    insert(abs(a - x[1]), b), insert(abs(b - x[1]), a);
    for (int i = 2; i <= q; i++) {
        f[i - 1] = std::min(tree[0].query(x[i]) + x[i], tree[1].query(n - x[i] + 1) - x[i]) + sum[i - 1];
        ans = std::min(ans, f[i - 1] + sum[q] - sum[i]);
        insert(f[i - 1] - sum[i], x[i - 1]);
    }
    printf("%lld", ans);
	return 0;
}

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

const int N=1e+4+1;
int f[N],n;
int main()
{
	cin>>n;
	for(int i=1;i<=min(n,100);i++)
		for(int j=1;j<=min(n,100);j++)
			for(int k=1;k<=min(n,100);k++)
			{
				int a=i*i+j*j+k*k+i*j+k*j+i*k;
				if(a<=n)
					f[a]++;
			}
	for(int i=1;i<=n;i++)
		cout<<f[i]<<"\n";
}



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

int main(){
	
	int n;
	cin >> n;
	
	int a[n];
	int ans[n];
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	
	ans[1] = abs(a[0]-a[1]);
	ans[2] = min(abs(a[2]-a[0]),abs(a[1]-a[0])+abs(a[2]-a[1]));
	
	for(int i = 3;i < n;i++){
		ans[i] = min(ans[i-1]+abs(a[i]-a[i-1]),abs(a[i]-a[i-2])+ans[i-2]);
	}
	
	cout << ans[n-1];
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
INF=10**9
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()

def main():
    N=int(input())
    R,C=[0]*N,[0]*N
    A=[0]*(N+1)
    for i in range(N):
        A[i],A[i+1]=map(int,input().split())
    dp=[[INF]*N for _ in range(N)]
    dp[0]=[0]*N
    for i in range(N):
        for j in range(N-1-i):
            for k in range(i+1):
                dp[i+1][j]=min(dp[i+1][j],dp[i-k][j]+dp[k][i+1-k+j]+A[j]*A[j+i+1-k]*A[j+i+2])
    print(dp[-1][0])

if __name__ == '__main__':
    main()



Measured memory_bytes: 5684
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n,m;
int main() {
	cout << fixed << setprecision(18);
	cin>>n>>m;
    cout<<6-n-m;
	
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

string s;

ll func(ll beforeans, ll from, ll till){
  ll ans = 0;
  for(ll i = from; i<= till; i++){
    ans *= 10;
    ans += (s[i] - '0');
  }
  ans = abs(ans - 753);

  return min(beforeans, ans);
}

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


  cin >> s;

  ll from = 0;
  ll till = 2;

  ll ans_num = 753;

  
  while(till <= s.size()-1){
    ans_num = func(ans_num, from, till);
    from ++;
    till ++;
  }

  cout << ans_num << endl;
  
  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>


using namespace std;


int get_digits(unsigned long x)
{
    int ret;
    if (x == 0)
        return 1;

    for (ret = 0; x > 0; x /= 10, ret++) ;
    return ret;
}


int main(void)
{
    unsigned long N;
    cin >> N;

    for (unsigned long i = sqrt(N) + 1; i >= 1; i--) {
        if (N % i == 0) {
            cout << get_digits(max(N / i, i)) << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認
 
int main(){
   ll X;
   cin >> X;
   if(X >= 30) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3592
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
					//多倍長整数/cpp_intで宣言
					//#include <boost/multiprecision/cpp_int.hpp>
					//
					//namespace mp = boost::multiprecision;


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string a, b, c;
	scans(a); scans(b); scans(c);
	int turn = 0;
	while (true) {
		if (turn == 0) {
			if (a.length() == 0) {
				printf("A\n");
				return 0;
			}
			turn = a[0] - 'a';
			a.erase(a.begin());
		}
		else if (turn == 1) {
			if (b.length() == 0) {
				printf("B\n");
				return 0;
			}
			turn = b[0] - 'a';
			b.erase(b.begin());
		}
		else {
			if (c.length() == 0) {
				printf("C\n");
				return 0;
			}
			turn = c[0] - 'a';
			c.erase(c.begin());
		}
	}

	Please AC;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 5e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,Q;
char s[MAXN];
int sum[MAXN<<2];

void build(int l,int r,int rt){
    if(l==r){
        sum[rt]=1<<(s[l]-'a');
//        printf("s[%d] = %c, sum = %d\n",l,s[l],sum[rt]);
        return;
    }
    int mid=(l+r)>>1;
    build(lson);
    build(rson);
    sum[rt]=sum[ls]|sum[rs];
}

int __ul,__ur,__uw;
void update(int l,int r,int rt){
    if(l==r){
        sum[rt]=1<<__uw;
        return;
    }
    int mid=(l+r)>>1;
    if(__ul<=mid) update(lson);
    else update(rson);
    sum[rt]=sum[ls]|sum[rs];
}

int __ql,__qr;
int query(int l,int r,int rt){
    if(__ql<=l&&r<=__qr){
        return sum[rt];
    }
    int mid=(l+r)>>1;
    if(__qr<=mid) return query(lson);
    else if(__ql>mid) return query(rson);
    else return query(lson)|query(rson);
}

void work(){
    scanf("%d",&N);
    scanf("%s",s+1);
    build(1,N,1);
//    printf("sum[1] = %d\n",sum[1]);
    scanf("%d",&Q);
    while(Q--){
        int a; scanf("%d",&a);
        if(a==2){
            scanf("%d%d",&__ql,&__qr);
            int x=query(1,N,1);
            int ans=0;
//            printf("x = %d\n",x);
            for(int i=0;i<26;i++){
                if(x&(1<<i)) ans++;
            }
            printf("%d\n",ans);
        }
        else{
            char op[10];
            scanf("%d%s",&__ul,op);
            __uw=op[0]-'a';
            __ur=__ul;
            update(1,N,1);
        }
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}








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

ll f(ll c){
    if(c==1) return 1;
    else return 2*f(c/2)+1;
}

int main(){
    ll h;
    cin>>h;
    ll cnt=f(h);
    cout<<cnt<<endl;
}

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

using namespace std;

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

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, k, x[100000];

int main(int argc, char **argv) {
	cin >> n >> k;
	REP(i, n) cin >> x[i];
	ll res = INF;
	REP(i, n-k+1) {
		if (x[i] <= 0 && x[i+k-1] <= 0) res = min(res, -x[i]);
		if (x[i] <= 0 && x[i+k-1] > 0) res = min(res, min(-x[i]*2 + x[i+k-1], x[i+k-1]*2 - x[i]));
		if (x[i] > 0) res = min(res, x[i+k-1]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n;
char s[N];

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    int ans=0;
    rep(i,1,n) 
    {
        if (s[i]=='P') putchar('P');
        else putchar('D');
    }
    return 0;
}

Measured memory_bytes: 3920
N, M, V, P = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort.reverse
start, last = 0, A.size - 1
head = -1

while start <= last do
    x = (start + last) / 2
    
    if A[x] >= A[P - 1]
        head = x
        start = x + 1
        next
    elsif A[x] + M < A[P - 1]
        last = x - 1
        next
    end

    barriers = A[P - 1, x - (P - 1)]
    a_x = A[x] + M

    acceptable_vote_num = barriers.map { |a| a_x - a }.inject(:+)

    if M * (barriers.size - (N - V)) <= acceptable_vote_num
        head = x
        start = x + 1
    else
        last = x - 1
    end
end

p head + 1

Measured memory_bytes: 22204
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

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

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	
	map< int, int > cntD;
	for_(i,0,N) {
		int d;
		cin >> d;
		cntD[d]++;
	}
	
	int M;
	cin >> M;
	
	map< int, int > cntT;
	for_(i,0,M) {
		int t;
		cin >> t;
		cntT[t]++;
	}
	
	for (auto p : cntT) {
		if (cntD[p.first] < p.second) {
			puts("NO");
			return 0;
		}
	}
	
	puts("YES");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 18944
// フェルマーの小定理
package main

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

const (
	m = 998244353
)

func mpow(x, y int) int {
	result := 1
	for y != 0 {
		if y&1 == 1 {
			result *= x
			result %= m
		}
		x *= x
		x %= m
		y >>= 1
	}
	return result
}

var (
	fac []int
)

func initFactorialTable(n int) {
	fac = make([]int, n+1)
	fac[0] = 1
	for i := 0; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % m
	}
}

func mcomb(n, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	return (fac[n] * mpow(fac[n-k], m-2) % m) * mpow(fac[k], m-2) % m
}

func main() {
	defer flush()

	N := readInt()
	M := readInt()
	K := readInt()

	initFactorialTable(N)

	result := 0
	for i := 0; i < K+1; i++ {
		t := M * mcomb(N-1, i)
		t %= m
		t *= mpow(M-1, N-1-i)
		t %= m
		result += t
		result %= m
	}
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 3440
import collections

n=int(input())

if n==1:
    print(0)
    exit()
    
a=[]
M=n
p=2

while p <= M**0.5:
    while n%p ==0:
        a.append(p)
        n = n//p       
        if n==1:
            break
    p += 1
if n!=1:
    a.append(n)
if len(a)==0:
    a.append(M)

c=collections.Counter(a)

x=c.most_common()

ans=0
for i in x:
    ans += int((-1+(1+8*i[1])**0.5)/2)

print(ans)


 

Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    while(cin>>n){
        cout<<n/3<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX = 101;
int sit[MAX];
int empty[MAX];
int Q,W;

void init(){
  fill(sit,sit+MAX,-1);
  fill(empty,empty+MAX,0);
}

void check(){
  if(sit[0] == -1) empty[0] = 1;
  else empty[0] = 0;

  for(int i = 1; i <= W; i++){
    if(sit[i] == -1) empty[i] = empty[i-1]+1;
    else empty[i] = 0;
  }
}

int sleepable(int n){
  for(int i = 0; i < W; i++)
    if(empty[i] == n) return i-n+1;

  return -1;
}

void sleep(int n, int f, int t){
  for(int i = f; i < f+t; i++)
    sit[i] = n;
}

void wake(int n){
  for(int i = 0; i < W; i++)
    if(sit[i] == n) sit[i] = -1;

}

int main(){
  while(cin >> W >> Q && W+Q){
    init();
    for(int i = 0; i < Q; i++){
      check();
      char c;
      cin >> c;
      if(c == 's'){
	int n,h,pos;
	cin >> n >> h;
	if((pos = sleepable(h)) != -1){
	  sleep(n,pos,h);
	  cout << pos << endl;
	}else cout << "impossible" << endl;
      }else{
	int n;
	cin >> n;
	wake(n);
      }
    }
    cout << "END" << endl;
  }
  return 0;
}

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

int main() {

  int N, K;
  cin >> N;
  cin >> K;
  
  int d = 0;  
 
//  while (i < N) {
  
//    cout << i << "  " << f << endl;
    
  for (int i = 0; i < N; i++) {
    
    int x;
    cin >> x;
    
    if (x < K-x)
      d += x*2;
    
    else 
      d += (K-x)*2;
    
//    cout << d << endl;
    
  }
  

    cout << d << endl;
  
}


Measured memory_bytes: 256
N=int(input())
ans=[]
for i in range(1,99):
    if N>26**i:
        N-=26**i
    else:
        N-=1
        for l in range(i):
            key=(chr(ord("a")+(N%26)))
            N=int(N/26)
            ans.append(key)
        break
    
ans.reverse()
for i in range(len(ans)):
    print(ans[i],end="")

Measured memory_bytes: 61892
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a > b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a < b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	double N; cin >> N;
	double x = N * 25 / 27;
	int a = x / 1.0;
	int b = a + 1;
	int c = a - 1;
	if (a * 27 / 25 == N)cout << a << endl;
	else if (b * 27 / 25 == N)cout << b << endl;
	else if (c * 27 / 25 == N)cout << c << endl;
	else {
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] dlm = " ".ToCharArray();
            string[] data = Console.ReadLine().Split(dlm);

            int a = int.Parse(data[0]);
            int b = int.Parse(data[1]);
            int c = int.Parse(data[2]);
            int n = 0;

            for (int i = a; i <= b; i++)
            {
                if (c % i == 0)
                {
                    n += 1;
                }
            }

            Console.WriteLine(n);


        }
    }
}


Measured memory_bytes: 18024
#include<bits/stdc++.h>
#define itn int
#define For(a,b,c,t)  for(ri a=b;a<=c;a+=t)
#define ri register int
#define Memset(a,b)  memset(a,b,sizeof(a))
#define li long long
#define il inline
using namespace std;
string a,b;
int main()
{
	cin>>a;
	int l=a.size();
	b=a;
	//printf("\n");
	For(i,0,l-1,1)
	{
		if(b[i]=='b')
		  b[i]='d';
		else if(b[i]=='d')
		  b[i]='b';
		else if(b[i]=='q')
		  b[i]='p';
		else if(b[i]=='p')
		  b[i]='q';
		//printf("%c",b[i]);
	}
	//printf("\n");
	For(i,0,l-1,1)
	{
		if(a[i]!=b[l-1-i])
		{
			printf("No");
			exit(0);
		}
	}
	printf("Yes");
	return 0;
}

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

using namespace std;

int main(){
  vector<int> a(3);
  std::cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end(), greater<int>());
  std::cout << abs(a[1]-a[0]) + abs(a[2]-a[1]) << '\n';
  return 0;
}


Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [None] * D
for i in range(D):
    S[i] = list(map(int, input().split()))
lasts = [0] * 26
score = 0
for d in range(D):
    bs = None
    ba = None
    for t in range(26):
        s = S[d][t]
        s -= sum(C[i] * (d+1-l) for i, l in enumerate(lasts) if i != t)
        if bs is None or s > bs:
            bs = s
            ba = t
    score += bs
    lasts[ba] = d
    print(ba+1)

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

int main() {
    unsigned long int k;
    string s;

    cin >> k;
    cin >> s;
    
    if (s.length() > k) {
        cout << s.substr(0, k) + "..." << endl;
    } else {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
use proconio::input;

fn main() {
    input!{
        x: u128,
    }
    let mut a = 100;
    let mut c = 0;
    while a < x {
        a += (a as f64 * 0.01) as u128;
        c += 1;
    }
    println!("{}", c);
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> x(3);
	x[0] = a; x[1] = b; x[2] = c;
	sort(x.begin(), x.end());
	cout << x[0] << " " << x[1] << " " << x[2] << endl;
	return 0;
}


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

int main() {
	int n,ans = 0;
	vector<int>a(3);
	cin >> a[0]>>a[1]>>a[2]>>n;
	sort(a.rbegin(), a.rend());
	for (int i = 0; i <= n / a[0]; i++) {
		int hoge = n - a[0] * i;
		if (hoge == 0) {
			ans++;
			continue;
		}
		for (int j = 0; j <= hoge/a[1]; j++) {
			int fuga = hoge - a[1] * j;
			if (hoge == 0) {
				ans++;
				continue;
			}
			if (fuga % a[2] == 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

const int LIMIT = 100000;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(LIMIT * 2);
    int x, y;
    REP(i, n) {
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y + LIMIT);
        g[y + LIMIT].push_back(x);
    }
    vector<bool> visited(LIMIT * 2, false);
    x = 0;
    y = 0;
    function<void (int)> dfs = [&](int u) {
        if (u < LIMIT) {
            x++;
        } else {
            y++;
        }
        visited[u] = true;
        for (auto v : g[u]) {
            if (!visited[v]) {
                dfs(v);
            }
        }
    };

    ll a = -n;
    REP(i, LIMIT * 2) {
        if (!visited[i]) {
            x = 0;
            y = 0;
            dfs(i);
            a += (ll)x * y;
        }
    }

    cout << a << endl;
}


Measured memory_bytes: 11008
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 21;
char grid[N][N];
int dist[N][N][N][N];
int tmp[N][N];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m;
inline bool valid(int x, int y) {
	return x <= n and 1 <= x and y <= m and 1 <= y and grid[x][y] == '.';
}
int BFS(int x, int y, int tx, int ty) {
	queue <PII> q;
	q.push(mp(x, y));
	tmp[x][y] = 0;
	while (!q.empty()) {
		auto u = q.front(); q.pop();
		int c = tmp[u.first][u.second];
		rep(i, 4) {
			int nx = u.first + dx[i],
				ny = u.second + dy[i];
			if (valid(nx, ny) && tmp[nx][ny] == -1) {
			//	cerr << "updating " << nx << ny << endl;; 
				tmp[nx][ny] = c + 1;
				if (nx == tx and ny == ty) goto OVER;
				q.push(mp(nx, ny));
			}
		}
	}
	OVER:
	dist[x][y][tx][ty] = tmp[tx][ty];
	dist[tx][ty][x][y] = tmp[tx][ty];
	return tmp[tx][ty];
}
int main() {
	cin >> n >> m;
	repn(i, n) scanf("%s", grid[i] + 1);
	int ans = 0;
	repn(x1, n) repn(y1, m) repn(x2, n) repn(y2, m) {
		if (dist[x1][y1][x2][y2]) continue;
		if (!valid(x1, y1) || !valid(x2, y2)) continue;
		memset(tmp, -1, sizeof(tmp));
		ans = max(ans, BFS(x1, y1, x2, y2));
	}
	cout << ans << endl;
	return 0;
}
/*
###
#..
###*/ 


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b,c;
  cin >> a;
  b =a/500;
  a -= b*500;
  a /= 5;
  cout << b*1000+a*5;
  return 0;
}
  /*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


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

int main(){
  string s;
  cin >> s;
  int i, j;
  i = 0; j = s.size() - 1;
  int count = 0;
  while(i < j){
    if(s.at(i) == s.at(j)){
      i++;
      j--;
    }else if(s.at(i) == 'x'){
      count++;
      i++;
    }else if(s.at(j) == 'x'){
      count++;
      j--;
    }else{
      cout << -1;
      return 0;
    }
  }
  cout << count;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == s[i + 1]) {
			ans++;
		}
	}
	cout << min(n - 1, ans + k * 2);

	return 0;
}


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

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

using namespace std;

int main()
{
    int N; cin >> N;
    vector<int> a(N);

    REP(i, N)
        cin >> a[i];

    vector<long> a_sum(N);

    REP(i, N)
    {
        if( i == 0 )
            a_sum[i] = a[0];
        else
            a_sum[i] = a_sum[i - 1] + a[i];
    }

    long min_diff = abs( a_sum[0] - (a_sum[N - 1] - a_sum[0]) );
    REP(i, N - 1)
    {
        long snuke = a_sum[i];
        long remain = a_sum[N - 1] - snuke;

        min_diff = min(min_diff, abs(snuke - remain));
    }

    cout << min_diff << endl;

    return 0;
}


Measured memory_bytes: 2560
a = [int(s) for s in input().split()]
if a[1] > a[2]:
    print("0")
elif a[1] == a[2]:
    print("1")
elif a[0] == 1:
    print("0")
else:
    mini = a[2] + a[1] * (a[0] - 1)
    maxi = a[1] + a[2] * (a[0] - 1)
    print(int(maxi) - int(mini) + 1)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
const int inf=1e9;
int a[maxn],b[maxn];
int main()
{
    int n,i,flag,x1,x2,m,q,x,y,w,ans,cost;
    //freopen("text.in","r",stdin);
    scanf("%d%d%d",&n,&m,&q);
    x1=inf; x2=inf;
    for (i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        x1=min(x1,a[i]);
    }
    for (i=1;i<=m;i++) {
        scanf("%d",&b[i]);
        x2=min(x2,b[i]);
    }
    ans=x1+x2;
    for (i=1;i<=q;i++) {
        scanf("%d%d%d",&x,&y,&w);
        cost=a[x]+b[y]-w;
        ans=min(ans,cost);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int a,b,c; cin >> a>>b>>c;
    cout << min({a+b,b+c,c+a}) << endl;
}


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

int main(){
  vector<long long> dp(301,0);
  dp[0] = 1;
  for(int j = 1; j <= 17; ++j){
    for(int i = 0; i+j*j < 301; ++i){
      dp[i+j*j] += dp[i];
    }
  }
  int n;
  while(cin >> n, n){
    cout << dp[n] << endl;
  }
}



Measured memory_bytes: 2996
#include<iostream>
#include<sstream>

using namespace std;

int toNumber(string s){
	int n=0,m=1;
	for(int i=0;i<s.length();i++){
		int k=1;
		switch(s.at(i)){
			case 'm':
				k*=10;
			case 'c':
				k*=10;
			case 'x':
				k*=10;
			case 'i':
				n+=k*m;
				m=1;
				break;
			default:
				if('0'<=s.at(i)&&s.at(i)<='9'){
					m=s.at(i)-'0';
				}
				break;
		}
	}
	return n;
}

string d="mcxi";

string fromNumber(int n){
	ostringstream s;
	for(int i=0;i<d.length();i++){
		int m=1;
		for(int j=0;j<d.length()-i-1;j++)m*=10;
		if(n/m>0){
			if(n/m>1){
				char c=n/m+'0';
				s << c;
			}
			s << d.at(i);
			n=n%m;
		}
	}
	return s.str();
}

int main(){
	ostringstream out;

	int n;
	string a,b;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		int na,nb;

		na=toNumber(a);
		nb=toNumber(b);

		out << fromNumber(na+nb) << endl;
	}


	cout << out.str();
	return 0;
}

Measured memory_bytes: 1272
# -*- coding: utf-8 -*-
"""
B - Polygon
https://atcoder.jp/contests/abc117/tasks/abc117_b

"""
import sys


def solve(L):
    rest, longest = L[:-1], L[-1]
    return ['No', 'Yes'][sum(rest) > longest]


def main(args):
    _ = int(input())
    L = map(int, input().split())
    ans = solve(sorted(L))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    int N;
    cin >>N;
    vector<int> A(N+1);
    vector<int>  B(N+1);
    vector<int>  C(N);
    for(int i = 1 ;i < N+1;i++){
        cin >> A[i];
    }
    for(int i = 1 ;i < N+1;i++){
        cin >> B[i];
    }
    for(int i = 1 ;i < N;i++){
        cin >> C[i];
    }
    int ans = 0;
    for(int i = 1;i < N+1;i++){
        ans += B[A[i]];
        if(i >= 2){
            if(A[i] - A[i-1] == 1){
                ans += C[A[i-1]];
            }
        }
    }
    cout << ans << endl;
}   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    if(A[0] == 5 and A[1] == 5 and A[2] == 7) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

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

int main(int argc, char *argv[]) {
	int a = 0;
	int b = 0;
	int c = 0;

	std::cin >> a;
	std::cin >> b;
	std::cin >> c;

	std::cout << (((b - a) == (c - b)) ? "YES" : "NO") << std::endl;
	return 0;
}


Measured memory_bytes: 256
//26
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<numeric>
#include<sstream>

using namespace std;

int t;

string sad(string a,string b){
  stringstream ss;
  ss<<atoi(a.c_str())+atoi(b.c_str());
  return ss.str();
}

vector<string> dfs(string n,vector<string> v){
  if(n.empty()){
    if(t>=atoi(accumulate(v.begin(),v.end(),string("0"),sad).c_str())){
      return v;
    }else{
      return vector<string>();
    }
  }else{
    vector<string> r;
    int m=-1;
    for(int i=0;i<n.size();i++){
      vector<string> nv=v;
      nv.push_back(n.substr(0,i+1));
      vector<string> rv=dfs(n.substr(i+1),nv);
      if(!rv.empty()){
	int ca=atoi(accumulate(rv.begin(),rv.end(),string("0"),sad).c_str());
	if(ca==m){
	  r.push_back("1");
	  r.push_back("-1");
	}else if(ca>m){
	  m=ca;
	  r=rv;
	}
      }
    }
    return r;
  }
}

int main(){
  string n;
  while(cin>>t>>n,t||n!="0"){
    if(t==atoi(n.c_str())){
      cout<<t<<' '<<t<<endl;
    }else{
      vector<string> v=dfs(n,vector<string> ());
      if(v.empty()){
	cout<<"error"<<endl;
      }else if(*v.rbegin()=="-1"){
	cout<<"rejected"<<endl;
      }else{
	cout<<atoi(accumulate(v.begin(),v.end(),string("0"),sad).c_str())<<' ';
	for(int i=0;i<v.size();i++){
	  cout<<v[i]<<((i==v.size()-1)?'\n':' ');
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1252
import Control.Monad (replicateM)
import Data.List (minimum, scanl', sort, sortBy)

main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine 
  as    <- map read . words <$> getLine
  print $ f n x as

f :: Int -> Int -> [Int] -> Int
f n x as
  | x < minas = 0
  | x <= sas  = length $ takeWhile (<= x) $ scanl' (+) b bs
  | x <  2 * sas = length $ takeWhile (<= (2*sas - x)) $ scanl' (+) c cs
  | otherwise    = 0
  where
    minas = minimum as
    sas = sum as
    as'@(b:bs) = sort as
    sa@(c:cs)  = sortBy (flip compare) as

Measured memory_bytes: 1020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CheckNumber(number, limitLow, limitHigh) ( (number) >= (limitLow) && (number) <= (limitHigh) )

typedef struct {
	int** matrix;
	int rowSize;
	int columnSize;
	int* rowSum;
	int* columnSum;
	int sumSum;
} Matrix;

void InputNumber(int* number, int limitLow, int limitHigh);
void InputNumber2(int* number1, int* number2, int limitLow, int limitHigh);
void CreateMatrix(Matrix* matrix, int rowSize, int columnSize);
void SumMatrix(Matrix* matrix);
void PrintMatrix(Matrix* matrix);
void FreeMatrix(Matrix* matrix);

int main(void) {
	int r;
	int c;
	int idr;
	int idc;
	Matrix matrix;

	InputNumber2(&r, &c, 1, 100);

	CreateMatrix(&matrix, r, c);
	for (idr = 0; idr < matrix.rowSize; idr++) {
		for (idc = 0; idc < matrix.columnSize; idc++) {
			InputNumber((*(matrix.matrix + idr) + idc), 0, 100);
		}
	}

	SumMatrix(&matrix);

	PrintMatrix(&matrix);

	FreeMatrix(&matrix);
}

void InputNumber(int* number, int limitLow, int limitHigh) {
	int x;
	do {
		scanf("%d", &x);
	} while (!CheckNumber(x, limitLow, limitHigh));
	*number = x;
}

void InputNumber2(int* number1, int* number2, int limitLow, int limitHigh) {
	int tmp1;
	int tmp2;
	do {
		scanf("%d %d", &tmp1, &tmp2);
	} while (!CheckNumber(tmp1, limitLow, limitHigh) || !CheckNumber(tmp2, limitLow, limitHigh));
	*number1 = tmp1;
	*number2 = tmp2;
}

void CreateMatrix(Matrix* matrix, int rowSize, int columnSize) {
	int idx;

	matrix->matrix = (int**)malloc(sizeof(int*) * rowSize);
	for(idx = 0; idx < rowSize; idx++) {
		*(matrix->matrix + idx) = (int*)malloc(sizeof(int) * columnSize);
	}
	matrix->rowSize = rowSize;
	matrix->columnSize = columnSize;

	matrix->rowSum = (int*)malloc(sizeof(int) * rowSize);
	memset(matrix->rowSum, 0, sizeof(int) * rowSize);

	matrix->columnSum = (int*)malloc(sizeof(int) * columnSize);
	memset(matrix->columnSum, 0, sizeof(int) * columnSize);

	matrix->sumSum = 0;
}

void SumMatrix(Matrix* matrix) {
	int idr;
	int idc;

	for (idr = 0; idr < matrix->rowSize; idr++) {
		for (idc = 0; idc < matrix->columnSize; idc++) {
			int number = *(*(matrix->matrix + idr) + idc);
			*(matrix->rowSum + idr) += number;
			*(matrix->columnSum + idc) += number;
			matrix->sumSum += number;
		}
	}
}

void PrintMatrix(Matrix* matrix) {
	int idr;
	int idc;

	for (idr = 0; idr < matrix->rowSize; idr++) {
		for (idc = 0; idc < matrix->columnSize; idc++) {
			printf("%d ", *(*(matrix->matrix + idr) + idc));
		}
		printf("%d\n", *(matrix->rowSum + idr));
	}

	for (idc = 0; idc < matrix->columnSize; idc++) {
		printf("%d ", *(matrix->columnSum + idc));
	}
	printf("%d\n", matrix->sumSum);
}

void FreeMatrix(Matrix* matrix) {
	int idr;
	for (idr = 0; idr < matrix->rowSize; idr++) {
		free(*(matrix->matrix + idr));
	}
	free(matrix->matrix);
	free(matrix->rowSum);
	free(matrix->columnSum);
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    ll dp[n+1][4][4][4];
    rep(i,n+1)rep(j,4)rep(k,4)rep(l,4)dp[i][j][k][l]=0;
    rep(j,4){
        rep(k,4){
            rep(l,4){
                dp[3][j][k][l]=1;
                if(j==2&&k==3&&l==0)dp[3][j][k][l]=0;
                if(j==2&&k==0&&l==3)dp[3][j][k][l]=0;
                if(j==3&&k==2&&l==0)dp[3][j][k][l]=0;
            }
        }
    }
    repl(i,3,n){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    rep(m,4){
                        if(m==2&&l==3&&j==0)continue;
                        if(m==2&&l==3&&k==0)continue;
                        if(m==2&&k==3&&j==0)continue;
                        if(m==2&&l==0&&k==3)continue;
                        if(m==3&&l==2&&k==0)continue;
                        dp[i+1][m][l][k]+=dp[i][l][k][j];
                        dp[i+1][m][l][k]%=MOD;
                    }
                }
            }
        }
    }
    ll ans=0;
    rep(j,4)rep(k,4)rep(l,4){ans+=dp[n][j][k][l];ans%=MOD;}
    cout <<ans <<endl;
}

Measured memory_bytes: 256
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
//#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
/*---------------------------------------------------------------------*/
#define FAST        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ff          first
#define ss          second
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define psb         push_back
#define psf         push_front
#define ppb         pop_back
#define ppf         pop_front
#define all(x)      x.begin(),x.end()
#define TESTS       int test;cin>>test;for(int tcase=1;tcase<=test;tcase++)
#define ordered_set tree< int, null_type, less_equal< int >, rb_tree_tag, tree_order_statistics_node_update>
/*--------------------------------------------------------------------*/
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v)
{ os << '{'; string sep;for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &v)
{ os << '{'; string sep;for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &v)
{ os << '{'; string sep;for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p)
{ return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define cc(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define OK      cerr << "LINE "<<__LINE__<<" :"<<endl;
#define ccm(x)  cerr << "(" << #x <<") : "<<endl;for(auto i : x){ cerr<<"["<<i.ff<<"] = "<<i.ss<<endl;}
#else
#define cc(...)
#define OK
#define ccm(x)
#endif
/*---------------------------------------------------------------------*/
#define MXN (int)(1e6)
#define MOD (ll)(1e9+7)
#define INF (ll)(4e18)
#define inf (int)(4e9)

int main()
{
    FAST
    int n;cin>>n;
    map <int,int> mp;
    ll sum=0ll;
    for(int i=1;i<=n;i++)
    {
        int h;cin>>h;
        sum+= mp[i-h];
        mp[i+h]++;
    }
    cout<<sum<<endl;
    return 0;
}
/*--------------------------------------------------------------------*/
/*
>Check Corner Cases (n==1 or T==1)
>Overflow issues?
>LB / UB !!not found!! check?
>slow multi-set operations?try without multi-set
*/
/*--------------------------------------------------------------------*/
/* ---INPUT---
--------(1)------


-------(2)-------



-------(3)-------


-------(4)-------



--------------
*/
/*-----------------------MEHEDI HASAN,CSE-JU--------------------------*/



Measured memory_bytes: 20612