akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define plll pair<ll, pll>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
 
ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}
 
ll modinv(ll x){
	return modpow(x, MOD-2);
}
 
bool was_output = false;
template<class t>
void output(t x){
	if(was_output)cout << " ";
	was_output = true;
	cout << x;
}
 
void outendl(){
	was_output = false;
	cout << endl;
}
 
int main(){
	bool flag = false;
	int n;
	cin >> n;
	repa(i, 10){
		if(n%i==0&&n/i<10){
			flag = true;
			break;
		}
	}
	
	cout << (flag?"Yes":"No") << endl;
	return 0;
}
 


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


int main(){
    int k;
    cin >> k;
    
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[k-1] << endl;
}

Measured memory_bytes: 256
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
R,G,B,N = LI()
dp = [0]*(N+1)
dp[0] = 1
for x,i in itertools.product([R,G,B],range(N+1)):
    if i-x>=0:
        dp[i] += dp[i-x]
print(dp[-1])


Measured memory_bytes: 3188
n = int(raw_input())
A = map(int, raw_input().split())
if A[0] > 0:
    psep = A[0]
    psop = -1
    opop = abs(-1 - A[0])
    opep = 0
elif A[0] < 0:
    psep = 1
    psop = A[0]
    opep = abs(1-A[0])
    opop = 0
else:
    psep = 1
    psop = -1
    opep = 1
    opop = 1
for i in range(1, n):
    if i % 2 == 0:
        if psep + A[i] <= 0:
            opep += abs(1 - (psep + A[i]))
            psep = 1
        else:
            psep = psep + A[i]
        if psop + A[i] >= 0:
            opop += abs(-1 - (psop + A[i]))
            psop = -1
        else:
            psop += A[i]
    else:
        if psep + A[i] >= 0:
            opep += abs(-1 - (psep+A[i]))
            psep = -1
        else:
            psep += A[i]
        if psop + A[i] <= 0:
            opop += abs(1-(psop+A[i]))
            psop = 1
        else:
            psop = psop + A[i]
print min(opop, opep)

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

struct pos {
    int num;
    int x;
    int y;
} typedef p;

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

    vector<p> stu(n+1);
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;

        stu[i].num = i;
        stu[i].x = x;
        stu[i].y = y;
    }

    vector<p> check(m+1);
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;

        check[i].num = i;
        check[i].x = x;
        check[i].y = y;
    }

    for (int i = 1; i <= n; i++) {
        int minDst = 1e9;
        int minCheck = 0;
        for (int j = 1; j <= m; j++) {
            int dif = abs(stu[i].x - check[j].x) + abs(stu[i].y - check[j].y);
            if (dif < minDst) {
                minDst = dif;
                minCheck = check[j].num;
            }
        }
        cout << minCheck << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
C = []
tmp_b = -1
for _ in range(N):
  tmp_n = int(input())
  if tmp_n != tmp_b:
    C.append(tmp_n)
    tmp_b = tmp_n

SUM = 1
DP_dict = {}

for c in C:
  if c not in DP_dict.keys():
    DP_dict[c] = SUM
  else:
    SUM += DP_dict[c]
    DP_dict[c] = SUM

print(SUM % (10**9+7))

Measured memory_bytes: 29472
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    cout << 3*n*n << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 110;
char mps[N][N];
int dp[N][N],n,m;
int dfs(int x,int y){
    if(~dp[x][y]) return dp[x][y];
    if(x==n&&y==m) return dp[x][y]=0;
    dp[x][y]=N*N;
    if(x<n) dp[x][y]=min(dp[x][y],dfs(x+1,y)+(mps[x+1][y]=='#'&&mps[x][y]=='.'?1:0));
    if(y<m) dp[x][y]=min(dp[x][y],dfs(x,y+1)+(mps[x][y+1]=='#'&&mps[x][y]=='.'?1:0));
    return dp[x][y];
}
int main(){
    scanf("%d %d",&n,&m); memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;++i) scanf("%s",mps[i]+1);
    printf("%d\n",dfs(1,1)+(mps[1][1]=='#'?1:0));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> a(N);
  int sum = 0;
  rep(i, N) {
    cin >> a[i];
    sum += a[i];
  }

  int ave1 = std::floor((double)sum / N);
  int ave2 = std::ceil((double)sum / N);

  long long cost1 = 0;
  long long cost2 = 0;
  rep(i, N) {
    cost1 += std::abs(a[i] - ave1) * std::abs(a[i] - ave1);
    cost2 += std::abs(a[i] - ave2) * std::abs(a[i] - ave2);
  }

  cout << std::min(cost1, cost2) << endl;

  return 0;
}


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

int main() {
  int N, K;
  double m, S=0;
  cin >> N >> K;
  for (int i=1; i<=N; i++) {
    int j=0;
    while (true) {
      if (i*pow(2,j)>=K) {
        m=pow(2,j);
        break;
      }
      j++;
    }
    S+=1/m;
  }
  cout << fixed << setprecision(15) << S/(double)N << endl;
}

Measured memory_bytes: 4096
n = gets.chomp.to_i
s = gets.chomp
countb = 0
countw = 0
abs = 0

(n - 1).downto(0) do |pos|
  if s[pos] == '.' then
    countw += 1
  else
    countb += 1
  end

  if countw < countb then
    abs += countw
    countb = 0
    countw = 0
  end
end

puts abs + [countw, countb].min


Measured memory_bytes: 2172
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k,s;
    cin>>n>>k>>s;
    vector<ll> a(n);
    rep(i,k) a[i] = s;
    ll b = INF;
    if (b==s) b--;
    for (int i = k; i < n; ++i) a[i] = b;
    print(a);
    return 0;
}

Measured memory_bytes: 2048
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String n = sc.next();
    for (char c : n.toCharArray()) {
      if (c == '7') {
        pw.println("Yes");
        return;
      }
    }
    pw.println("No");
  }
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n)
    {
        int a;
        cin >> a;
        mp[a] += 1;
    }
    int ans = 0;
    for (auto i : mp)
    {
        if (i.first > i.second)
        {
            ans += i.second;
        }
        else
        {
            ans += abs(i.second - i.first);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
typedef long long LL;
using namespace std;
LL a[100005];
int main()
{
    LL n,x,ans,tmp;cin>>n>>x;
    ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=2;i<=n;i++)
    {
        tmp=a[i]+a[i-1]-x;
        if(tmp<0) tmp=0;
        ans+=tmp;
        if(tmp>=a[i])
        {
            a[i-1]-=(tmp-a[i]);
            a[i]=0;
        }
        else a[i]-=tmp;
    }
    cout<<ans<<endl;
    return 0;
}


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

struct Dice{
  int n1,n2,n3,n4,n5,n6;
  Dice(int n1, int n2, int n3, int n4, int n5, int n6)
    :n1(n1), n2(n2), n3(n3), n4(n4), n5(n5), n6(n6) {}

  void N(){
    swap(n1,n2);swap(n2,n6);swap(n6,n5);
  }
  void S(){
    swap(n1,n5);swap(n5,n6);swap(n6,n2);
  }
  void E(){
    swap(n1,n4);swap(n4,n6);swap(n6,n3);
  }
  void W(){
    swap(n1,n3);swap(n3,n6);swap(n6,n4);
  }
};

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  Dice dice(a,b,c,d,e,f);

  string s;cin>>s;
  for(int i=0; i<s.size(); i++){
    switch(s[i]){
      case 'N': dice.N();break;
      case 'S': dice.S();break;
      case 'E': dice.E();break;
      case 'W': dice.W();break;
    }
  }

  cout<<dice.n1<<endl;
}


Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int a,b,c;
cin>>a>>b>>c;
int a1=a+b;
int a2=b+c;
int a3=c+a;
if (a1 <= a2 && a1 <= a3) 
        cout << a1 ; 
  
    else if (a2 <= a1 && a2 <= a3) 
        cout << a2; 
  
    else
        cout << a3 ; 
  
} 

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

int max(int a, int b) {
    if (a >= b) return a;
    else return b;
}

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

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

    int lim = max(x, y);
    int sml = min(x, y);
    int res = a * x + b * y;
    for (int i=lim; i>=0; --i) {
        if (i > sml) {
            if (x == lim) {
                res = min(res, 2*c*i + a*(lim-i));
            } else {
                res = min(res, 2*c*i + b*(lim-i));
            }
        } else {
            if (x == lim) {
                res = min(res, 2*c*i + a*(lim-i) + b*(sml-i));
            } else {
                res = min(res, 2*c*i + a*(sml-i) + b*(lim-i));
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
str_in = input().split()
num   = int(str_in[0])
tgt_a = int(str_in[1])
tgt_b = int(str_in[2])
tgt_c = int(str_in[3])

source = [int(input()) for i in range(num)]

mp = float('inf')

for i in range(1,2**num):

  sum_a = 0
  len_a = 0
  
  bin_i = format(i,'08b')  
  for t in range(1,num+1):
    sum_a += int(bin_i[-t])
    len_a += int(bin_i[-t]) * source[t-1]
    
  for j in range(1,2**num):
 
    sum_b = 0
    len_b = 0

    if (i & j) > 0:
      continue
    
    bin_j = format(j,'08b')
    for t in range(1,num+1):
      sum_b += int(bin_j[-t])
      len_b += int(bin_j[-t]) * source[t-1]

    for k in range(1,2**num):

      sum_c = 0
      len_c = 0
      
      if (i & k) > 0:
        continue
      elif(j & k) > 0:
        continue
        
      bin_k = format(k,'08b')        
      
      for t in range(1,num+1):
        sum_c += int(bin_k[-t])
        len_c += int(bin_k[-t]) * source[t-1]
        
      mp_try = abs(len_a - tgt_a) + abs(len_b - tgt_b) + abs(len_c - tgt_c) + (sum_a + sum_b + sum_c - 3) * 10 
      if(mp > mp_try):
        mp = mp_try

print (mp)


Measured memory_bytes: 3064
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll dp[100100][13];

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

    dp[0][0] = 1;

    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < 13; j++){
            if(s[i] != '?'){
                int now = s[i] - '0';
                dp[i + 1][(j * 10 + now) % 13] += dp[i][j];
                dp[i + 1][(j * 10 + now) % 13] %= MOD;
            } else {
                for(int d = 0; d < 10; d++){
                    dp[i + 1][(j * 10 + d) % 13] += dp[i][j];
                    dp[i + 1][(j * 10 + d) % 13] %= MOD;
                }
            }
        }
    }

    cout << dp[s.size()][5] % MOD << endl;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int cur = 0;
	int answer = 1;
	for (int i = 0; i < n; ++i) {
		cur += a[i];
		if (cur <= x) {
			++answer;
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename lx> inline void read(lx &x){
	x = 0;int f = 1;char c = getchar();
	for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
	for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;return;
}
template <typename lx> inline void print(lx x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
	return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
const int inf = 2147483647;
const int maxn = 57;
int n,sum;
int a[maxn],b[maxn];
int main()
{
	read(n);
	for(rg int i = 1;i <= n; i++) read(a[i]),b[i] = a[i];
	sort(a + 1,a + 1 + n);
	for(rg int i = 1;i <= n; i++) if(a[i] != b[i]) sum++;
	if(sum == 0 || sum == 2) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
d = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
X, Y = input().split()
x = d[X]
y = d[Y]

if x < y:
    print('<')
elif x == y:
    print('=')
else:
    print('>')


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

using namespace std;

int main()
{
	int n,m;//長跟寬
	while(cin>>n>>m )
	{   if((n==0)&&(m==0)){break;}
		for(int i=1;i<=m;i++){cout<<"#";}
		cout<<endl;
		
		for(int j=1;j<=(n-2);j++)
		{
			cout<<"#";
			for(int k=1;k<=(m-2);k++)
			{
				cout<<".";
			}
			cout<<"#"<<endl;
		}
		
		for(int i=1;i<=m;i++){cout<<"#";}
		cout<<endl<<endl;
		
	 } 
		return 0;
}


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

int main() {
  int cnt,ans=0;
  int n; cin>>n;
  for(int i=1;i<=n;i+=2) {
    cnt=0;
    for(int j=1;j<=i;j++) {
      if(i%j==0) cnt++;
    }

    if(cnt==8) ans++;
  }
  cout<<ans<<endl;
}


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

int n, a[100005];
int main() {
	int i;
	cin>>n;
	for(i=1; i<=n; i++) scanf("%d", &a[i]);
	for(i=n-1; i>=1; i--) {
		if(a[i] > a[i+1]) {
			a[i]--;
			if(a[i] > a[i+1]) {cout<<"No"; return 0;}
		}
	}
	cout<<"Yes";
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  } else if (N == 2) {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+2;
int ar[N],cnt[N],cnt1[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,num;
	cin>>n>>num;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(i=1;i<=num;i++){
		bool cac=true;
		for(j=1;j<=n+1;j++){
			cnt[j]=0;
		}
		for(j=1;j<=n;j++){
			cnt[max(j-ar[j],1)]++;
			cnt[min(n+1,j+ar[j]+1)]--;
		}
		k=0;
		for(j=1;j<=n;j++){
			k+=cnt[j];
			if(k!=ar[j]){
				cac=false;
			}
			ar[j]=k;
		}
		if(cac){
			break;
		}
	}
	for(i=1;i<=n;i++){
		cout<<ar[i]<<' ';
	}
}

Measured memory_bytes: 5220
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val c = sc.nextLong()
  val xv = Array.fill(n)((sc.nextLong(), sc.nextLong()))
  val fc = xv.scanLeft((0L, 0L)){case ((_, vc), (x, v)) => (x, vc + v)}
  val fcMax = fc.scanLeft((0L, 0L)){case ((_, m), (xc, vc)) => (xc, m.max(vc - xc))}.tail
  val bc = xv.scanRight((0L, 0L)){case ((x, v), (_, vc)) => (c - x, vc + v)}
  val bcMax = bc.scanRight((0L, 0L)){case ((xc, vc), (_, m)) => (xc, m.max(vc - xc))}.init
  println(fcMax.zip(bcMax).map{case ((xf, mf), (xb, mb)) => mf + mb - xf.min(xb)}.max)
}


Measured memory_bytes: 83944
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int cnt[4] = {0};

    for(int i = 0;i < 3;i++){
        int a,b;
        cin >> a >> b;
        cnt[--a]++;
        cnt[--b]++;
    }

    for(int i = 0;i < 4;i++){
        if(cnt[i] > 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a[101],sum1=0,sum2=0,i,j,c;
    while(~scanf("%d",&n))
    {
        sum1=0,sum2=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0; i<n-1; i++)
            for(j=0; j<n-1-i; j++)
            {
                if(a[j]<a[j+1])
                {
                    c=a[j];
                    a[j]=a[j+1];
                    a[j+1]=c;
                }
            }
        for(int i=0; i<n; i++)
        {
            if(i%2==0)
                sum1+=a[i];
            else
                sum2+=a[i];
        }
        printf("%d\n",sum1-sum2);
    }
}


Measured memory_bytes: 128
def main():
    import heapq
    n,m=map(int,input().split())
    a=list(map(lambda x:-int(x),input().split()))
    heapq.heapify(a)
    import heapq
    for i in range(m):
        h=heapq.heappop(a)
        heapq.heappush(a,h/2)
    s=0
    for i in a:
        s+=int(-i)
    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14380
MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
dp=[0]*(n+1)
dp[0]=1
dp[1]=1 if 1 not in a else 0
a=sorted(list(set(range(2,n+1))-set(a)))
for i in a:
    dp[i]=(dp[i-1]+dp[i-2])%MOD
print(dp[n]%MOD)

Measured memory_bytes: 27300
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var S = ReadLine();
            var T = ReadLine();

            int idx = -1;
            for (int i = 0; i < S.Length - T.Length + 1; i++)
            {
                bool f = true;
                for (int j = 0; j < T.Length; j++)
                {
                    if (S[i + j] == '?') continue;
                    else if (S[i + j] == T[j]) continue;
                    else f = false;
                }
                if (f) idx = i;
            }
            if (idx == -1)
            {
                WriteLine("UNRESTORABLE");
                return;
            }
            var sb = new StringBuilder();
            for (int i = 0; i < S.Length; i++)
            {
                if (i == idx)
                {
                    sb.Append(T);
                    i += T.Length - 1;
                    continue;
                }

                if (S[i] == '?') sb.Append('a');
                else sb.Append(S[i]);
            }
            WriteLine(sb.ToString());
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17372
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'

const int N = 1e6 + 11;
int freq[N], a[N];

int32_t main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      freq[a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      freq[a[i]]--;
      bool ok = true;
      for (int j = 1; j * j <= a[i]; j++) {
        if (a[i] % j == 0) {
          if (freq[a[i] / j] != 0) ok = false;
          if (freq[j] != 0) ok = false;
        }
      }
      freq[a[i]]++;
      ans += ok;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12984
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
N, M = map(int, readline().split())
 
fact = [1] * (M+1)
fact_inv = [1] * (M+1)
for i in range(1,M+1):
    fact[i] = fact[i-1] * i % mod 
fact_inv[M] = pow(fact[M],mod-2,mod)
for i in range(M,0,-1):
    fact_inv[i-1] = (i * fact_inv[i]) % mod 
 
def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
total = 0
for k in range(N+1):
    a = fact[M-k] * fact_inv[M-N] * comb(N,k) % mod
    if k % 2 == 0:
        total += a
    else:
        total -= a
ans = (comb(M,N) * fact[N]) % mod * total 
print(ans%mod)

Measured memory_bytes: 48336
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static long Calc(long a, long b, long c) {
        if (a % 2 == 1 && b % 2 == 1 && c % 2 == 1) {
            var xs = new[] { a, b, c }.OrderBy(e => e).Take(2).ToArray();
            return xs[0] * xs[1];
        }
        return 0;
    }

    static void Main() {
        var abc = ReadInts();
        int a = abc[0], b = abc[1], c = abc[2];
        Console.WriteLine(Calc(a, b, c));
    }
}

Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
using namespace std;

int main() {

	queue< pair<string, int> > que;
	string name;
	int n, q, t;
	cin >> n >> q;

	for(int i = 0; i < n; i++) {
		cin >> name >> t;
		que.push(make_pair(name, t));
	}

	pair<string, int> u;
	int elapse = 0, a;

	while( !que.empty()) {
		u = que.front(); que.pop();
		a = min(u.second, q);
		elapse += a;
		u.second -= a;
		if(u.second > 0) que.push(u);
		else cout << u.first << " " << elapse <<endl;
	}
	return 0;
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
int main(){
int K,T;
  cin>>K>>T;
  vector<int>a(T);
  for(int i=0;i<T;i++)
    cin>>a.at(i);
  int sum=0;
  for(int i=0;i<T;i++){
  sum+=a.at(i);
  }sort(a.begin(),a.end());
  int ans=2*a.at(T-1)-1-sum;
  ans=max(0,ans);
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
use std::collections::HashSet;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(usize);
    let v_s = get_one!(String; n);

    let set_s: HashSet<String> = v_s.into_iter().collect();
    let ans = set_s.len();
    println!("{}", ans)
}


Measured memory_bytes: 19400
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;

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

    while (N--)
    {
        string s, t;
        cin >> s >> t;

        int dp[1010][1010];
        for (int i = 0; i < 1010; ++i)
            for (int j = 0; j < 1010; ++j)
                dp[i][j] = 0;

        int n = s.size(), m = t.size();

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                if (s[i] == t[j])
                {
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                }
                else
                {

                    dp[i + 1][j + 1] = max({dp[i + 1][j + 1], dp[i][j], dp[i + 1][j], dp[i][j + 1]});
                }
            }
        }

        cout << dp[n][m] << endl;
    }

    return 0;
}


Measured memory_bytes: 7184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    if(s.at(k-1) == 'A') s.at(k-1) = 'a';
    if(s.at(k-1) == 'B') s.at(k-1) = 'b';
    if(s.at(k-1) == 'C') s.at(k-1) = 'c';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


ll ten(ll n) {
  ll res=1;
  ll x=10;
  while(n>0) {
    if(n&1) res=res*x%13;
    x=x*x%13;
    n>>=1;
  }
  return res;
}

ll dp[MAX][13]={};
int main(void) {
  string s;
  cin >> s;
  ll i, j, k;
  ll N=s.size();
  
  dp[0][0]=1;
  for(i=0; i<N; i++) {
    for(j=0; j<13; j++) {
      if(s[i]=='?') {
        for(k=0; k<10; k++) {
          ll t=k*ten(N-i-1);
          moC(dp[i+1][(j+t)%13], +, dp[i][j]);
        }
      }else {
        ll t=(s[i]-'0')*ten(N-i-1);
        moC(dp[i+1][(j+t)%13], +, dp[i][j]);
      }
    }
  }
  
  pt(dp[N][5]);
}


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

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

using namespace std;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;

int main() {
    // おっと
    unsigned long long N;
    cin >> N;

    // P_N = 1 としたら残りは P_k = k + 1とすればよく、
    // 結局、1 から N-1 までの総和になる
    cout << N * (N - 1) / 2 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int [] L = new int [M];
		int [] R = new int [M];	
		int min = 0;
		int max = 100000;
		for (int i = 0; i<M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.max(min, L[i]);
			max = Math.min(max, R[i]);
		}
		if(min<=max) {
			System.out.println(max-min+1);
		}
		else {
			System.out.println(0);
		}
	}
}	



Measured memory_bytes: 82456
#include <iostream>
#include <map>
#include <cctype>
using namespace std;

int main() {
    map<char, int> m;
    m['a'] = 0;
    m['b'] = 0;
    m['c'] = 0;
    m['d'] = 0;
    m['e'] = 0;
    m['f'] = 0;
    m['g'] = 0;
    m['h'] = 0;
    m['i'] = 0;
    m['j'] = 0;
    m['k'] = 0;
    m['l'] = 0;
    m['m'] = 0;
    m['n'] = 0;
    m['o'] = 0;
    m['p'] = 0;
    m['q'] = 0;
    m['r'] = 0;
    m['s'] = 0;
    m['t'] = 0;
    m['u'] = 0;
    m['v'] = 0;
    m['w'] = 0;
    m['x'] = 0;
    m['y'] = 0;
    m['z'] = 0;

    char c;
    while(cin >> c) {
        if(isalpha(c)) {
            if(isupper(c)) c = tolower(c);
            m[c] += 1;
        }
    }

    cout << "a : " << m['a'] << endl;
    cout << "b : " << m['b'] << endl;
    cout << "c : " << m['c'] << endl;
    cout << "d : " << m['d'] << endl;
    cout << "e : " << m['e'] << endl;
    cout << "f : " << m['f'] << endl;
    cout << "g : " << m['g'] << endl;
    cout << "h : " << m['h'] << endl;
    cout << "i : " << m['i'] << endl;
    cout << "j : " << m['j'] << endl;
    cout << "k : " << m['k'] << endl;
    cout << "l : " << m['l'] << endl;
    cout << "m : " << m['m'] << endl;
    cout << "n : " << m['n'] << endl;
    cout << "o : " << m['o'] << endl;
    cout << "p : " << m['p'] << endl;
    cout << "q : " << m['q'] << endl;
    cout << "r : " << m['r'] << endl;
    cout << "s : " << m['s'] << endl;
    cout << "t : " << m['t'] << endl;
    cout << "u : " << m['u'] << endl;
    cout << "v : " << m['v'] << endl;
    cout << "w : " << m['w'] << endl;
    cout << "x : " << m['x'] << endl;
    cout << "y : " << m['y'] << endl;
    cout << "z : " << m['z'] << endl;

    return 0;
}


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

public class Main{


	static int A,B,C;
	static int []l;
	static int INF=(int)1e9;
	static int solve(int msk,int a,int b,int c,int numa,int numb,int numc) {
		if(msk==0) {
			if(numa==0 || numb==0 || numc==0)
				return INF;
			return (numa-1)*10+(numb-1)*10+(numc-1)*10+Math.abs(A-a)+Math.abs(C-c)+Math.abs(B-b);
			
		}
		int z=msk&-msk;
		int idx=(int) (Math.log(z)/Math.log(2));
		msk=msk-(msk&-msk);
		int x=l[idx];
		int ans=solve(msk,a,b,c,numa,numb,numc);
		ans=Math.min(ans, solve(msk,a+x,b,c,numa+1,numb,numc));
		ans=Math.min(ans, solve(msk,a,b+x,c,numa,numb+1,numc));
		ans=Math.min(ans, solve(msk,a,b,c+x,numa,numb,numc+1));
		return ans;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt();
		A=sc.nextInt();
		B=sc.nextInt();
		C=sc.nextInt();
		l=new int [n];
		for(int i=0;i<n;i++)
			l[i]=sc.nextInt();
		out.println(solve((1<<n)-1, 0, 0, 0, 0, 0, 0));
		
		out.close();
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 24256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	long n, m, num1 = 0, num2 = 0;
	char mat[2000][2000];

	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1 << endl;
		getchar();
		getchar();
		return 0;
	}

	/*
	fill((char*)mat, (char*)(mat + 2000), '.');

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {

			if (mat[i][j] == '.') {
				mat[i][j] = '#';
			}else if (mat[i][j] == '#') mat[i][j] = '.';

			if (mat[i - 1][j] == '.') {
				mat[i - 1][j] = '#';
			}else if (mat[i - 1][j] == '#') mat[i - 1][j] = '.';

			if (mat[i - 1][j + 1] == '.') {
				mat[i - 1][j + 1] = '#';
			}else if (mat[i - 1][j + 1] == '#') mat[i - 1][j + 1] = '.';

			if (mat[i][j + 1] == '.') {
				mat[i][j + 1] = '#';
			}else if (mat[i][j + 1] == '#') mat[i][j + 1] = '.';

			if (mat[i + 1][j + 1] == '.') {
				mat[i + 1][j + 1] = '#';
			}else if (mat[i + 1][j + 1] == '#') mat[i + 1][j + 1] = '.';

			if (mat[i + 1][j] == '.') {
				mat[i + 1][j] = '#';
			}else if (mat[i + 1][j] == '#') mat[i + 1][j] = '.';

			if (mat[i + 1][j - 1] == '.') {
				mat[i + 1][j - 1] = '#';
			}else if (mat[i + 1][j - 1] == '#') mat[i + 1][j - 1] = '.';

			if (mat[i][j - 1] == '.') {
				mat[i][j - 1] = '#';
			}else if (mat[i][j - 1] == '#') mat[i][j - 1] = '.';

			if (mat[i - 1][j - 1] == '.') {
				mat[i - 1][j - 1] = '#';
			}else if (mat[i - 1][j - 1] == '#') mat[i - 1][j - 1] = '.';

		}
		
	}

	int count = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			//cout << mat[i][j];
			if (mat[i][j] == '#') count++;
		}
		//cout << endl;
	}

	//cout << count << endl;
	*/


	if (n > 2 && m > 2) {

		num1 = n * m;

		num1 = num1 - (n + n);

		num1 = num1 - (m + m);

		if (n > 2) {
			num1 += 2;
		}

		if (m > 2) {
			num1 += 2;
		}

	}
	else if(n<=2 && m<=2){
		num1 = 0;
	}
	else if(n > 2 && m==2 ){

		//num1 = n * m;
		//num1 = num1 - (m + m);
		num1 = 0;
	}
	else if (n== 2 && m > 2) {

		//num1 = n * m;
		//num1 = num1 - (n + n);
		num1 = 0;

	}
	else if (n > 2 && m == 1) {

		num1 = n * m;
		num1 = num1 - (m + m);
		
	}
	else if (n == 1 && m > 2) {

		num1 = n * m;
		num1 = num1 - (n + n);

	}

	cout << num1 << endl;











	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    cout<<(n*(n-1))/2LL+(m*(m-1))/2LL<<endl;
}
// PLUS ULTRA!

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;


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

    stack<pair<string, char>> st;

    st.push(make_pair("a",'a'));

    while(!st.empty()){
        string s = st.top().fi;
        char cmax = st.top().se;
        st.pop();
        if(s.size()==n) cout << s << endl;
        else{
            st.push(make_pair((s+char(cmax+1)), cmax+1));
            char ci = cmax;
            rep(i, cmax-'a'+1){
                st.push(make_pair((s+ci), cmax));
                ci--;
            }
        }
    }
    
    

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){cin >> a[i];}
    int ans;
    int sum=a[0];
    for(int i=1; i<n; i++){sum^=a[i];}
    for(int i=0; i<n; i++){
        int ans=a[i]^sum;
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4248
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#define S 100

int my_min(int a, int b) {
    if (a >= b) {
        return b;
    } else {
        return a;
    }
}

int main(void) {
    int k, n;
    char c, s[S+2]; // +2 for newline and null
    bool is_same_char, has_same_odd_char;

    fgets(s, S+1, stdin);
    n = strlen(s);
    if (s[n-1] == '\n') {
        s[n-1] = '\0';
        n--;
    }

    scanf("%d", &k);

    // special case
    is_same_char = true;
    c = s[0];
    for (int i = 1; i < n; i++) {
        if (s[i] != c) {
            is_same_char = false;
            break;
        }
    }
    if (is_same_char) {
        printf("%ld\n", (long) k * (long) n / 2);
        return 0;
    }

    if (s[0] == s[n-1]) {
        int count_forward = 0, count_backward = 0;
        char c = s[0];

        int i = 0;
        while (i < n && s[i] == c) {
            count_forward++;
            i++;
        }
        i = n-1;
        while (i >= 0 && s[i] == c) {
            count_backward++;
            i--;
        }

        if (count_forward % 2 == 1 && count_backward % 2 == 1) {
            has_same_odd_char = true;
        } else {
            has_same_odd_char = false;
        }
    } else {
        has_same_odd_char = false;
    }

    int count = 0, ch_count = 1;
    c = s[0];
    for (int i = 1; i < n; i++) {
        if (s[i] == c) {
            ch_count++;
            if (ch_count % 2 == 0) {
                count++;
            }
        } else {
            ch_count = 1;
            c = s[i];
        }
        // printf("count=%d, ch_count=%d\n", count, ch_count);
    }

    long result;
    if (has_same_odd_char) {
        result = (long) count * (long) k + ((long) k-1);
    } else {
        result = (long) count * (long) k;
    }

    printf("%ld\n", result);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

ll n, m;

vi dp(300000, -1);

ll fact(ll x){
  if(x == 0) return 1;
  if(dp[x] != -1) return dp[x];
  return dp[x] = (fact(x-1) * x)%m;
}

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >>  n;
    vi v(n);
    f(i, sz(v)) cin >> v[i];
    ll m = INF;
    ll ans = 0;
    f(i, n){
      if(m >= v[i]){
        ans++;
        m = v[i];
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define kill __kill__

int n, a, b;

char type[110][110];
int kill[110][110];
vector<pii> fo[110][110];
vector<pii> rfo[110][110];

vector<pii> start;

void Dfs(int x, int y){
  if(type[x][y] == 'W'){
    for(const auto& e : rfo[x][y]){
      ++kill[e.fi][e.se];
      if(kill[e.fi][e.se] >= sz(fo[e.fi][e.se])){
        if(type[e.fi][e.se] == '?'){
          type[e.fi][e.se] = 'L';
          Dfs(e.fi, e.se);
        }
      }
    }
  } else if(type[x][y] == 'L'){
    for(const auto& e : rfo[x][y]){
      if(type[e.fi][e.se] == '?'){
        type[e.fi][e.se] = 'W';
        Dfs(e.fi, e.se);
      }
    }
  }
}

int main(){
  memset(type, '?', sizeof type);

  cin >> n >> a >> b;

  for(int x = 1;x <= n;++x)
    for(int y = 1;y <= n;++y){
      if(x == y) continue;
      if(x + 1 <= n && x + 1 != y)
        fo[x][y].pb(mp(y, x + 1));
      if(x - 1 > 0 && x - 1 != y)
        fo[x][y].pb(mp(y, x - 1));
      if(sz(fo[x][y]) == 0){
        start.pb(mp(x, y));
        type[x][y] = 'L';
      }
    }

  for(int x = 1;x <= n;++x)
    for(int y = 1;y <= n;++y)
      for(const auto& e : fo[x][y])
        rfo[e.fi][e.se].pb(mp(x, y));

  for(const auto& e : start)
    Dfs(e.fi, e.se);

  if(type[a][b] == 'W') printf("Alice\n");
  else if(type[a][b] == 'L') printf("Borys\n");
  else printf("Draw\n");

  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<ll,ll>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec vector <int> 
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  ll n,w;
  cin >> n >> w;
  ll m = 0;
  vector< vector<ll> > v (4, vector<ll>() );
  ll r,t ;
  cin >> r >> t;
  v[0].pb(t);
  REP(i,n-1){
    ll x,y;
    cin >> x >> y;
    v[x-r].pb(y);
  }
  
  REP(i,4){
    //cout << 444564 << endl;
    sort(v[i].begin(),v[i].end(), greater <ll>());
    //cout << 6889787 << endl;
    v[i].insert(v[i].begin(),0);
    rep(j,1,v[i].size()+1){
      v[i][j] = v[i][j-1]+v[i][j];
    }
  }
  /*
  REP(i,4){
    REP(j,v[i].size())
      cout << v[i][j] << "  ";
    cout << endl;
  }
  */
  ll sum = 0;
  //cout << 4545456 << endl;
  REP(i,v[0].size()){
    REP(j,v[1].size()){
      REP(k,v[2].size()){
	REP(l,v[3].size()){
	  ll s = v[0][i] + v[1][j] + v[2][k] + v[3][l];
	  ll t = i*r + j*(r+1) + k*(r+2) + l*(r+3);
	  if(t <= w){
	    sum = max(sum,s);
	  }
	}
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

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

    int r = -1;
    vector<string> words = {"dreamer", "dream", "eraser", "erase"};

    while (r < sn-1) {
        int now = r;
        for (auto word : words) {
            int n = word.size();
            string sub = s.substr(r+1, n);
            if (word == sub) {
                if (r+n == sn-1) {
                    cout << "YES" << endl;
                    return 0;
                }
                if (s.at(r+n+1) == 'd' || s.at(r+n+1) == 'e') {
                    r += n;
                    break;
                }
            }
        }
        if (now == r) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3716