akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int N;
char S[99999999];
char res[99999999];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	static_assert('(' < ')', "");

	in >> N>>S;
	std::reverse(S, S + N);
	auto res_end = res + 999999;
	auto iter = res_end-1;
	int32_t count = 0;
	for (int32_t i = 0; i < N; ++i)
	{
		if (S[i] == ')') {
			*iter-- = ')';
			++count;
		}
		else {
			*iter-- = '(';
			if (count > 0) {
				--count;
			}
			else {
				*res_end++ = ')';
			}
		}
	}
	while (count) {
		*iter-- = '(';
		--count;
	}
	out << (iter+1) << endl;

	return 0;
}
#endif


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> l(n);
    std::vector<int> r(n);
    for(int i = 0; i < n; i++){
        std::cin >> l[i] >> r[i];
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += (r[i] - l[i] + 1);
    }

    std::cout << sum;
    return 0;
}




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

int main() {
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int amount, years, n;
    cin >> amount >> years >> n;
    int ans = 0;
    for (int j = 0; j < n; j++) {
      int b, charge, total = 0;
      double rate;
      cin >> b >> rate >> charge;
      int balance = amount;
      int interest;
      for (int k = 0; k < years; k++) {
        interest = balance * rate;
        balance += b * interest - charge;
        total += interest;
      }
      ans = max(ans, !b * total + balance);
    }
    cout << ans << endl;
  }
}



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

int check(int x){
  int y=0;
  while(y*(y+1)/2 < x){
    y++;
  }
  return y;
}

int main(){
  int n; cin >> n;
  int i=check(n);
  if(n-i*(i+1)/2){
    cout << "No" << endl;
    return 0;
  }else{
    cout << "Yes" << endl;
  }
  
  vector<vector<int>> a(i+1);
  
  for(int p=1; p<=n; p++){
    a[check(p)].push_back(p);
    a[p-1-(check(p)-1)*check(p)/2].push_back(p);
  }
  
  int tes = 0;
  cout << i+1 << endl;
  for(int cnt=0; cnt<i+1; cnt++){
    cout << i << " ";
    for(const auto q: a[cnt]){
      cout << q << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 2304
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
int main()
{
    LL k,n=50;
    scanf("%lld",&k);
    printf("50\n");
    LL cnt=k/50,res=k%50;
    for(int i=0;i<50;i++)
    {
        if(i<res) printf("%lld",i+cnt+n-res+1);
        else printf("%lld",i+cnt-res);
        if(i!=49) printf(" ");
    }
    return 0;
}

Measured memory_bytes: 256
def slv(n,a,s):
  base=[0]
  for i in range(n-1,-1,-1):
    v=a[i]
    for j in sorted(base,reverse=True):
      v=min(v,j^v)
    if v==0:
      pass
    else:
      if s[i]=='0':base.append(v)
      if s[i]=='1':return 1
  if base:return 0
  return 1

t=int(input())
n=[]
a=[]
s=[]
for _ in range(t):
  n.append(int(input()))
  a.append(list(map(int,input().split())))
  s.append(input())
for i in range(t):
  print(slv(n[i],a[i],s[i]))


Measured memory_bytes: 73740
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def main():
    p = 'dream dreamer erase eraser'.split()
    pp = [[_, len(_)] for _ in p]
    s = input()
    while len(s) > 0:
        f = False
        for ps, pl in pp:
            if ps == s[-pl:]:
                s = s[:-pl]
                f = True
                break
        if not f:
            return 'NO'

    return 'YES'


print(main())


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

int main() {
  int N, T;
  double A;
  cin >> N >> T >> A;
  vector<int> H(N);
  double delta, best_delta;
  int best_i;
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
    double tmp_A = T - H.at(i) * 0.006;
    if (A < tmp_A) {
      delta = tmp_A - A;
    }
    else {
      delta = A - tmp_A;
    }
    
    if (i == 0) {
      best_delta = delta;
      best_i = i + 1;
    }
    
    if (delta < best_delta) {
      best_delta = delta;
      best_i = i + 1;
    }
  }
  cout << best_i << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
   string s;
   cin>>s;
   if(s=="ARC") cout<<"ABC";
   else cout<<"ARC";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db long double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi totor<int>
#define vl totor<ll>
#define rep(i, x, y) for(register int i = x; i <= y; i ++)
#define rrep(i, x, y) for(register int i = x; i >= y; i --)
#define eps 1e-15
#define lb(x) x & -x
#define sz(x) (x).size()
using namespace std;
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 read1()
{
	ll 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;
}
const int N = 10010;

char S[N];
int vis[26];
char ans[N];

int len = 0;

int main() 
{
    scanf("%s", S + 1);
    len = strlen(S + 1);
    memcpy(ans, S, sizeof(S));
    rrep(i, len, 0)
    {
        memset(vis, 0, sizeof(vis));
        rep(j, 1, i)
            vis[S[j] - 'a'] = 1;

        rep(j, 0, 25)
            if (!vis[j] && (i == len || j > (S[i + 1] - 'a'))) 
            {
                int cur = i;
                ans[++ cur] = j + 'a';
                ans[cur + 1] = 0;
                puts(ans + 1);
                return 0;
            }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll inf=1e+18;
const int MAXI=2500;

using pll=pair<ll,ll>;//money,time
using Edge=pair<int,pll>;
using Graph=vector<vector<Edge>>;
int n,m;
ll s;
Graph G;
vector<ll> c,d;
int main(void){
    cin>>n>>m>>s;
    G.assign(n,vector<Edge>());
    rep(i,m){
        ll u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
        G[u].push_back(Edge(v,pll(a,b)));
        G[v].push_back(Edge(u,pll(a,b)));
    }
    c.resize(n);d.resize(n);
    rep(i,n) cin>>c[i]>>d[i];
    
    if(s>=MAXI) s=MAXI;
    vector<vector<ll>> dp(n,vector<ll>(MAXI+1,inf));
    priority_queue<pair<ll,pll>, vector<pair<ll,pll>>, greater<pair<ll,pll>> > que; //time,edge,money
    dp[0][s]=0;
    que.push({0,pll(0,s)});
    while(que.size()){
        auto p=que.top();que.pop();
        ll t=p.first;
        int v=p.second.first;
        ll ss=p.second.second;
        if(t>dp[v][ss])continue;
        if(ss+c[v]<=MAXI){
            ll ns=ss+c[v];
            ll ntime=t+d[v];
            if(chmin(dp[v][ns],ntime)){
                que.push(make_pair(ntime,pll(v,ns)));
            }
        }
        
        for(auto e:G[v]){
            if(ss<e.second.first)continue;
            int nv=e.first;
            ll ns=ss-e.second.first;
            ll ntime=t+e.second.second;
            if(chmin(dp[nv][ns],ntime)){
                que.push(make_pair(ntime,pll(nv,ns)));
            }
        }
    }
    rep(i,n){
        if(i==0)continue;
        ll res=inf;
        rep(j,MAXI+1)res=min(res,dp[i][j]);
        cout<<res<<endl;
    }
}

Measured memory_bytes: 7368
#!/usr/bin/env python3

# データ読み込み
d, g = map(int, input().split())
p = []
c = []
for i in range(d):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)

ans = sum(p) # 全部解いた場合を初期値にする

for i in range(1<<d): # 組み合わせループ（2^dパターン）
    score = 0
    count = 0

    # 完答問題の組み合わせから点数を計算する
    for k in range(d):
        if i>>k&1: # 1になっているビットに対応するボーナスポイントを獲得したとする
            score += (k+1)*100*p[k] # 通常得点を加算
            score += c[k] # ボーナスポイントを加算
            count += p[k] # 問題数を加算

    # print(bin(i),count, score)

    # 完答問題だけでスコアが目標を超えていなければ、残りの問題をスコアが目標に達するまで解く
    add_count = 0
    if score < g:
        flag = 0
        add = 0
        for k in range(d,0,-1): # k桁の上の桁からサーチ
            if not i>>(k-1)&1: # 完答していない問題(k桁目が0になっているビット)について
                for j in range(1, p[k-1], 1): # j問解いたとき
                    add += k*100
                    score += k*100 # 加算点
                    add_count += 1
                    # print('k,j,count,add_count',k,j,count, add_count)
                    if score >= g:
                        flag = 1
                        break
            if flag == 1:
                break

    count += add_count
    # print(bin(i), count, score, add)
    # 回数を更新
    if score >= g and ans > count:
        ans = count

print(ans)


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

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

int main() {
	int h, w;
	cin >> h >> w;
	string a[102] = {};
	rep(i, 0, h) {
		cin >> a[i];
	}
	rep(i, 0, w + 2)cout<<"#";
	cout << endl;
	rep(i, 0, h)print("#"<<a[i]<<"#");
	rep(i, 0, w + 2)cout << "#";
	cout << endl;
	return 0;
}

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

using namespace std;

template<class T> void ReadInteger(T & x) {
    x = 0;
    int f = 1, ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 - '0' + ch;
        ch = getchar();
    }
    x *= f;
}

int N, K, M;
int C[305][305];
int f[305][305][305];

inline void add(int & x, int y) {
    x += y;
    x %= M;
}

void Solve() {
    f[0][1][0]  = 1;
    for(int i = 0; i <= N; i++) {
        for(int j = 1; j <= K; j++) {
            for(int p = i; p >= 0; p--) {
                if(p) add(f[i][j][p - 1], f[i][j][p]);
                else add(f[i][j + 1][i], f[i][j][p]);
                add(f[i + 1][j][p], 1ll * f[i][j][p] * (p + 1) % M);
            }
        }
    }
    cout << f[N][K + 1][N] << endl;
}
int main(int argc, char const *argv[]) {
    ReadInteger(N);
    ReadInteger(K);
    ReadInteger(M);
    Solve();
    return 0;
}


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

using namespace std;

int main(){
    int N,ans=0,A;
    cin >> N;
    vector<int> a(N,0);
    for(int i=0;i<N;i++){
        cin >> A;
        if(N<A){
            ans++;
        }else{
            a[A-1]++;
        }
    }

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

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	map<int,int> ds;
	rep(i,n){
		int d; cin>>d; ds[d]++;
	}
	int m; cin>>m;
	rep(i,m){
		int t; cin>>t;
		if(ds[t]==0) return cout<<"NO"<<endl,0;
		ds[t]--;
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2 +2], R[MAX/2+2], A[MAX];

void merge(struct Card A[],int n, int left, int mid, int right){
    int i,j,k;
    int n1 = mid-left;
    int n2 = right - mid;
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1].value = R[n2].value=SENTINEL;
    i=0;
    j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value){
            A[k]=L[i++];
        }else {
            A[k]=R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if(left+1<right){
        mid=(left+right) /2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i,j;
    struct Card temp,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value<=x.value){
            i++;
            temp=A[i]; A[i]=A[j]; A[j]=temp;
        }
    }
    temp=A[i+1]; A[i+1]=A[r]; A[r]=temp;
    return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p<r){
        q= partition(A,n,p,r);
        quickSort(A,n,p,q-1);
        quickSort(A,n,q+1,r);
    }
}

int main(void){
    int n,i,v;
    struct Card B[MAX];
    char S[10];
    int stable=1;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %d",S,&v);
        A[i].suit=B[i].suit=S[0];
        A[i].value =B[i].value=v;
    }
    
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    
    for(i=0;i<n;i++){
        if(A[i].suit !=B[i].suit) stable=0;
    }
    
    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++){
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    return 0;
}



Measured memory_bytes: 4088
#include<iostream>

using namespace std;
const int t = 1e4 + 44;
int ans[t];
void  test_case()
{
int n;
cin>>n;
           for (int x = 1; x * x <= n; ++x) for (int y = 1; x * x + y * y + x * y <= n; ++y) 
                      for (int z = 1; x * x + y * y +z * z + x * y + y * z + z * x <= n; ++z) ans[x * x + y * y +z * z + x * y + y * z + z * x]++;
           for (int i = 1; i <= n; ++i) cout<<ans[i]<<"\n";}
int main()
{
int tc=1;
//cin>>tc;
while(tc--)
{
test_case();
}
return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e+9+7;
//A,G,C,Tの順に番号を振り分けていく
//実装重すぎる 思いつくのは簡単だったけど
int main(){
    int n;cin>>n;
    int dp[n+1][4][4][4];
    for(int i=0;i<=n;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++)dp[i][j][k][l]=0;
            }
        }
    }
    dp[0][3][3][3]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    if(dp[i][j][k][l]==0)continue;
                    for(int a=0;a<4;a++){//jkla
                        if(k==0&&l==1&&a==2)continue;//AGC
                        if(j==0&&l==1&&a==2)continue;//AXGC
                        if(j==0&&k==1&&a==2)continue;//AGXC
                        if(k==1&&l==0&&a==2)continue;//GAC
                        if(k==0&&l==2&&a==1)continue;//ACG
                        dp[i+1][k][l][a]+=dp[i][j][k][l];
                        dp[i+1][k][l][a]%=mod;
                    }
                }
            }
        }
    }
    long long res =0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                res+=dp[n][i][j][k];
                res%=mod;
            }
        }
    }
    cout<<res<<endl;
}//実装くそ重すぎ

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int tmp = 1e9 + 7, ans = 0, am = 0;
	for (int i = 1; i <= n; ++ i) {
		int a;
		scanf("%d", &a);
		tmp = min(a, tmp);
		if (tmp < a) {
			if (a - tmp > am) {
				ans = 1;
				am = a - tmp;
			}
			else if (a - tmp == am) {
				ans ++;
			}
		}
	}
	assert(ans);
	printf("%d\n", ans);
}



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

using namespace std;

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

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

    int b[n];
    b[0] = a[0] + k - a[n-1];
    int m = b[0];
    for (int i = 1; i < n; i++)
    {
        b[i] = a[i] - a[i-1];
        
        if (m < b[i])
        {
            m = b[i];
        }
    }

    k -= m;
    cout << k << endl;

    return 0;
}

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

int i,a[10]={};

int main() {
	for (i=0;i<10;i++){
		cin >> a[i];
	}
	sort(a,a+10);
	for (i=0;i<3;i++){
		cout << a[10-1-i] << endl;
	}
	return 0;
}

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



int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int cnt = 0;
    while(a >= b) {
        b *= 2;
        cnt++;
    }
    while(b >= c) {
        c *= 2;
        cnt++;
    }
    
    if(cnt <= k)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}




Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
using namespace std;

struct pyramid {
	int x;
	int y;
	int h;
};

int main()
{
	pyramid prd[101];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> prd[i].x >> prd[i].y >> prd[i].h;
	int p = 0;
	while (prd[p].h == 0) 
		p++;
	for (int i = 0; i <= 100; i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			int temp_H = prd[p].h + abs(i - prd[p].x) + abs(j - prd[p].y);
			int k = 0;
			for (; k < n; k++)
			{
				int temp_h = temp_H - abs(i - prd[k].x) - abs(j - prd[k].y);
				if (temp_h < 0) 
					temp_h = 0;
				if (temp_h != prd[k].h)
					break;
			}
			if (k==n)
			{
				cout << i << ' ' << j << ' ' << temp_H << endl; 
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[222222];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int h,w;
char c[510][510];
bool red[510][510];
bool blue[510][510];
signed main(){
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
		}
	}
	rep(i,h){
		rep(j,w){
			if(j==0)red[i][j]=true;
			else if(j==w-1)blue[i][j]=true;
			else{
				if(i%2==0)red[i][j]=true;
				else blue[i][j]=true;
			}
			if(c[i][j]=='#'){
				red[i][j]=true;
				blue[i][j]=true;
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if(red[i][j])cout<<'#';
			else cout<<'.';
		}
		cout<<endl;
	}
	cout<<endl;
	rep(i,h){
		rep(j,w){
			if(blue[i][j])cout<<'#';
			else cout<<'.';
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1536
n = int(input())
l = ['M','A','R','C','H']
m = []
a = []
r = []
c = []
h = []
for i in range(n):
    s = input()
    if not s[0] in l: continue
    if s[0] == 'M':
        m.append(s)
    elif s[0] == 'A':
        a.append(s)
    elif s[0] == 'R':
        r.append(s)
    elif s[0] == 'C':
        c.append(s)
    else:
        h.append(s)

n = sum([len(i) for i in [m,a,r,c,h]])
all = n * (n - 1) * (n - 2) // 6
for t in [m,a,r,c,h]:
    i = len(t)
    if i >= 3:
        k = i * (i - 1) * (i - 2) // 6
        all -= k
    if i >= 2:
        k = i * (i - 1) // 2
        all -= k * (n - i)
print(all)


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

string s[4];

int main(){
	for(int i=0;i<3;i++) cin >> s[i], reverse(s[i].begin(),s[i].end());
	int cur = 0;
	while(s[cur]!=""){
		int ccur = s[cur].back()-'a';
		s[cur].pop_back();
		cur = ccur;
	}
	cout << (char)(cur+'A') << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n), b(n);
  ll s;
  rep(i, n) {
    cin >> a[i];
    s -= a[i];
  }
  rep(i, n) {
    cin >> b[i];
    s += b[i];
  }
  bool ok = true;
  if(s < 0) ok = false;
  ll p = 0, m = 0;
  rep(i, n) {
    if(a[i] > b[i])
      m += a[i] - b[i];
    else
      p += (b[i] - a[i] + 1) / 2;
  }
  if(max(p, m) > s) ok = false;
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define in(n) cin>>n>>
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int r,g;
    
    cin >> r >> g;
    
    cout << 2*g-r << endl;
    
    
    

return 0;}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] time = new int[n + 3];
		int[] maxv = new int[n + 2];
		time[0] = 0;
		time[1] = 0;
		for (int i = 0, k = 2; i < n; i++, k++) {
			time[k] = sc.nextInt();
			time[k] += time[k-1];
		}
		time[n + 2] = time[n + 1];
		int totalTime = time[n+2];
		maxv[0] = 0;
		maxv[n + 1] = 0;
		for (int i = 1; i <= n; i++) {
			maxv[i] = sc.nextInt();
		}

//		System.out.println(Arrays.toString(time));
//		System.out.println(Arrays.toString(maxv));
//		System.out.println(totalTime);

		double[] maxV_Every_0_5_seconds = new double[totalTime * 2+1];
		Arrays.fill(maxV_Every_0_5_seconds, Integer.MAX_VALUE);
		for (double i = 0; i < totalTime * 2+1; i++) {
			for(int j = 0; j < n+2; j++) {
				//j個目の条件はtime[j+1]-time[j]の区間の最大速度はmax[v]
				if(i <= 2*time[j]) {
					maxV_Every_0_5_seconds[(int) i] = Math.min(maxV_Every_0_5_seconds[(int) i], maxv[j]+time[j]-(i/2));
				}
				if(i >= 2*time[j+1]) {
					maxV_Every_0_5_seconds[(int) i] = Math.min(maxV_Every_0_5_seconds[(int) i], maxv[j]-time[j+1]+(i/2));
				}
				if(i >= 2*time[j] && i <= 2*time[j+1]) {
					maxV_Every_0_5_seconds[(int) i] = Math.min(maxV_Every_0_5_seconds[(int) i], maxv[j]);
				}
			}
		}
//		System.out.println(Arrays.toString(maxV_Every_0_5_seconds));
		double ans = 0;
		for(int i = 0; i < totalTime*2; i++) {
			ans += 0.25 * (maxV_Every_0_5_seconds[i]+maxV_Every_0_5_seconds[i+1]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    reverse(A,A+n);
    if(A[0]!= 2){
        cout << -1 << endl;
        return 0;
    }

    int B[n];
    B[0] = A[0];

    FOR(i,1,n){
        int syou = B[i-1] / A[i];
        if(B[i-1] % A[i] != 0) syou ++;
        B[i] = A[i] * syou;
    }
    int ninzuu = B[n-1];
    REPR(i,n-1){
        ninzuu = ninzuu - (ninzuu % A[i]);
    }
    if(ninzuu != 2){
        cout << -1 << endl;
        return 0;
    }



    int C[n];
    C[0] = A[0];
    FOR(i,1,n){
        int syou = (C[i-1] + A[i-1]) / A[i];
        if((C[i-1] + A[i-1]) % A[i] == 0  ) syou--;
        C[i] = A[i] * syou;

    }
    
    cout << B[n-1] << endl;
    cout << C[n-1] + A[n-1] -1<< endl;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
    int x,y;
    for (int i = 0; i+= 1;){
        cin >> x >> y;
        if (x == 0 && y == 0){
            break;
        }
        else{
            if (x <y){
                cout <<x << " " << y << endl;
            }
            else {
                cout <<y <<" " << x << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3044
#include <iostream>

using namespace std;

static long long INF =1LL<<60;
int N;
int a[100010][3];
long long dp[100010][3];
int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++) dp[i][j]=0;
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      dp[i+1][j]=max(dp[i+1][j],dp[i][(j+1)%3]+a[i][(j+1)%3]);
      dp[i+1][j]=max(dp[i+1][j],dp[i][(j+2)%3]+a[i][(j+2)%3]);
    }
  }
  cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt(),c=nxt(),d=nxt();
    cout<<max(a*b,c*d)<<endl;
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#!python3

# input
N = int(input())
A = list(map(int, input().split()))


def main():
    x = 0
    right = 0
    while right < N and x & A[right] == 0:
        x += A[right]
        right += 1
    
    ans = right
    for left in range(N - 1):
        x -= A[left]
        while right < N and x & A[right] == 0:
            x += A[right]
            right += 1
        ans += right - left - 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25688
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

class UnionFind
{
public:
    UnionFind(int N) : par(N)
    {
        for (ll i = 0; i < N; i++)
        {
            par[i] = i;
        }
    }

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

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

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

private:
    vector<int> par;
};

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

struct Dish{
    ll time;
    ll taste;
};
int main()
{
    ll N, T;
    cin >> N >> T;
    vector<Dish> dishes(N + 1);
    for (ll i = 0; i < N; i++)
    {
        ll ai, bi;
        cin >> ai >> bi;
        Dish d = {ai, bi};
        dishes[i + 1] = d;
    }

    vector<vector<ll>> DP1(N + 1, vector<ll>(T + 1, 0));
    vector<vector<ll>> DP2(N + 1, vector<ll>(T + 1, 0));

    // DP1 => 1-i 種類までの料理の中で j 分以内で最大の満腹度
    for (ll i = 1; i <= N; i++)
    {
        for (ll j = 0; j <= T; j++)
        {
            if (j < dishes[i].time) {
                DP1[i][j] = DP1[i - 1][j];
                continue;
            }
            DP1[i][j] = max(DP1[i - 1][j], dishes[i].taste + DP1[i - 1][j - dishes[i].time]);
        }
    }
    for (ll i = 1; i <= N; i++)
    {
        for (ll j = 0; j <= T; j++)
        {
            if (j < dishes[N - i + 1].time) { 
                DP2[i][j] = DP2[i - 1][j];
                continue;
            }
            DP2[i][j] = max(DP2[i - 1][j], dishes[N - i + 1].taste + DP2[i - 1][j - dishes[N - i + 1].time]);
        }
    }

    ll ans = 0;    
    for (ll i = 1; i <= N; i++)
    {
        for (ll j = 0; j <= T - 1; j++)
        {
            ans = max(ans, DP1[i - 1][j] + DP2[N - i][T - 1 - j] + dishes[i].taste);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 144184
#include<bits/stdc++.h>
using namespace std;
#define mod                   1000000007
#define ll                    long long
#define Author                std::ios_base::sync_with_stdio(0);
#define u_map                 unordered_map<ll,ll>
#define n_map                 map<ll,ll>
#define n_pair                pair<ll,ll>
#define all(v)                v.begin(),v.end()
#define frr(i,j,k)           for(int i=j; i<k; i++)
#define frp(i,j,k)           for(int i=j; i>=k; i--)
#define pb(a)                 push_back(a)
#define lb(v,t)               lower_bound(all(v),t)-v.begin()
#define ub(v,t)               upper_bound(all(v),t)-v.begin()
#define in(t)                 scanf("%lld",&t);
#define out(t)                printf("%lld\n",t);
#define inputarr(a,n)        for(int i=0;i<n;++i) cin>>a[i]
#define printarr(a,n)        for(int i=0;i<n;++i) cout<<a[i]<<" "
#define mem(a)              memset(a,0,sizeof(a))
#define int_max     INT_MAX64
ll abst(ll a){if(a<0)return -a; return a;}
ll power(ll a, ll b){ll res=1;while(b){if(b&1)res=res*a;a=a*a;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}
ll lcm(ll a, ll b){return a*b/__gcd(a,b);}
ll ncr(ll n, ll r){ll p=1;ll i;for(i=1; i<=r; i++){p*=(n-i+1);p*=i;}return p;}
#define sz 100005
int main(){
    ll n,k;
    cin>>n>>k;
    vector<pair<int,int>>vs;
    ll mx=0;
    frr(i,0,n){
        ll a,b;
        cin>>a>>b;
        mx+=b;
        vs.pb(make_pair(b,a));
    }
    ll dp[n+1][mx+1];
    int ans=0;
    dp[0][0]=0;
    for(int i=1;i<=mx;++i)
    dp[0][i]=10000000000000000;
    for(int i=0;i<n;++i){
        for(int j=0;j<=mx;++j){
            if(j>=vs[i].first){
               dp[i+1][j]=min(dp[i][j],dp[i][j-(vs[i].first)]+vs[i].second);
            }
            else{
                dp[i+1][j]=dp[i][j];
            }
            if(dp[i+1][j]<=k){
                ans=max(ans,j);
            }
            //cout<<dp[i][j]<<" ";
        }
       // cout<<endl;
    }
    //cout<<dp[n][90]<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll dp[100010][2];//桁数、１超えていない：０確定していない
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   string s;
   cin>>s;
   int n=s.size();
   dp[0][0]=1;
   for(int i=0;i<n;i++){
       (dp[i+1][1]=3*dp[i][1])%=mod;
       if(s[i]=='0'){
           (dp[i+1][0]+=dp[i][0])%=mod;
       }
       else{
            (dp[i+1][0]+=dp[i][0]*2)%=mod;
           (dp[i+1][1]+=dp[i][0])%=mod;
       }
   }
   cout<<(dp[n][0]+dp[n][1])%mod<<endl;
}

Measured memory_bytes: 2000
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int c = in.nextInt();
			int k = in.nextInt();
			int[] t = new int[n];
			for (int i = 0; i < n; i++) {
				t[i] = in.nextInt();
			}
			Arrays.sort(t);
			int ans = 0;
			int j = 0;
			int inside = 0;
			for (int i = 0; i < n; ) {
				while (j < n && t[j] <= t[i] + k) {
					++j;
					++inside;
					if (inside == c) {
						++ans;
						inside = 0;
						if (j < n && t[j] < t[i] + k) {
							break;
						}
					}
				}
				if (inside > 0) {
					++ans;
					inside = 0;
				}
				i = j;
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 35300
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  vector<ll> L(N);
  REP(i, N) cin >> L[i];
  ll ans = 0;
  REP(i, N - 2)
  for (int j = i + 1; j < N - 1; j++)
    for (int k = j + 1; k < N; k++) {
      if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
      vector<int> A(3);
      A[0] = L[i], A[1] = L[j], A[2] = L[k];
      sort(A.begin(), A.end());
      if (A[0] + A[1] > A[2]) ans++;
    }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll N;

int main() {
    cin >> N;
    vector<int> A(N + 2), B(N + 2);
    A[0] = 0;
    REP(i, N) {
        cin >> A[i + 1];
    }
    A[N + 1] = 0;
    REP(i, N) {
        B[i + 1] = B[i] + abs(A[i] - A[i + 1]);
    }
    B[N + 1] = B[N] + abs(0 - A[N]);
    FOR(i, 1, N) {
        cout << B[N + 1] - B[i + 1] + abs(A[i + 1] - A[i - 1]) + B[i - 1] - B[0] << endl;
    }
    return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
constexpr int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    // dp[i][j] = number of sequences ending with value i of length j
    // dp[i][1] = 1
    // dp[i][j] = sum dp[k][j - 1] where i * k <= n
    
    vi ranges;
    // if (n >= 30000) {
        for (int i = 1; i * i <= n; ++i) {
            ranges.push_back(i);
            ranges.push_back(n / i);
        }

        sort(all(ranges));
        ranges.erase(unique(all(ranges)), end(ranges));
    // } else {
    //     ranges.resize(n);
    //     iota(all(ranges), 1);
    // }

    int m = ranges.size();
    vi dp(all(ranges));

    for (int j = 1; j < k; ++j) {
        vi ndp(m);

        int p = m - 1;
        for (int i = 0; i < m; ++i) {
            // cout << "dp[" << i << "] = " << dp[i] << '\n';

            int v = ranges[i];
            while (1LL * v * ranges[p] > n) {
                --p;
            }

            // cout << "p = " << p << '\n';
            ndp[i] = 1LL * (ranges[i] - (i ? ranges[i - 1] : 0)) * dp[p] % MOD;
        }

        for (int i = 1; i < m; ++i) {
            ndp[i] += ndp[i - 1];
            ndp[i] %= MOD;
        }

        swap(dp, ndp);
    }

    /*
    for (int i = 0; i < m; ++i) {
        cout << ranges[i] << ' ' << dp[i] << '\n';
    }
    */

    cout << dp[m - 1] << '\n';

    return 0;
}


Measured memory_bytes: 1148
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int A, B;
    int ans;
    cin >> A >> B;
    ans = A + B;
    
    if (ans < 10) cout << ans << endl;
    else cout << "error" << endl;
}


Measured memory_bytes: 256
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e5 + 5;
void colorEdges(ll ptr, vector<vector<pair<ll, ll>>> &gra,
                vector<ll> &edgeColors, bool isVisited[])
{
    queue<ll> q;
    ll c = 0;
    set<ll> colored;
    if (isVisited[ptr])
        return;
    isVisited[ptr] = 1;
    for (ll i = 0; i < gra[ptr].size(); i++)
    {
        if (edgeColors[gra[ptr][i].second] != -1)
            colored.insert(edgeColors[gra[ptr][i].second]);
    }
    for (ll i = 0; i < gra[ptr].size(); i++)
    {
        if (!isVisited[gra[ptr][i].first])
            q.push(gra[ptr][i].first);
        if (edgeColors[gra[ptr][i].second] == -1)
        {
            while (colored.find(c) != colored.end())
                c++;
            edgeColors[gra[ptr][i].second] = c;
            colored.insert(c);
            c++;
        }
    }
    while (!q.empty())
    {
        ll temp = q.front();
        q.pop();
        colorEdges(temp, gra, edgeColors, isVisited);
    }

    return;
}
int main()
{
    ll n, u, v;
    cin >> n;
    vector<vector<pair<ll, ll>>> g(n);
    vector<ll> ec(n - 1, -1);
    bool isVisited[100000] = {0};
    for (ll i = 0; i < n - 1; i++)
        cin >> u >> v, u--, v--, g[u].push_back({v, i}), g[v].push_back({u, i});
    ll m = 0;
    colorEdges(0, g, ec, isVisited);
    for (ll i = 0; i < n - 1; i++)
        m = max(m, ec[i] + 1);
    cout << m << "\n";
    for (ll i = 0; i < n - 1; i++)
        cout << ec[i] + 1 << "\n";
    return 0;
}

Measured memory_bytes: 61824
#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 n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n){
        cout << s[i] << t[i];
    }cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n ) for( int ( i ) = 0; ( i ) < ( n ); ( i )++ )
#define repr( i, n ) for( int ( i ) = ( n ); ( i ) >= 0; ( i )-- )
#define FOR( i, m, n ) for( int ( i ) = ( m ); ( i ) < ( n ); ( i )++ )
#define all( x ) ( x ).begin(), ( x ).end()
typedef long long lint;
using namespace std;

int main( void ){
	
	int n;
	int count = 0;
	int max = 0;
	string s, x, y;
	char eng[ 35 ] = { 0 };
	cin >> n >> s;
	
	for( int i = 0; i < n - 1; i++ ){
		for( int j = 0; j <= i; j++ ){
			x += s[ j ];
			eng[ s[ j ] - 'a' ] = 1;
		}
		for( int k = i + 1; k < n; k++ ){
			y += s[ k ];
			if( eng[ s[ k ] - 'a' ] == 1 ){
				eng[ s[ k ] - 'a' ] = 2;
			}
		}
		for( int l = 0; l < 35; l++ ){
			if( eng[ l ] == 2 ){
				count++;
			}
			eng[ l ] = 0;
		}
		
		if( count > max ){
			max = count;
		}
		count = 0;
		
		x = "";
		y = "";
		
	}
	
	cout << max;
	
	return 0;
}

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

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

vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

bool is_prime(int64_t x) {
    for(int64_t i = 2; i * i <= x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll GCD = gcd(a, b);
    vector<int64_t> divisors = divisor(GCD);
    ll ans = 0;
    rep(i, divisors.size()) {
        if(is_prime(divisors[i]) == true) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
bool first_plus(vector<int> &digits){
  if(digits.at(0)+digits.at(1)==7-digits.at(3)-digits.at(2)||(digits.at(0)-digits.at(1)==7-digits.at(3)-digits.at(2))||(-digits.at(0)+digits.at(1)==7-digits.at(3)-digits.at(2))||(-digits.at(0)-digits.at(1)==7-digits.at(3)-digits.at(2))){
    return true;
  }
  else{
    return false;
  }
}
bool second_plus(vector<int> &digits){
  if((first_plus(digits)&&digits.at(0)==7-digits.at(3)-digits.at(2)-digits.at(1))||(first_plus(digits)&&-digits.at(0)==7-digits.at(3)-digits.at(2)-digits.at(1))){
    return true;
  }
  else if((!(first_plus(digits))&&digits.at(0)==7-digits.at(3)+digits.at(2)-digits.at(1))||(!(first_plus(digits))&&-digits.at(0)==7-digits.at(3)+digits.at(2)-digits.at(1))){
    return true;
  }
  else return false;
}
bool third_plus(vector<int> &digits){
  if(first_plus(digits)&&second_plus(digits)&&7-digits.at(3)-digits.at(2)-digits.at(1)>-1){
    return true;
  }
  else if(!(first_plus(digits))&&second_plus(digits)&&7-digits.at(3)+digits.at(2)-digits.at(1)>-1){
    return true;
  }
  else if(first_plus(digits)&&!(second_plus(digits))&&7-digits.at(3)-digits.at(2)+digits.at(1)>-1){
    return true;
  }
  else if(!(first_plus(digits))&&!(second_plus(digits))&&7-digits.at(3)+digits.at(2)+digits.at(1)>-1){
    return true;
  }
  else {
    return false;
  }

}

int main() {
  int ABCD;
  cin>>ABCD;
  vector<int> digits(0);
  int keta=1;
  for(int i=0;i<4;i++){
   digits.push_back((ABCD%(keta*10))/keta);
   keta*=10;
  }
  cout<<digits.at(3);
  if(first_plus(digits)){
    cout<<'+';
  }
  else{
    cout<<'-';
  }
  cout<<digits.at(2);
  if(second_plus(digits)){
    cout<<'+';
  }
  else{
    cout<<'-';
  }
  cout<<digits.at(1);
  if(third_plus(digits)){
    cout<<'+';
  }
  else{
    cout<<'-';
  }
  cout<<digits.at(0)<<'='<<7<<endl;
}

Measured memory_bytes: 256