akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
	  int p;
	  cin >> p;
	  if (i != p) {
		  ans++;
		}
	}
  if (ans <= 2) {
	  cout << "YES" << endl;
	}
  else {
	  cout << "NO" << endl;
	}
  return 0;
}


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

int main(void)
{
  uint32_t n, k;
  std::cin >> n >> k;

  uint32_t ans = k;
  for (int i = 1; i < n; i++) {
    ans *= (k-1);
  }

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

  return 0;
}

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

int main(){

  int n, k, ans=1;

  cin>>n>>k;

  for(int i=0;i<n;i++){
    if(ans*2>ans+k) ans+=k;
    else ans*=2;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int n;
	
	scanf("%d", &n);
	
	int num[110];
	
	for (int i = 0; i < n; i++){
		scanf("%d", &num[i]);
	}
	
	long dp[110][25] = {0};
	
	dp[0][num[0]] = 1;
	
	for (int i = 1; i < n - 1; i++){
		for (int j = 0; j <= 20; j++){
			if (j + num[i] <= 20){
				dp[i][j] += dp[i-1][j + num[i]];
			}
			if (j - num[i] >= 0){
				dp[i][j] += dp[i-1][j - num[i]];
			}
		}
	}
	
	printf("%ld\n", dp[n - 2][num[n-1]]);
	return (0);
}

Measured memory_bytes: 1060
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  ll h, w;
  cin >> h >> w;

  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return;
  }

  ll s = h * w;
  if (s % 2 == 0) {
    cout << s / 2 << endl;
  }
  else {
    cout << s / 2 + 1 << endl;
  }

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
from math import factorial
 
N = int(input())
lst = [int(x) for x in input().split(" ")]
mod = 10**9 + 7
dists = [lst[i+1] - lst[i] for i in range(N-1)]
ans = 0
m = N - 1
fac = factorial(m) % mod
tmp = fac

for i in range(m):
    ans += dists[i] * tmp
    ans %= mod
    tmp += fac*pow((i+2), (mod-2), mod) % mod
    
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  long double N = 0,ans = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(), A.end()); //小さい順
  ans = A[0];
  rep(i,N-1){
    ans = (ans + A[i + 1]) / 2;
  }
  cout << ans;
}

Measured memory_bytes: 256
'use strict'

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines.shift());
  const P = lines.shift().split(' ').map(x => parseFloat(x));

//console.log([N, P]);

  const dp=[];
  for(var i =0;i<N;i++){
    dp.push(Array(N+2).fill(0.0))
  }

  dp[0][0]=P[0];
  dp[0][1]=1-P[0];

  for(var i =1;i<N;i++){
    for(var j=0;j<=i+1;j++){
      let pre_left = dp[i-1][j-1];
      if(pre_left==undefined){pre_left=0.0;}

      let pre_right = dp[i-1][j];
      if(pre_right==undefined){pre_right=0.0;}

      dp[i][j] = pre_left * (1.0 - P[i]) + pre_right * P[i]
//console.log([pre_left, pre_right]);

    }
//console.log('-')
  }


//console.log(dp);

  let result = 0;

  for(var i=0;i<N/2;i++){
    result += dp[N-1][i]
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 151160
#include <iostream>

using namespace std;

int main(void) {

	int A, B, pay = 0;

	cin >> A >> B;

	if (A <= 5) {
		pay = 0;
	}
	else if (A <= 12) {
		pay = B * 0.5;
	}
	else {
		pay = B;
	}
	
	cout << pay << endl;

	return 0; 
}

Measured memory_bytes: 256
import itertools as itr

N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())

L = list(range(N))
P = list(itr.permutations(L,N))

D = 0
for i in P:
    for j in range(N-1):
        D += ((x[i[j]] - x[i[j+1]])**2 + (y[i[j]] - y[i[j+1]])**2)**0.5

print(D / len(P))


Measured memory_bytes: 13916
#include <stdio.h>
#define abs(a) ((a)>0?(a):-(a))
 
long long range(long long, long long, long long);
 
int main(){
	long long h, w;
	long long a, b, c, d, x, y, z, m;
	long long ans;
	scanf("%lld%lld", &h, &w);
	if(!(h%3 && w%3)){
		puts("0\n");
	}else{
		a = h / 3;
		b = h - a;
		c = w / 2;
		d = w - c;
		ans = range(a*w, b*c, b*d);
		a++;
		b--;
		m = range(a*w, b*c, b*d);
		if(m < ans) ans = m;
		a = w / 3;
		b = w - a;
		c = h / 2;
		d = h - c;
		m = range(a*h, b*c, b*d);
		if(m < ans) ans = m;
		a++;
		b--;
		m = range(a*h, b*c, b*d);
		if(m < ans) ans = m;
		if(w < ans) ans = w;
		if(h < ans) ans = h;
		printf("%lld\n", ans);
	}
}
 
long long range(long long a, long long b, long long c){
	if(a > b)
		if(b < c)
			if(a < c) return c - b;
			else return a - b;
		else return a - c;
	else if(a < c)
		if(b < c) return c - a;
		else return b - a;
	else return b - c;
}

Measured memory_bytes: 128
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll n,d;
	cin>>n>>d;
	
	ll count = 0;
	for (int i = 0; i < n; i++){
		ll a,b;
		cin>>a>>b;

		if(a * a + b * b  <= d * d){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3684
# -*- coding utf-8 -*-

n = int(input())
pn = list(map(int, input().split()))

ans = 0
for i in range(n - 2):
    if (pn[i + 1] > pn[i] and pn[i + 2] > pn[i + 1]) or (pn[i + 1] > pn[i+2] and pn[i] > pn[i + 1]):
        ans += 1
print(ans)



Measured memory_bytes: 3060
n,p=map(int,input().split())
al=list(map(int,input().split()))
c=0
for a in al:
    if a%2==1:
        c+=1
if c==0:
    if p==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    while (s.length()) {
        if (s.length() >= 5 && s.substr(s.length() - 5, 5) == "dream") {
            for (int i = 0; i < 5; i++) s.pop_back();
        }
        else if (s.length() >= 7 && s.substr(s.length() - 7, 7) == "dreamer") {
            for (int i = 0; i < 7; i++) s.pop_back();
        }
        else if (s.length() >= 5 && s.substr(s.length() - 5, 5) == "erase") {
            for (int i = 0; i < 5; i++) s.pop_back();
        }
        else if (s.length() >= 6 && s.substr(s.length() - 6, 6) == "eraser") {
            for (int i = 0; i < 6; i++) s.pop_back();
        }
        else {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
const int N = 3005;
const ll mod = 998244353;
ll ans=0,f[N][N];
int main()
{
	int n,s,a[N];	
	cin>>n>>s;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=s;j++)f[i][j]=f[i-1][j];
		f[i][a[i]]=(f[i][a[i]]+i)%mod;
		for(int j=0;j+a[i]<=s;j++)
		f[i][j+a[i]]=(f[i][j+a[i]]+f[i-1][j])%mod; 
		ans=(ans+f[i][s])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

bool sortby1(pair<int,int> &a, pair<int,int> &b){
    return a.first<b.first;
}
bool sortby2(pair<int,int> &a, pair<int,int> &b){
    return a.second>b.second;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<string> X(n);
    for(int i=0;i<n;i++){
        cin>>X[i];
    }
    int open=0,close=0;
    vector<pair<int,int>> reqpos;
    vector<pair<int,int>> reqneg;
    for(int i=0;i<n;i++){
        int val=0;
        int minval=0;
        int maxval=0;
        for(int j=0;j<X[i].length();j++){
            if(X[i][j]=='('){
                val++;
                open++;
            }
            else{
                val--;
                close++;
            }
            if(val<0){
                val=0;
                minval++;
            }        }
        val=0;
        for(int j=X[i].length()-1;j>=0;j--){
            if(X[i][j]==')'){
                val++;
            }
            else{
                val--;
            }
            if(val<0){
                val=0;
                maxval++;
            }
        }
        if(minval==0 && maxval==0){
            continue;
        }
        else{
            if(maxval-minval>=0){
                reqpos.push_back({minval,maxval});
            }
            else{
                reqneg.push_back({minval,maxval});
            }
        }
    }
    if(open!=close){
        cout<<"No\n";
        return 0;
    }

    sort(reqpos.begin(),reqpos.end(), sortby1);
    sort(reqneg.begin(), reqneg.end(), sortby2);
    int diff=0;
    for(int i=0;i<reqpos.size();i++){
        if(diff<reqpos[i].first){
            cout<<"No\n";
            return 0;
        }
        diff+=reqpos[i].second-reqpos[i].first;
    }
    for(int i=0;i<reqneg.size();i++){
        if(diff<reqneg[i].first){
            cout<<"No\n";
            return 0;
        }
        diff+=reqneg[i].second-reqneg[i].first;        
    }
    cout<<"Yes\n";
}

Measured memory_bytes: 42480
#include<stdio.h>
 
int main(void){
    int a,b,an;
    char op;
    for(;;){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        switch(op){
            case '+':
                an=a+b;
                break;
            case '-':
                an=a-b;
                break;
            case '*':
                an=a*b;
                break;
            case '/':
                an=a/b;
                break;
        }
        printf("%d\n",an);
    }
    return 0;
}


Measured memory_bytes: 2032
#include <iostream>
#include <set>
using namespace std;

int N, a;
set<int> st;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        if (st.find(a) == st.end())
            st.insert(a);
        else
            st.erase(a);
    }
    cout << st.size() << endl;
}


Measured memory_bytes: 4864
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	while(1){
		int a,b;
		char op;
		scanf("%d %c %d", &a,&op,&b);
		if(op=='+'){
			cout<< a+b<<endl;
		}
		if(op=='-'){
			cout<< a-b<<endl;
		}
		if(op=='*'){
			cout<< a*b<<endl;
		}
		if(op=='/'){
			cout<< a/b<<endl;
		}
		if(op=='?'){
			break;
		}
	}
return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;

int main(){
	long long n,k;
	cin>>n>>k;
	long long ans=1;
	rep(i,n){
		if(i==0)ans*=k;
		else ans*=k-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef long long int int64;

typedef struct sushi{
  int t,d;
} node;

int cmpSushi(const void *a,const void *b){
  return -(((node *)a)->d-((node *)b)->d);
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  node *a=(node *)calloc(n,sizeof(node));
  int i;
  for(i=0;i<n;i++) cin >> a[i].t >> a[i].d;
  qsort(a,n,sizeof(node),cmpSushi);
  int *used=(int *)calloc(n+1,sizeof(int));
  int *stack=(int *)calloc(n,sizeof(int));
  int top=0;
  int cnt=0;
  int64 sum=0;
  for(i=0;i<k;i++){
    sum+=a[i].d;
    if(used[a[i].t]){
      stack[top++]=a[i].d;
    } else {
      used[a[i].t]=1;
      cnt++;
    }
  }
  int64 max=sum+(int64)cnt*cnt;
  for(i=k;i<n && top>0;i++){
    if(used[a[i].t]) continue;
    used[a[i].t]=1;
    sum+=a[i].d-stack[--top];
    cnt++;
    if(max<sum+(int64)cnt*cnt) max=sum+(int64)cnt*cnt;
  }
  cout << max << endl;
}
int main(){
  run();
  return 0;
}

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    if(n==1)cout<<0<<endl;
    else{
    int cnth=0,cntb=0;
    if(s[0]=='R'&&s[1]=='R')cnth++;
    if(s[0]!=s[1])cntb++;
    if(s[s.size()-1]=='L'&&s[s.size()-2]=='L')cnth++;
    REP(i,1,n-1){
        if(s[i]=='L'&&s[i-1]=='L')cnth++;
        if(s[i]=='R'&&s[i+1]=='R')cnth++;
        if(s[i]!=s[i+1])cntb++;
    }
        if(cntb>2*k)cout<<cnth+2*k<<endl;
        else cout<<cnth+cntb<<endl;
    }
}

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

int a[] = { 1, 3, 5, 7, 8, 10, 12 };
int b[] = { 4, 6, 9, 11 };
int c[] = { 2 };

char check(int x) {
	char res;
	for (int i = 0; i < 7; i++) {
		if (x == a[i])res = 'a';
	}
	for (int i = 0; i < 4; i++) {
		if (x == b[i])res = 'b';
	}
	for (int i = 0; i < 1; i++) {
		if (x == c[i])res = 'c';
	}

	return res;
}

int main() {
	int x, y;
	cin >> x >> y;

	if (check(x) == check(y)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <ciso646>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <utility>
#include <vector>


typedef long long Index;
typedef std::pair<Index, Index> Position;
typedef std::map<Position, Index> Counter;


constexpr int MAX_J = 9;
constexpr int SQUARE_SIZE = 3;


class Board {
public:
    Board (Index height, Index width) : height_(height), width_(width) {}
    void paintCell(Index r, Index c){
        for (auto k = 0; k < SQUARE_SIZE; k++)
        {
            for (auto l = 0; l < SQUARE_SIZE; l++)
            {
                auto sr = r - k;
                auto sc = c - l;
                if (insideBoard(sr, sc))
                {
                    counter_[std::make_pair(sr, sc)]++;
                }
            }
        }
    }
    std::vector<Index> summarize() {
        std::vector<Index> ans(MAX_J + 1);
        for (const auto& elem : counter_)
        {
            if (1 <= elem.second and elem.second <= MAX_J)
            {
                ans[elem.second]++;
            }
        }
        ans[0] = (height_ - 2) * (width_ - 2) - std::accumulate(ans.begin(), ans.end(), 0LL);
        return ans;
    }
private:
    Index height_;
    Index width_;
    Counter counter_;
    bool insideBoard(Index r, Index c) const {
        return 0 <= r and r < height_ - 2 and 0 <= c and c < width_ - 2;
    }
};


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    Index h, w, n;
    std::cin >> h >> w >> n;
    Board board(h, w);
    for (auto i = 0; i < n; i++)
    {
        Index a, b;
        std::cin >> a >> b;
        a--;
        b--;
        board.paintCell(a, b);
    }
    auto ans = board.summarize();
    for (const auto& x : ans)
    {
        std::cout << x << std::endl;
    }
    return EXIT_SUCCESS;
}

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

using namespace std;

int main() {
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	long long a[n], b[m];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i) {
			a[i] += a[i - 1];
		}
		if (a[i] <= k) {
			ans = i + 1;
		}
	}
	
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (i) {
			b[i] += b[i - 1];
		}
		if (b[i] <= k) {
			ans = max(ans, i + 1);
		}
	}
	
	
	
	int lib = -1;
	for (int i = 0; i < m; i++) {
		if (b[i] + a[0] <= k) {
			lib = i;
		} else {
			break;
		}
	}
	
	if (lib == -1) {
		printf("%d\n", ans);
		return 0;
	}
	
	ans = max(ans, lib + 2);
	
	for (int i = 1; i < n; i++) {
		if (a[i] + b[lib] <= k) {
			ans = max(ans, i + lib + 2);
		} else {
			while (lib >= 0 && a[i] + b[lib] > k) {
				lib--;
			}
			if (lib < 0) {
				break;
			}
			ans = max(ans, i + lib + 2);
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 6848
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
    long long val,id;
    friend bool operator <(node b,node c){if(b.val<c.val) return true;if(b.val==c.val&&b.id<c.id) return true;return false;}
}a[100050];
long long n,ans[100050],num[100050];
int main(){
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++){scanf("%lld",&a[i].val);a[i].id=i;num[i]=a[i].val;}
    sort(a+1,a+n+1);
    for(long long i=1,j=0;i<=n;i++){
    	while(a[i].val>num[j]) j++;
        ans[j]+=(a[i].val-a[i-1].val)*(n-i+1);
    }
    for(long long i=1;i<=n;i++) printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 4224
N, K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [[]for i in range(N)]

dp[0] = 0
dp[1] = abs(lst[0] - lst[1])
for i in range(2, N):
    ans = []
    for j in range(min(i, K)):
        ans.append(dp[i-j-1] + abs(lst[i-j-1] - lst[i]))
    dp[i] = min(ans)

print(dp[-1])

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    string S; cin >> S;
    int Q; cin >> Q;
    int T, F;
    string C;
    string D, E;
    bool J = true;
    for(int i = 0; i < Q; i++) {
        cin >> T;
        if(T == 1) {
            if(J == true) {
                J = false;
            }
            else {
                J = true;
            }
        }
        else {
            cin >> F >> C;
            if(F == 1) {
                if(J == true) {
                    D = C + D;
                }
                else {
                    E += C;
                }
            }
            else {
                if(J == true) {
                    E += C;
                }
                else {
                    D = C + D;
                }
            }
        }
    }
    if(J == false) {
        reverse(D.begin(), D.end());
        reverse(S.begin(), S.end());
        reverse(E.begin(), E.end());
        S = E + S + D;
    }
    else {
        S = D + S + E;
    }
    cout << S << endl;
}

Measured memory_bytes: 1360
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 5010;
const int M = 210;

int n,m;
LL a[N];
int b[N][M],now[M];
LL tree[N][N];

LL maxll(LL x,LL y){
	if (x>y)return x;
	return y;
}

void add(int i,int x,int v){
	while(x<=n){
		tree[i][x]=tree[i][x]+v;
		x+=x&-x;
	}
}

void addv(int l1,int r1,int l2,int r2,int v){
	fo(i,l1,r1){
		add(i,l2,v);
		add(i,r2+1,-v);
	}
}

LL getv(int i,int x){
	LL ans=0;
	while(x){
		ans=ans+tree[i][x];
		x-=x&-x;
	}
	return ans;
}

int main(){
	n=get();m=get();
	fo(i,2,n)a[i]=get();
	fo(i,1,n)a[i]=a[i]+a[i-1];
	fo(i,1,n)fo(j,1,m)b[i][j]=get();
	fo(j,1,m){
		fo(i,1,n){
			int l=i,r=i;
			while(l>1&&b[l-1][j]<b[i][j])l--;
			while(r<n&&b[r+1][j]<=b[i][j])r++;
			addv(l,i,i,r,b[i][j]);
		}
	}
	LL ans=0;
	fo(i,1,n)
		fo(j,i,n)
		ans=maxll(ans,getv(i,j)-(a[j]-a[i]));
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    int sx,sy,tx,ty; cin >>sx >> sy >> tx >> ty;

    for(int i = 0; i < tx - sx; i++) cout << 'R';
    for(int i = 0; i < ty - sy; i++) cout << 'U';
    for(int i = 0; i < tx - sx; i++) cout << 'L';
    for(int i = 0; i < ty - sy; i++) cout << 'D';
    cout << 'L';
    for(int i = 0; i < ty - sy + 1; i++) cout << 'U';
    for(int i = 0; i < tx - sx + 1; i++) cout << 'R';
    cout << 'D';
    cout << 'R';
    for(int i = 0; i < ty - sy + 1; i++) cout << 'D';
    for(int i = 0; i < tx - sx + 1; i++) cout << 'L';
    cout << 'U';
    cout <<endl;
    
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;

    rep2(i, 1, 10){
        rep2(j, 1, 10){
            if(i*j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll mod = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

void solve(){
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n,0);
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll p = a[0];
	ll in = 1;
	for(ll i=k;i<n;i++){
		if(a[i]>p){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
		p = a[in];in++;
	}
	
}

int main(){
    fastio;
    ll t=1;//cin>>t;
    for(ll i=1;i<=t;i++){
    	solve();
	}	
}




Measured memory_bytes: 4800
q=list(map(int,input().split()))
grid=[]
def ze(x,y):
  z=[]
  if y[0]+1<x[0]:
    z.append([y[0]+1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]+1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]+1,y[1]-1])
  if y[0]-1>=0:
    z.append([y[0]-1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]-1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]-1,y[1]-1])    
  if y[1]+1<x[1]:
    z.append([y[0],y[1]+1])
  if y[1]-1>=0:
    z.append([y[0],y[1]-1])
  return(z)
for i in range(q[0]):
    y=input()

    grid.append([i for i in y])
  
for i in range(q[0]):
    for j in range(q[1]):
        if grid[i][j]=='.':
            
          
            lamsa=ze(q,[i,j])
            
            count=0
            
            for k in range(len(lamsa)) :
                
                
                if grid[lamsa[k][0]][lamsa[k][1]] == '#' :
                  count+=1
            grid[i][j]=count      
                
for i in range(q[0]):
    pr=''
    for j in range(q[1]):
        pr=pr+str(grid[i][j])
    print(pr)
           

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        String po=s.nextLine();
        char a[]=po.toCharArray();
        int i=0,tmp=0,check=0;
        int b[]=new int[200];
        for(char a1 : a){
            //System.out.println(a1);
            if(a1==' '){
                if(check==1){
                    b[i]=tmp;
                    check=0;
                    i++;
                    tmp=0;
                }
            }
            else if(a1=='+'){ b[i-2]=b[i-2]+b[i-1]; i--;}
            else if(a1=='-'){ b[i-2]=b[i-2]-b[i-1]; i--;}
            else if(a1=='*'){ b[i-2]=b[i-2]*b[i-1]; i--;}
            else {
                if(check==1){
                    tmp=tmp*10+a1-'0';
                }else{
                    tmp=a1-'0';
                }
                check=1;
            }
        }
        System.out.println(b[0]);
    }
}


Measured memory_bytes: 26228
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int n,s,x[N];
ll t[N],p[N];

void solve(int l,int r) {
	if (x[r]<s) {
		fo(i,l,r) t[i]=s-x[i];
		return;
	}
	if (x[l]>s) {
		fo(i,l,r) t[i]=x[i]-s;
		return;
	}
	if (p[l]>=p[r]) {
		p[l]+=p[r];
		solve(l,r-1);
		t[r]=t[l]+x[r]-x[l];
	} else {
		p[r]+=p[l];
		solve(l+1,r);
		t[l]=t[r]+x[r]-x[l];
	}
}

int main() {
	n=read();s=read();
	fo(i,1,n) x[i]=read(),p[i]=read();
	solve(1,n);
	printf("%lld\n",max(t[1],t[n]));
	return 0;
}

Measured memory_bytes: 4736
#include <cstdio>
#include <iostream>
const int N = 1e5 + 5;
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
const int inf = 1e9;
int n, m, que[N], qn, sgn[N], xl[N], xr[N], flag, fa[N];
int tot, first[N], next[N << 1], end[N << 1];
inline void AddEdge(int x, int y) {
	next[++tot] = first[x], first[x] = tot, end[tot] = y;
	next[++tot] = first[y], first[y] = tot, end[tot] = x;
}
int main() {
	n = Get();
	for (int i = 1; i < n; ++i) AddEdge(Get(), Get());
	
	m = Get(), flag = true;
	for (int i = 1; i <= n; ++i) sgn[i] = -1, xl[i] = -inf, xr[i] = inf;
	for (int i = 1; i <= m; ++i) { 
		int x = Get(), val = Get();
		if (val < xl[x] || val > xr[x]) flag = false;
		xl[x] = xr[x] = val, sgn[x] = val & 1;
	}
	
	que[qn = 1] = 1;
	for (int ql = 1, u; u = que[ql], ql <= qn; ++ql)
		for (int k = first[u], v; v = end[k], k; k = next[k])
			if (v != fa[u]) fa[v] = u, que[++qn] = v;
		
	for (int qr = qn, u; u = que[qr], qr; --qr) 
		for (int k = first[u], v; v = end[k], k; k = next[k]) 
			if (v != fa[u]) {
				int vl = xl[v] - 1, vr = xr[v] + 1;
				if (vr < xl[u] || xr[u] < vl) flag = false;
				xl[u] = std :: max(xl[u], vl);
				xr[u] = std :: min(xr[u], vr);
				
				if (sgn[v] >= 0) 
					if (sgn[u] >= 0 && sgn[u] == sgn[v]) flag = false;
					else sgn[u] = sgn[v] ^ 1;
			}
	
	for (int ql = 1, u; u = que[ql], ql <= qn; ++ql) {
		if (fa[u]) {
			xl[u] = std :: max(xl[u], xl[fa[u]] - 1);
			xr[u] = std :: min(xr[u], xr[fa[u]] + 1);
			sgn[u] = sgn[fa[u]] ^ 1;
		}
		
		if (xl[u] > xr[u] || xl[u] == xr[u] && sgn[u] >= 0 && (xl[u] & 1) != sgn[u]) flag = false; 
		
		xl[u] = xr[u] = xl[u] + xr[u] >> 1;
		if (sgn[u] >= 0 && (xl[u] & 1) != sgn[u]) ++xl[u], ++xr[u];
		sgn[u] = xl[u] & 1;
	}
	
	if (!flag) {
		puts("No");
		return 0;
	}
	else {
		puts("Yes");
		for (int i = 1; i <= n; ++i) printf("%d\n", xl[i]);
	}
}

Measured memory_bytes: 4864
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    vector<int> a(3);
    rep(i, 3)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    if (a[0] == 5 && a[1] == 5 && a[2] == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        int count = 0;
        for(int i = 0; i < 2; i++){
            if(a > b){
                count += a;
                a--;
            }else{
                count += b;
                b--;
            }
        }
        
        System.out.println(count);
    }
}

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

int main() {
  string S;
  cin >> S;
  int d = S.size() - 1;
  long long t = 0;

  for (int b = 0; b < (1 << d); ++b) {
    int p = 0;
    for (int i = 0; i <= d; ++i) {
      if (b & (1 << i)) {
        t += stoll(S.substr(p, i + 1 - p));
        p = i + 1;
      }
      if (i == d) {
        t += stoll(S.substr(p));
        p = 0;
      }
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#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++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

long long  a, b, c, d;

int main(){
    cin >> a >> b >> c >> d;
    long long ans = 0;
    int ac = a*c, ad = a*d, bc = b*c, bd = b*d;
    if(b > 0 && d < 0){
        ans = a*d;
    }else if (b < 0 && d > 0){
        ans = b*c;
    }else if(b < 0 && d < 0){
        ans = a*c;
    }else {
        ans = b*d;
    }
    if(a*c > ans) ans = a*c;
    cout << ans << endl;
}

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

int main()
{

	int n;
	cin >> n;
	map<int, int> m;
	vector<int> v(n+1);
	for (int i=1;i<=n;++i)
	{
		int a;
		cin >> a;
		a-=i;
		v[i]=a;
		//fprintf(stderr,"i: %d a: %d\n",i,a);
		m[a]++;
		//m.insert(make_pair(a,i));
	}

	int64_t count=0;
	for (int i=1;i<=n;++i)
	{
		int lookfor=-v[i]-2*i;
		if (m.count(lookfor)>0)
		{
			count+=m[lookfor];
		}
		//count+=m.count(lookfor);
		//fprintf(stderr,"i: %d lookfor: %d count %d\n",i,lookfor,m.count(lookfor));
	}
	cout << count << endl;
}






Measured memory_bytes: 12584
from collections import deque


def main():
    h, w = map(int, input().split())
    inf = 10 ** 9 + 7
    grid = [list(input()) for _ in range(h)]
    count = [[inf for _ in range(w)] for _ in range(h)]
    d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
    wall = 0
    count[0][0] = 1
    for g in grid:
        wall += g.count("#")
    s = deque([[0, 0]])
    while s:
        y, x = s.popleft()
        if grid[y][x] == ".":
            grid[y][x] = "#"
            for dy, dx in d:
                if 0 <= y + dy < h and 0 <= x + dx < w and grid[y + dy][x + dx] == ".":
                    count[y + dy][x + dx] = min(count[y + dy][x + dx], count[y][x] + 1)
                    s.append([y + dy, x + dx])
    print(h * w - count[-1][-1] - wall if count[-1][-1] != inf else -1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	map < int,int >x; 
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		int key=a[i]-1;
		if(x[key]==0)
		{
			x[a[i]]=1;
		}
		else
		{
			x[a[i]]=x[key]+1;
		}
	}
	map < int,int >:: iterator it;
	int max=0;
	for(it=x.begin();it!=x.end();it++)
	{
		if(it->second>max)
		max=it->second;
	}
	cout<<n-max<<endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*power((a*a)%mod,n/2))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int md = 998244353;
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


signed main()
{
    showoff;
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b);
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...  

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n;
    cin>>n;
    if(n==1)
        cout<<"Hello World"<<endl;
    else
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N;
  cin >> N;
  int A[N];
  rep(i, 0, N) cin >> A[i];

  int ans=0;
  rep(i, 0, N) {
    ans++;
    while (N > i+1 && A[i] == A[i+1]) i++;
    if (N == i+1) break;
    if (A[i] < A[i+1])  while (N > i+1 && A[i] <= A[i+1]) i++;
    else                while (N > i+1 && A[i] >= A[i+1]) i++;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
bool ok(string S) {
    if(S == "") return true;
    if(S.substr(0, 2) == "hi") {
        return ok(S.substr(2, S.size()));
    }
    return false;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(ok(S)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
  int N,a[200];
  cin >> N;
  for(int i=0;i<N;i++)cin>>a[i];
  int ans=0;
  while(true){
    bool existodd=false;
    for(int i=0;i<N;i++){
      if(a[i]%2!=0)existodd=true;
    }
    if(existodd)break;
  for(int i=0;i<N;i++){
   
      a[i]/=2;    
  }
    ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	int y = 0;
	int n = x;
	while(n){
		y += n % 10;
		n /=10;
	}
	if(x % y == 0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
// ITP1_7_B

#include <iostream>
using namespace std;

int main()
{
	int n, x, smin, smax;
	while (1) {
		int ans = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) { break; }
		for (int i = 1; i <= n - 2; i++) {
			smin = i * 3 + 3;
			smax = i + 2 * n - 1;
			if (smax < x) {
				continue;
			}
			else if (smin > x) {
				break;
			}
			for (int j = i + 1; j <= n - 1; j++) {
				smin = i + j * 2 - 1;
				smax = i + j + n;
				if (smax < x) {
					continue;
				}
				else if (smin > x) {
					break;
				}
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) {
						ans++;
						break;
					}
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3088
n,m = map(int,input().split())
s,c = [0]*m,[0]*m
for i in range(m):
    s[i],c[i] = map(int,input().split())
    s[i] -= 1
ans = ''
number = ['0']*n
for j in range(m):
    flag_1 = (number[s[j]] != '0' and number[s[j]] != str(c[j]))
    flag_2 = (s[j] == 0 and c[j] == 0 and n != 1)
    if flag_1 or flag_2:
        ans = '-1'
        break
    else:
        number[s[j]] = str(c[j])
else:
    if number[0]  == '0' and  n != 1:
        number[0] = '1'
    ans = ''.join(number)

print(ans)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;


int main() {
	string s;
	cin >> s;
	ll sum = 0;
	for (ll i = 0, len = s.length(); i < len; i++) {
		sum += s[i] - '0';
	}
	if (sum % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

long long cal(long long x) {
    if(x <= 0) return 0; 
    return x * (x - 1) / 2LL;
}

int main() {
    int n;
    cin >> n;
    vector<int> arr(n), cnt(n + 1);
    for(int &x : arr) cin >> x, cnt[x]++;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += cal(cnt[i]);
    }
    for(int i = 0; i < n; i++) {
        ans -= cal(cnt[arr[i]]);
        ans += cal(cnt[arr[i]] - 1);
        cout << ans << '\n';
        ans -= cal(cnt[arr[i]] - 1);
        ans += cal(cnt[arr[i]]);
    } 
    return 0;   
}

Measured memory_bytes: 4096
def insertionSort(A, N, g):
    global cnt
    for i in range(g, N):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v

def shellSort(A, N):
    global cnt
    cnt = 0

    G = []
    g = 1
    while g <= N:
        G.insert(0, g)
        g = 3 * g + 1

    for g in G:
        insertionSort(A, N, g)

    print len(G)
    print " ".join(str(g) for g in G)
    print cnt
    for i in A:
        print i

if __name__ == "__main__":
    N = input()
    A = []
    for i in range(N):
        A.append(input())
    shellSort(A, N)

Measured memory_bytes: 69800
#include<stdio.h>

int main(void){

  int n;
  scanf("%d",&n);

  int a[n];
  int b[n-1];
  int i,j;
  int ans=0;

  for(i=0;i<n-1;i++){
    scanf("%d",&b[i]);
  }

  a[0]=b[0];
  for(i=0;i<n-2;i++){
    if(b[i]>b[i+1]){
      a[i+1]=b[i+1];
    }
    else if(b[i]<=b[i+1]){
      a[i+1]=b[i];
    }
  }

  a[n-1]=b[n-2];

  for(i=0;i<n;i++){
    //printf("%d\n",a[i]);
    ans=ans+a[i];
  }
  printf("%d",ans);





    return 0;
}


Measured memory_bytes: 128
from operator import itemgetter

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    tmp = list(map(int,input().split()))
    BC.append(tmp)
A.sort(reverse=True)
BC.sort(key=itemgetter(1),reverse=True)

l = 0
r = N-1
flg = False
for k in range(M):
    # l tansaku
    for p in range(l,N):
        if BC[k][1] > A[p]:
            l = p
            break
        elif p == N-1:
            flg = True
    #break
    if flg or r < l: break
    tmpC = BC[k][1]
    #chikan
    for o in range(BC[k][0]):
        if r < l or r == -1:
            flg = True
            break
        A[r] = tmpC
        r -= 1

print(sum(A))


Measured memory_bytes: 32976
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = Long.parseLong(in.nextLine());
		solve(n);
	}
	
	public static void solve( long n ) {
		if ( n%2 == 0 ) {
			System.out.println(n);
		} else {
			System.out.println(n*2);
		}
	}
}

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

int sumofDigits(int i){
  int sum = 0;
  while(i > 0){
    sum = sum + i%10;
    i = i/10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for(int n = 1; n<=N; ++n){
    int sum = sumofDigits(n);
    if(A <= sum and sum <= B){
      total = total + n;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b == c + d)
        cout << "Balanced";
    else if (a + b > c + d)
        cout << "Left";
    else
        cout << "Right";
}


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

using namespace std;

int main() {
	string S;
	cin >> S;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			if (S[i] == S[j]) count++;
		}
	}
	if (count == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3612
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        n: i64,
        a: i64,
        b: i64,
    }
    if (n < 2 && a != b) || a > b { println!("0") }
    else { println!("{}", (b - a) * (n - 2) + 1) }
}



Measured memory_bytes: 4352
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1000000007; /// 1e9+7
const int MAX = 100005;     /// 1e5+5
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}

int n;
bool visit[MAX][100];
int summ(int x){
    int ret = 0;
    while(x>0){
        ret += x%10;
        x/=10;
    }
    return ret;
}
void dfs(int num, int sum){
    if(sum>=99) return;
    if(num>=n) return;
    if(visit[num][sum]) return;
    visit[num][sum]=true;
    for(int i=0; i<10; i++)
        dfs((num*10+i)%n, sum+i);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++){
        dfs(i, summ(i));
    }
    int ans = summ(n);
    for(int i=1; i<99; i++){
        if(visit[0][i]) ans = min(ans, i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 233344
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string s,s2;
            cin>>s>>s2;
            int ans=0,i;
            for(i=0;i<s.length();++i)
                if(s[i]!=s2[i])
                    ++ans;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3880
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i, A in enumerate(L):
    for j, B in enumerate(L[i + 1:], start=i + 1):
        right = bisect_left(L, A + B)
        ans += right - j - 1

print(ans)

Measured memory_bytes: 3188