akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

void solve() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T> bool inline chmin(T& a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool inline chmax(T& a, T b) { if (a < b) {a=b;return 1;} return 0; }
int N;
long long W, weight[110], value[110];
long long dp[110][100010] = {0};
int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];
	for (int i = 0; i < N; i++) {
		for (int sum_w = 0; sum_w <= W; sum_w++) {
			if (sum_w - weight[i]>=0) {
				chmax(dp[i + 1][sum_w], dp[i][sum_w-weight[i]]+value[i]);
			}

			chmax(dp[i + 1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 79360
#include<iostream>
#define NIL -1

struct Node
{
    int parent, left_child, right_sibling ;
} ;

Node tree[100001] ;
int depth[100001] ;

void print_node( int u )
{
    std::cout << "node " << u << ": " ;
    std::cout << "parent = " << tree[u].parent <<", " ;
    std::cout << "depth = " << depth[u] << ", " ;
    if( tree[u].parent == NIL )
    {
        std::cout << "root, " ;
    }
    else if( tree[u].left_child == NIL )
    {
        std::cout << "leaf, " ;
    }
    else
    {
        std::cout << "internal node, " ;
    }
    std::cout << "[" ;
    for( int c = tree[u].left_child, flag = 0 ; c != NIL ; c = tree[c].right_sibling )
    {
        if( flag ) 
        {
            std::cout << ", " ;
        }
        std::cout << c ;
        flag = 1 ;
    }
    std::cout << "]" << std::endl ; 
}

void make_depth( int root, int stone = 0 )
{
    depth[root] = stone ;
    if( tree[root].right_sibling != NIL )
    {
        make_depth( tree[root].right_sibling, stone ) ;
    }
    if( tree[root].left_child != NIL )
    {
        make_depth( tree[root].left_child , stone+1 ) ;
    }

}

int main()
{
    int n ; 
    std::cin >> n ;
    for( int i = 0 ; i < n ; ++i )
    {
        tree[i].parent = tree[i].left_child = tree[i].right_sibling = NIL ; 
    }
    int a, b, c, d ;
    for( int i  = 0 ; i < n ; ++i )
    {
        std::cin >> a >> b ;
        for( int j = 0 ; j < b ; ++j )
        {
            std::cin >> c ;
            if( j == 0 )
            {
                tree[a].left_child = c ;
            }
            else
            {
                tree[d].right_sibling = c ;
            }
            d = c ;
            tree[c].parent = a ;
        }
    }
    int root ;
    for( int i = 0 ; i < n ; ++i )
    {
        if( tree[i].parent == NIL )
        {
            root = i ;
        }
    }

    make_depth( root ) ;
    for( int i = 0 ; i < n ; ++i )
    {
        print_node( i ) ;
    }
    return 0 ;
}



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


int main() {
	string s;
	cin >> s;
	int flag = 0;
	for (int i = 0; i < s.size()-1; i++) {
		if ((s[i] == 'A') && (s[i + 1] == 'C')) {
			flag = 1;
			break;
		}
	}
	if (flag==1) {
		cout << "Yes"<<endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc126/tasks/abc126_e

######### Union Find ########
class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.root = [-1] * n
        self.rnk = [0] * n

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def count(self, x):
        return -self.root[self.find(x)]

if __name__ == '__main__':
    n, m = map(int, input().split())
    uf = UnionFind(n)

    for _ in range(m):
        xi, yi, zi = map(int, input().split())
        xi -= 1
        yi -= 1
        uf.unite(xi, yi)

    count = 0
    for i in range(n):
        if uf.root[i] < 0:
            count += 1
    print(count)


Measured memory_bytes: 72920
n = int(input())
ans = 0 
for i in range(1, n+1):
  if i % 3 == 0 and i % 5 == 0:
    pass 
  elif i % 3 == 0:
    pass 
  elif i % 5 == 0:
    pass 
  else:
    ans += i 

print(ans)

Measured memory_bytes: 65080
#include <iostream>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int h,r;
    cin>>h>>r;
    if(h+r==0){
        cout<<0<<"\n";
    }
    if(h+r>0){
        cout<<1<<"\n";
    }
    if(h+r<0){
        cout<<-1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int>> G;
vector<double> dp;

double solve(int k) {
    dp[N - 1] = 0;
    for(int i=N-2; i>=0; --i) {
        double ma = -1;
        dp[i] = 0.0;
        for(int to : G[i]) {
            dp[i] += dp[to];
            if(ma < dp[to]) ma = dp[to];
        }
        if(i == k && G[i].size() > 1) {
            dp[i] = (dp[i] - ma) / (G[i].size() - 1) + 1;
        } else {
            dp[i] = dp[i] / G[i].size() + 1;
        }
    }
    return dp[0];
}

int main() {
    cin >> N >> M;
    G.resize(N); dp.resize(N);
    for(int i=0; i<M; ++i) {
        int s, t; cin >> s >> t;
        G[s - 1].push_back(t - 1);
    }

    double res = solve(N - 1);
    for(int k=N-2; k>=0; --k) {
        res = min(res, solve(k));
    }
    cout << fixed << setprecision(10) << res << endl;
}

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

int main()
{
    int N, Q;
    cin >> N >> Q;
    string str;
    cin >> str;
    
    vector<int> s(N+1, 0);
    for (int i = 0; i < N; i++) {
        if (i + 1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    for (int q = 0; q < Q; q++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        cout << s[r] - s[l] << endl;
    }
}

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

int main() {
    string s;
    cin >> s;
    string res;
    int cnt = 0;
    for(int i=s.size()-1; i>=0; --i) {
        if(s[i] == 'B') {
            cnt++;
        } else {
            if(cnt > 0) {
                cnt--;
            } else {
                res += s[i];
            }
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull  unsigned long long ;
#define _CRT_SECURE_NO_WARNINGS 
const double  pai= acos(-1.0);
const int max1=5e5+5;
int a[max1],maxlen[max1];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int i,k,sum=1,n,j,sum1=1;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sum=1;
	for(i=1;i<n;i++)
	{
	if(a[i]>=a[i+1])sum++;
	else
	sum=1;
	sum1=max(sum,sum1);
	}
	cout<<sum1-1<<endl;
	return 0;
 }

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
int main(){
	string S;
	cin >> S;
	
	int count = 0;
	for(int i = 0; i < 4; i++){
		for(int j = i+1; j < 4; j++){
			if(S[i] == S[j])
				count++;
		}  
	}
	cout << ((count == 2)?"Yes":"No") << endl;
}


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

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

  int ans=1;
  for(int i=2; i<33; i++){
    int y=i*i;
    while(y<=x){
      ans=max(ans,y);
      y*=i;
    }
  }
  cout<<ans<<endl;
}

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

int main(){
                                                                     

    int n, i;

    int al = 1;

    int k = 1;

    
    cin >> n;

    vector<int> a(n);


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> a.at(i);

         al *= 3;

         if( a.at(i) % 2 == 0 ) k *= 2;

         }


    cout << al - k << endl;


    return 0;

    }

Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int k,s;
    cin>>k>>s;
    int cnt=0;
    for(int i=0;i<=k;i++){
        for(int j = 0;j<=k;j++){
            if((s-i-j)<=k&&(s-i-j)>=0){
                //cout<<i<<j<<(s-i-j)<<endl;
                cnt+=1;
            }
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3580
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import javax.lang.model.util.ElementScanner6;

class Main
{
    long ways[][];

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int C = sc.nextInt();
        // System.out.print(V+" "+E);
        Main object=new Main();
        sc.nextLine();
        object.ways=new long[R+1][C+1];
        object.ways[1][1]=1;
        char ch;String str;
        for(int i=0;i<R;i++)
        {
            str=sc.next();
            for(int j=0;j<C;j++)
            {
                 ch=str.charAt(j);
                 if(i==0&&j==0)
                   object.ways[1][1]=1;
                 else if(ch=='.')
                   object.ways[i+1][j+1]=(object.ways[i][j+1]+object.ways[i+1][j])%1000000007;
                 else
                   object.ways[i+1][j+1]=0;
            }
            sc.nextLine();
        }
        System.out.println(object.ways[R][C]);
        sc.close();
     }
}

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const int MOD = 1000000007;
const int MAX = 200000;

vector<pair<ll,ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (long long a = 2; a * a <= n; a++){
    if(n % a != 0) continue;
    ll ex = 0; //指数
    while(n % a == 0){
      ex++;
      n /= a;
    }
    res.push_back(make_pair(a, ex));
  }
  if(n != 1){
    res.push_back(make_pair(n, 1));
  }
  return res;
}


int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<pair<ll, ll>> res = prime_factorize(n);
  rep(i, res.size()){
    ll j = 1;
    ll num = res[i].second;
    while(num  - j >= 0){
      ans++;
      num -= j;
      j++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N;
	cin >> N;
// 	std::vector<int> h(n, 0);
    string x;
    cin >> x;
    if(N&1){
        cout << "No";
        return 0;
    }
    int mid = (int)(N/2);
    for(int i=0; i<(int)(N/2); i++){
        if(x[i]!=x[mid+i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int num2 = sc.nextInt();
        int sum = 0;
        for(int i=0;i<2;i++)
        {
            if(num>num2)
            {
                sum = sum + num;
                num = num - 1;
            }
            else if(num<num2)
            {
                sum = sum + num2;
                num2 = num2-1;
            }
            else
            {
                sum = sum + num;
                num = num - 1;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

class RMQ{
public:
  int n;
  P dat[555555];
  void init(int _n){
    n=1;
    while(n<_n)n*=2;
    rep(i,2*n) dat[i]=P(MAX,-1);
  }
  void update(int k,P a){
    k+=n-1;dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  P query(int a,int b){return query(a,b,0,0,n);}
  P query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return P(MAX,-1);
    if(a<=l&&r<=b) return dat[k];
    P vl=query(a,b,k*2+1,l,(l+r)/2);
    P vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};


RMQ t;

void Main() {
  ll n,m;
  string s;
  cin >> n >> m >> s;
  t.init(n+1);
  int p[n+1];
  memset(p,-1,sizeof(p));
  rep(i,n) t.update(i,P(MAX,i));
  t.update(n,P(0,n));
  rrep(i,n) {
    if(s[i]=='1') continue;
    P q=t.query(i+1,min(n+1,i+m+1));
    t.update(i,P(q.F+1,i));
    p[i]=q.S;
  }
  if(t.query(0,1).F==MAX) {
    pr(-1);
    return;
  }
  vector<int> v;
  int x=0;
  while(x!=n) {
    int y=p[x];
    v.pb(y-x);
    x=y;
  }
  PR(v,v.size());
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 10568
s=input()
s=str(s)
if(s[0]=='R' and s[1]=='R' and s[2]=='R'):
  print(3)
elif((s[0]=='R' and s[1]=='R') or (s[1]=='R' and s[2]=='R')):
  print(2)
elif(s[0]=='S' and s[1]=='S' and s[2]=='S'):
  print(0)
else:
  print(1)

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

const int mod = 998244353;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % mod;
		b = (b * b) % mod;
		e >>= 1; // e/=2;
	}
	return res;
}

ll fact[200005], inv[200005];
ll C(ll n, ll k)
{
	return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main()
{
	fast;
	int n, m, k;
	cin >> n >> m >> k;
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = pw(fact[i], mod - 2);
	}
	ll ans = 0;
	for (int i = 0; i <= k; i++)
	{
		int c = n - i;
		ll coef = (1LL * m * pw(m - 1, c - 1)) % mod;
		coef = (coef * C(n - 1, i)) % mod;
		ans = (ans + coef) % mod;
	}
	cout << ans << en;
}

Measured memory_bytes: 6780
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    map<char, int> ma;
    string s;
    cin >> s;
    rep(i, s.size()) { ma[s[i]]++; }

    if (ma['W'] > 0 && ma['E'] == 0) {
        cout << "No" << endl;
    } else if (ma['E'] > 0 && ma['W'] == 0) {
        cout << "No" << endl;
    } else if (ma['N'] > 0 && ma['S'] == 0) {
        cout << "No" << endl;
    } else if (ma['N'] == 0 && ma['S'] > 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3652
#include<stdio.h>
  
#define NIL -1
  
static const int MAX = 500;
static const int INFTY = (1<<21);
  
main(){
  int e,i, j, n, sum,min,length;
  int key[MAX],pass[MAX],pi[MAX],M[MAX][MAX];
  
  scanf("%d", &n);
  
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
  
  for(i=0;i<n;i++){
    key[i]=INFTY;
    pi[i]=NIL;
    pass[i] = 0;
  }
  key[0]=0;
  
  while(length!=NIL){
    min=INFTY;
    length=NIL;
    for(i=0;i<n;i++){
      if(key[i]<min && pass[i]!=1){
      length=i;
      min=key[i];
      }
    }
    pass[length]=1;
    for(i=0;i<n;i++){
      if(key[i] >= M[length][i] && pass[i]!=1){
    key[i] = M[length][i];
    pi[i] = length;
      }
    }
  }
    
  sum = 0;
  
  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) sum += M[i][pi[i]];
  }
  
  printf("%d\n", sum);
  
  return 0;
}

Measured memory_bytes: 804
#include <stdio.h>

#define N 100000000
#define inf 2147483647

int S[N],L[N/2],R[N/2];
int n,count = 0;
int l=0;

void merge(int left,int mid,int right){
	l++;
	int n1 = mid - left;
	int n2 = right - mid;
	int i;
	for(i=0;i<n1;i++){
		L[i] = S[left + i];
	}
	for(i=0;i<n2;i++){
		R[i] = S[mid+i];
	}
	L[n1] = inf;
	R[n2] = inf;
	int j=0;
	i = 0;
	int k;
	for(k=left;k<right;k++){
		count++;
		if(L[i] <= R[j])S[k] = L[i++];
		else if(L[i] > R[j])S[k] = R[j++]; 
	}
}	

void mergesort(int left,int right){
	if(left+1 < right){
		int mid = (right + left) / 2;
		mergesort(left,mid);
		mergesort(mid,right);
		merge(left,mid,right);
	}
}	

int main(){
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	mergesort(0,n);
	for(i=0;i<n-1;i++){
		printf("%d ",S[i]);
	}
	printf("%d\n%d\n",S[i],count);
}

Measured memory_bytes: 6516
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[500111];
int a[500111];
int main()
{
	scanf("%s",s);int l=strlen(s);
	for(int i=0;i<l;i++)a[l-i-1]=s[i]-'0';
	
	int c=0;
	for(int i=0;i<l;i++)
	{
		a[i]=a[i]*9+c;
		c=a[i]/10;
		a[i]%=10;
	}
	if(c)a[l++]=c;
	
	int sum=0;for(int i=0;i<l;i++)sum+=a[i];
	
	for(int _=1;;_++)
	{
		c=0;
		sum+=9;
		a[0]+=9;
		for(int i=0;i<l;i++)
		{
			a[i]+=c;
			c=a[i]/10;
			a[i]%=10;
			sum-=9*c;
			if(c==0)break;
		}
		if(c)a[l++]=c;
		if(sum<=9*_)
		{
			printendl(_);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2005;
const int mod=1e9+7;
int n,k;
ll C[N][N];
int main()
{
	C[0][0]=1;
	for(int i=1;i<N;i++)
	{
		C[i][0]=1;
		for(int j=1;j<N;j++)
		{
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		ll ans=C[k-1][i-1];
		ans=ans*C[n-k+1][i]%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>

using namespace std;

int main(){

    int h, w;
    cin >> h >> w;

    char picture[h][w];

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> picture[i][j];
        }
    }

    for (int i = -1; i <= w; i++){
        cout << "#";
    } cout << endl;

    for (int i = 0; i < h; i++){
        cout << "#";
        for (int j = 0; j < w; j++){
            cout << picture[i][j];
        }
        cout << "#" << endl;
    }

    for (int i = -1; i <= w; i++){
        cout << "#";
    } cout << endl;


    return 0;
}

Measured memory_bytes: 256
ac = wa = tle = re = 0
gets.chomp.to_i.times{
	case gets.chomp
	when 'AC' then
		ac += 1
	when 'WA' then
		wa += 1
	when 'TLE' then
		tle += 1
	else
		re += 1
	end
}
puts "AC x #{ac}"
puts "WA x #{wa}"
puts "TLE x #{tle}"
puts "RE x #{re}"



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

using namespace std;
const int MOD = 1e9+7;

int main()
{
    int n;
    cin >> n;
    vector< vector<int> >can(n, vector<int>(n));
    for (int i = 0; i<n; i++)
        for (int j = 0; j<n; j++)
            cin >> can[i][j];
    vector<int>dp(1<<n);
    dp[0] = 1;
    for (int mask = 0; mask<(1<<n)-1; mask++)
    {
        int a = __builtin_popcount(mask);
        for (int b = 0; b<n; b++)
            if (can[a][b] && !(mask&(1<<b)))
            {
                int nmask = mask^(1<<b);
                dp[nmask] = (dp[nmask]+dp[mask])%MOD;
            }
    }
    cout << dp[(1<<n)-1];
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a;
  cin>>a;
  if(a%2==0)
    cout<<a/2;
  else
    cout<<a/2+1;
}

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

#define MAX_N 10

int main() {
	int N;
	int p[MAX_N] = {0};
	int sum = 0, max = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		max = std::max(max, p[i]);
		sum += p[i];
	}
	sum -= max/2;
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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 REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

// const int kMaxN;

int N;
int ans = 0;

signed main() {
  cin >> N;

  REP(i, N) {
    if ((i+1)%2 == 1) {
      int y = 0;
      REP(j, i+1) {
        if ((i+1)%(j+1) == 0) { ++y; }
      }
      if (y == 8) { ++ans; }
    }
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef pair<int,int> pii;

int dp[301][301];
pii nxt[301][301];
char s1[501];
char s2[501];
int s1s;
int s2s;

char res[501];
int main(){
	string str;
	while(cin>>str&&str!="#END"){
		int ms=0;
		for(int i=0;i<(int)str.size()-1;i++){
			s1s=i+1;
			s2s=str.size()-i-1;
			for(int j=0;j<i+1;j++)s1[j]=str[j];
			for(int j=i+1;j<(int)str.size();j++)s2[j-i-1]=str[j];
			memset(dp,0,sizeof(dp));
			for(int j=s1s;j>=0;j--){
				for(int k=s2s;k>=0;k--){
					int res=0;
					int a=j;
					int b=k;
					if(a==s1s||b==s2s)res=0;
					else if(s1[a]==s2[b]){
						int tmp=dp[a+1][b+1]+1;
						if(tmp>res){
							nxt[a][b].first=a+1;
							nxt[a][b].second=b+1;
							res=tmp;
						}
					}
					else{
						int tmp=dp[a][b+1];
						if(tmp>res){
							nxt[a][b].first=a;
							nxt[a][b].second=b+1;
							res=tmp;
						}
						tmp=dp[a+1][b];
						if(tmp>res){
							nxt[a][b].first=a+1;
							nxt[a][b].second=b;
							res=tmp;
						}
					}
					dp[a][b]=res;
				}
			}
			//int tmp=dfs(0,0);
			int tmp=dp[0][0];
			if(tmp>ms){
				ms=tmp;
				int ca,cb;
				ca=cb=0;
				int cnt=0;
				while(1){
					if(ca==s1s||cb==s2s)break;
					int na=nxt[ca][cb].first;
					int nb=nxt[ca][cb].second;
					if(na-ca==1&&nb-cb==1){
						res[cnt]=s1[ca];
						cnt++;
					}
					ca=na;
					cb=nb;
				}
				res[cnt]='\0';
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1956
//==========================================
// ABC142b
//
// 2019/09/28
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

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

Measured memory_bytes: 256
N = int(input())
P = [int(input()) for i in range(N)]
Q = {}
for i in range(N):
    Q[P[i]] = i

tmp = 1
ans = 1
for i in range(1, N):
    if Q[i] < Q[i + 1]:
        tmp += 1
    else:
        ans = max(ans, tmp)
        tmp = 1
ans = max(ans, tmp)
print(N - ans)

Measured memory_bytes: 83416
#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<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int a, b;
  string s, t, u;
  cin >> s >> t >> a >> b >> u;
  if(s == u)
    cout << a - 1 << ' ' << b << endl;
  else
    cout << a << ' ' << b - 1 << endl;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())

A = [0]*N

for i in range(N):
	A[i] = list(map(int, input().split()))

cost = 100000*12
ans = -1

for i in range(2**N):
	total = [0]*(M)
	c = 0
	for j in range(N):
		if ((i >> j) & 1):
			c += A[j][0]
			count = 0
			for k in range(M): 
				total[k] += A[j][k + 1]
	if min(total) >= X:
		cost = min(cost, c)
		ans = cost

print(ans)

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

int64_t kyori(int64_t x, int64_t a, int64_t b) {
  int64_t d1 = a > x ? a - x : x - a;
  int64_t d2 = b > a ? b - a : a - b;
  return d1 + d2;
}

int main()
{
  int a, b, q;
  cin >> a >> b >> q;
  valarray<int64_t> s(a + 2), t(b + 2), x(q), ans(q);
  for (int i = 1; i <= a; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= b; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++) {
    cin >> x[i];
  }
  s[0] = -100000000000;
  t[0] = -100000000000;
  s[a + 1] = 100000000000;
  t[b + 1] = 100000000000;
  for (int i = 0; i < q; i++) {
    auto s_it = lower_bound(begin(s), end(s), x[i]);
    auto t_it = lower_bound(begin(t), end(t), x[i]);
    int64_t d = 100000000000;
    d = min(d, kyori(x[i], *(s_it - 1), *(t_it - 1)));
    d = min(d, kyori(x[i], *(t_it - 1), *(s_it - 1)));
    d = min(d, kyori(x[i], *(s_it - 1), *t_it));
    d = min(d, kyori(x[i], *t_it, *(s_it - 1)));
    d = min(d, kyori(x[i], *(t_it - 1), *s_it));
    d = min(d, kyori(x[i], *s_it, *(t_it - 1)));
    d = min(d, kyori(x[i], *s_it, *t_it));
    d = min(d, kyori(x[i], *t_it, *s_it));
    ans[i] = d;
  }
  for (auto&& a : ans) {
    cout << a << endl;
  }
}


Measured memory_bytes: 4480
function main (input) {
    var n = input.split('\n')[0];
    var a = input.split('\n')[1].split(' ');
    var flg = true;
    var cnt = 0;

    while (flg) {
        for (var i = 0; i < n; i++) {
            if (a[i] % 2 != 0) {
                flg = false;
            }
            a[i] = a[i]/2;
        }
        cnt++;
    }
    console.log(cnt -1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
signed main() {
	ll n, m, a = 0, b = 0, cnt = 0, ans = INF; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		cin >> a; if (a == 1) { b = h; }
	}
	cout << (n - 1 + m - 2) / (m - 1) << endl;
	cin >> n; return 0;
}


Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// Queue
type Queue<'a> = Queue of ('a list * 'a list)

[<RequireQualifiedAccess>]
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Queue =
  let empty = Queue([], [])
  let ofList l = Queue(l, [])
  let check (Queue(f, r)) =
    match (f, r) with
    | ([], _) -> Queue(List.rev r, [])
    | _ -> Queue(f, r)
  let snoc x (Queue(f, r)) = Queue(f, x::r) |> check
  let head (Queue(f, _)) = List.head f
  let tryHead (Queue(f, _)) = List.tryHead f
  let tail (Queue(f, r)) =
    match f with
    | [] -> failwith "queue is empty"
    | _::f -> Queue(f, r) |> check
  let tryUncons (Queue(f, r)) =
    match f with
    | [] -> None
    | x::f -> Some(x, Queue(f, r) |> check)
  let (|Cons|Nil|) q =
    match tryUncons q with
    | Some(h,t) -> Cons(h, t)
    | None -> Nil
// Queue

// start
let (H, W) = readInts() |> pair
let S =
  let s=Array2D.create H W false
  for y in 0..(H-1) do
    readStr().ToCharArray()
    |> Array.iteri (fun x c -> s.[y, x] <- c='.')
  s

let maxRoute (y, x) =
  let g = Array2D.create H W (-1)
  g.[y, x]<-0
  let rec bfs =
    function
    | Queue.Nil -> ()
    | Queue.Cons((i, j), q) ->
      let q'=
        [(i+1, j); (i-1, j); (i, j+1); (i, j-1)]
        |> List.fold (fun q' (a, b) ->
          if 0<=a&&a<H && 0<=b&&b<W && S.[a,b] && g.[a,b]<0 then
            g.[a,b]<-g.[i,j]+1
            q' |> Queue.snoc (a,b)
          else q'
        ) q
      bfs q'
  bfs (Queue.ofList [(y, x)])
  let mutable m = 0
  g |> Array2D.iter (fun v-> m<-max m v)
  m

seq {
  for y in 0..(H-1) do
    for x in 0..(W-1) do
      yield (y, x)
}
|> Seq.filter (fun (y,x) -> Array2D.get S y x)
|> Seq.map maxRoute
|> Seq.max
|> printfn "%d"

Measured memory_bytes: 18648
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  while (true) {
    string s;
    cin >> s;
    if (s == "-") return;
    ll n;
    cin >> n;
    ll sum = 0;
    rep (i, n) {
      ll tmp;
      cin >> tmp;
      sum += tmp;
    }
    sum %= s.size();
    string ss = s + s;
    string a = ss.substr(sum, s.size());
    cout << a << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3232
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

void execute_test();

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

void execute_test() {
    int n, a = 0, b = 0;

    for (int i = 0; i < 3; i++) {
    	cin >> n;
    	a += (n == 5);
    	b += (n == 7);
    }

    if (a == 2 && b == 1) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 256
<?php
while(1){
	fscanf(STDIN,"%d",$n);	
	$a=array();
	$a[0]=0;
	if($n==0)break;
	for($i=1;$i<=$n;$i++){
		fscanf(STDIN,"%d",$a[$i]);
	}
	$maxv=-1000000;
	
	for($i=1;$i<=$n;$i++){
		if($a[$i-1]+$a[$i]>$a[$i]){
			$a[$i]=$a[$i-1]+$a[$i];
		}
		if($maxv<$a[$i]){
			$maxv=$a[$i];
		}
	}
	print $maxv."\n";
}

Measured memory_bytes: 7040
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<queue>

using namespace std;
using P = pair<int, int>;

vector<vector<int>> g;
vector<int> col;
int n;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    col = vector<int>(n, -1);
    REP(i, n - 1) {int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a);}
    queue<P> q;
    q.emplace(0, 0);
    q.emplace(n - 1, 1);
    int cnt[] = {0, 0};
    while(!q.empty()) {
        P top = q.front();
        q.pop();
        int node, c;
        tie(node, c) = top;
        if (col[node] != -1) continue;
        col[node] = c;
        cnt[c]++;
        for (auto adj : g[node]) {
            if (col[adj] != -1) continue;
            q.emplace(adj, c);
        }
    }
    // DV(col);
    cout << (cnt[0] > cnt[1] ? "Fennec" : "Snuke") << endl;
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i < (int)n; i++)
#define Loopr(i, n) for(int i= (int)n - 1; i >= 0; i--)
using namespace std;
typedef long long int ll;

struct node {
	int parent, left, right;
};

int n, r, l;
vector<node> nodes(25, { -1,-1,-1 });

void print_pre(int a) {
	if (a != -1) {
		cout << " " << a;
		print_pre(nodes[a].left);
		print_pre(nodes[a].right);
	}
}

void print_in(int a) {
	if (a != -1) {
		print_in(nodes[a].left);
		cout << " " << a;
		print_in(nodes[a].right);
	}
}

void print_post(int a) {
	if (a != -1) {
		print_post(nodes[a].left);
		print_post(nodes[a].right);
		cout << " " << a;
	}
}

int main() {
	cin >> n;
	Loop(i, n) {
		int id;
		cin >> id;
		int l, r;
		cin >> l >> r;
		nodes[id].left = l;
		nodes[id].right = r;
		if (l != -1)nodes[l].parent = id;
		if (r != -1)nodes[r].parent = id;
	}
	Loop(i, n) {
		if (nodes[i].parent == -1) {
			r = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	print_pre(r);
	cout << endl;
	cout << "Inorder" << endl;
	print_in(r);
	cout << endl;
	cout << "Postorder" << endl;
	print_post(r);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,x,a[maxn],e[maxn];
long long sum[maxn],ans,s;
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++) cin>>a[i];
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	e[1]=e[2]=5;
	for(int i=3;i<=n;i++) e[i]=e[i-1]+2;
	ans=1e18;
	for(int k=1;k<=n;k++) 
	{
		s=(long long)(n+k)*x;
		for (int i=1,cnt=1;i<=n;i+=k,cnt++)
		{
		    s+=(long long)(sum[min(i+k-1,n)]-sum[i-1])*e[cnt];
			if(s>ans) break;
		}
		ans=min(ans,s);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main() {
  int n,k,a;
  cin >> n >> k;
  a = 1;
  for (int i; i<n; i++) {
    if (a+k >= a*2) {
      a *= 2;
    } else {
      a += k;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
//#include<numeric>
#include<functional>
//#include<string>
//#include<iostream>

using namespace std;
const int one = 1;
const int big = (one<<20);
typedef long long int llint;
//11:10???13:00
int main(void){
	int N,K,h,i,j,a,b,saidai,honwa;
	vector<int> hon[11];//?????£????????\?????????
	int dp[11][2001]={0};//x?????£???????????§y????£???£???????????¬?????????
	scanf("%d %d",&N,&K);
	for(i=0;i<N;i++){
		scanf("%d %d",&a,&b);
		hon[b].push_back(a);
	}
	for(i=1;i<=10;i++){
		sort(hon[i].begin(),hon[i].end(),greater<int>());
	}
	for(h=1;h<=10;h++){
		for(i=1;i<=K;i++){
			saidai=dp[h-1][i];
			honwa=0;
			for(j=0;j<hon[h].size();j++){
				if(i-j-1<0){ break; }
				honwa+=hon[h][j]+2*j;
				saidai=max(saidai,dp[h-1][i-j-1]+honwa);
			}
			dp[h][i]=saidai;
		}
	}
	printf("%d\n",dp[10][K]);
	return 0;
}

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

int main(){
    stack<int> S;int a,b,x;string s;

    while(cin>>s){
        if(s[0]=='+'){
            a=S.top();S.pop();b=S.top();S.pop();
            S.push(a+b);
        }
        else if(s[0]=='-'){
            a=S.top();S.pop();b=S.top();S.pop();
            S.push(b-a);
        }
        else if(s[0]=='*'){
            a=S.top();S.pop();b=S.top();S.pop();
            S.push(a*b);
        }
        else{
            S.push(atoi(s.c_str()));
        }
    }
    cout<<S.top()<<endl;
}


Measured memory_bytes: 3172
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<assert.h>
#include<math.h>
#include<algorithm>
//#include<iostream>
using namespace std;

int n;
#define maxn 100011
char s[maxn],ss[maxn];int pos[maxn];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);int len=0;
	for (int i=1;i<=n;i++)
		if (s[i]!='x') ss[++len]=s[i],pos[len]=i;
	bool flag=0;
	for (int i=1;i<=len/2;i++)
		if (ss[i]!=ss[len-i+1]) flag=1;
	if (flag) puts("-1");
	else
	{
		int j=pos[(len+1)/2],k=pos[(len+2)/2];
		int ans=0;
		while (j && k<=n)
		{
			int c1=0,c2=0;
			j--;while (j && s[j]=='x') j--,c1++;
			k++;while (k<=n && s[k]=='x') k++,c2++;
			ans+=fabs(c1-c2);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int A = iin(), B = iin();
    if (A > B) {
        iout(A * 2 - 1);
    } else if (A == B) {
        iout(A*2);
    } else {
        iout(B * 2 - 1);
    }
    return 0;
}


Measured memory_bytes: 128
import numpy as np
N = int(input())
S = input()

left = [0]*N
right = [0]*N
for i in range(1,N):
    if S[i-1]=='W':
        left[i] += left[i-1] + 1
    else:
        left[i] += left[i-1]
left = np.array(left)

for i in range(1,N):
    if S[N-i]=='E':
        right[i] += right[i-1] + 1
    else:
        right[i] += right[i-1]
right = np.array(right[::-1])

ans = (left+right).min()
print(ans)

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d)cout << "Yes";
	else if (abs(a - b) <= d && abs(b - c) <= d)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

class DICE {
  public:
    int T, S, E, W, N, B;

    DICE() { T = S = E = W = N = B = 0; }
    DICE(vector<int> tmp) {
        if(tmp.size() != 6)
            exit(1);
        T = tmp[0];
        S = tmp[1];
        E = tmp[2];
        W = tmp[3];
        N = tmp[4];
        B = tmp[5];
    }
    DICE(int T0, int S0, int E0, int W0, int N0, int B0) {
        tie(T, S, E, W, N, B) = make_tuple(T0, S0, E0, W0, N0, B0);
    }

    void turn(char dir) {
        if(dir == 'S')
            tie(T, B, S, N) = make_tuple(N, S, T, B);
        else if(dir == 'N')
            tie(T, B, N, S) = make_tuple(S, N, T, B);
        else if(dir == 'E')
            tie(T, B, E, W) = make_tuple(W, E, T, B);
        else if(dir == 'W')
            tie(T, B, W, E) = make_tuple(E, W, T, B);
        else if(dir == 'B')
            tie(T, B, W, E) = make_tuple(B, T, E, W);
        else if(dir == 'R')
            tie(N, E, S, W) = make_tuple(W, N, E, S);
    }

    bool match(int to, int fr) {
        if(T != to) {
            if(to == B) {
                turn('B');
            } else if(to == E) {
                turn('W');
            } else if(to == W) {
                turn('E');
            } else if(to == S) {
                turn('N');
            } else if(to == N) {
                turn('S');
            }
        }
        while(fr != S) {
            turn('R');
        }
        return true;
    }
};

bool isSameDice(DICE a, DICE b) {
    return (a.B == b.B && a.W == b.W && a.E == b.E && a.N == b.N &&
            a.T == b.T && a.S == b.S);
}

int main() {
    int n;
    cin >> n;
    vector<DICE> d(n);
    rep(i, n) cin >> d[i].T >> d[i].S >> d[i].E >> d[i].W >> d[i].N >> d[i].B;
    string rotate = "XNNNNWNNNNWNNNNWNNNNNWNNNNWNNNNWNNNNWNNNN";

    rep(i, n) {
        rep(j, i + 1, n) {
            rep(k, rotate.length()) {
                d[j].turn(rotate[k]);
                if(isSameDice(d[i], d[j])) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 3204
"use strict";

function main(input) {
  input = input.split(/\n/).map(v => ~~v);
  const X = input[3] / 50;
  const A = input[0];
  const B = input[1];
  const C = input[2];

  let ans = 0;
  for (let i = 0; i <= A; i++) {
    for (let j = 0; j <= B; j++) {
      for (let k = 0; k <= C; k++) {
        if (i * 10 + j * 2 + k  === X) ans++;
      }
    }
  }

  console.log(ans);
}

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


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

int main(){
    int D,T,S;cin>>D>>T>>S;
    if(D<=T*S) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#define llint long long
#define inf 1e9

using namespace std;

string s;
int x[] = {0, -1, 0, 1, -1, 0, 1, -1, 0, 1};
int dp[100005][10][10][2];

int main(void)
{
  while(1){
    cin >> s;
    if(s == "#") break;

    llint n = s.size();
    s = "#" + s;

    for(int i = 0; i <= n; i++){
      for(int j = 1; j <= 9; j++){
        for(int k = 1; k <= 9; k++){
          for(int l = 0; l < 2; l++){
            dp[i][j][k][l] = inf;
          }
        }
      }
    }
    for(int j = 1; j <= 9; j++){
      for(int k = 1; k <= 9; k++){
        if(j == 5 || k == 5 || j == k || x[j] > x[k]) continue;
        //cout << j << " " << k << endl;
          for(int l = 0; l < 2; l++) dp[0][j][k][l] = 0;
      }
    }

    for(int i = 0; i < n; i++){
      int c = s[i+1]-'0';
      for(int j = 1; j <= 9; j++){
        for(int k = 1; k <= 9; k++){
          for(int l = 0; l < 2; l++){
            if(x[c] <= x[k] && c != k) dp[i+1][c][k][0] = min(dp[i+1][c][k][0], dp[i][j][k][l] + ((l == 0)?1:0));
            if(x[j] <= x[c] && c != j) dp[i+1][j][c][1] = min(dp[i+1][j][c][1], dp[i][j][k][l] + ((l == 1)?1:0));
          }
        }
      }

      /*for(int j = 1; j <= 9; j++){
        for(int k = 1; k <= 9; k++){
          cout << dp[i][j][k] << " ";
        }
        cout << endl;
      }
      cout<< endl;*/
    }


    int ans = inf;
    for(int j = 1; j <= 9; j++){
      for(int k = 1; k <= 9; k++){
        for(int l = 0; l < 2; l++){
          ans = min(ans, dp[n][j][k][l]);
        }
      }
    }
    cout << ans << endl;
  }
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H[i];
  sort(H.begin(), H.end());
  int mindiff = 1000000000;
  for (int i = 0; i < N - K + 1; i++)
    mindiff = min(mindiff, H[i + K - 1] - H[i]);
  cout << mindiff << '\n';
  return 0;
}


Measured memory_bytes: 640