akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll x,y;
        ll maxi=-1e18;
        maxi=max({maxi,a*c,b*d,a*d,b*c});
        cout<<maxi;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    
    string s; cin >> s;
    string ans;
    int num = stoi(s);
    for(int i=0; i<999; i++){
        if(s[0]==s[1] && s[1]==s[2] && s[2]==s[0]){
            ans = s;
            break;
        }
        num++;
        s = to_string(num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
	long double a,b;
  cin>>a>>b;
  if(a>b){
  	cout<<"GREATER"<<endl;
  }
  else if(a<b){
  	cout<<"LESS"<<endl;
  }
  else if(a == b){
  	cout<<"EQUAL"<<endl;
  }

	return 0;
}


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

const char HORIZ = 'h';
const char VERT = 'v';

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

    string s1, s2;
    cin >> s1 >> s2;

    string blocks;
    for(int i = 0; i < s1.size(); ++i)
    {
        if(s1[i] == s2[i])
        {
            blocks += VERT;
        }
        else
        {
            blocks += HORIZ;
            i += 1;
        }
    }

    long long count = blocks[0] == VERT ? 3 : 6;
    for(int i = 1; i < blocks.size(); ++i)
    {
        int mul = 1;
        if(blocks[i - 1] == VERT) mul = 2;
        else if(blocks[i] == HORIZ) mul = 3;

        count *= mul;
        count %= 1000000007;
    }

    cout << count << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
        adj_list[b].push_back(a);
    }
    if (m % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> dfs_num(n);
    vector<int> edge_count(n, 0);
    vector<bool> visited(n, false);
    vector<vector<int>> dfs_children(n);
    vector<pair<int, int>> result;
    int num_visited = 0;
    function<void (int)> dfs = [&](int i) {
        visited[i] = true;
        dfs_num[i] = num_visited++;
        int count = 0;
        for (int j : adj_list[i]) {
            if (!visited[j]) {
                dfs(j);
                dfs_children[i].push_back(j);
                count += edge_count[j] + 1;
                if (edge_count[j] % 2 == 0) {
                    result.push_back(make_pair(i, j));
                } else {
                    result.push_back(make_pair(j, i));
                }
            } else if (dfs_num[j] > dfs_num[i]) {
                result.push_back(make_pair(i, j));
                ++count;
            }
        }
        edge_count[i] = count;
    };
    dfs(0);
    for (auto edge : result) {
        cout << edge.first+1 << " " << edge.second+1 << "\n";
    }
    return 0;
}


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

signed main(void)
{
	int a, b;
	string s;
	bool ok;
	cin >> a >> b >> s;

	ok = true;
	for (int i = 0; i < a + b + 1; i++)
	{
		if (i == a)
		{
			if (s[i] != '-')
				ok = false;
		}
		else
			if (!(s[i] >= '0' && s[i] <= '9'))
				ok = false;
	}
	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

void display_array(int a[], int n) {
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << a[i];
  }
  cout << "\n";
}

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

  display_array(A, n);
  for (int i = 1; i < n; i++) {
    int key = A[i];
    for (int j = i; j >= 0; j--) {
      if (j == 0 || key > A[j-1]) {
        A[j] = key;
        break;
      }
      A[j] = A[j-1];
    }
    display_array(A, n);
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

int tile(char x){
  if(x=='B'){return 0;}
  else{return 1;}
}

int main(){
  int N, K;cin>>N>>K;
  vll x,y;
  vi c;
  for (int i=0;i<N;++i){
    int x_,y_;char c_;cin>>x_>>y_>>c_;
    x.push_back(x_);y.push_back(y_);c.push_back(tile(c_));
  }

  for (int i=0;i<N;++i){
    ll a=x[i]/K, b=y[i]/K;
    x[i]-=a*K;y[i]-=b*K;(c[i]+=a+b)%=2;
  }
  //num_white;

  int wcnt[K][K];
  int bcnt[K][K];
  memset(wcnt, 0, sizeof(wcnt));
  memset(bcnt, 0, sizeof(bcnt));
  for (int i=0;i<N;++i){
    wcnt[x[i]][y[i]]+=c[i];
    bcnt[x[i]][y[i]]+=1-c[i];
  }


  int rwcum[K][K+1];
  int rbcum[K][K+1];
  memset(rwcum, 0, sizeof(rwcum));
  memset(rbcum, 0, sizeof(rbcum));

  for (int i=0;i<K;++i){
    for (int j=0;j<K;++j){
      rwcum[i][j+1]=rwcum[i][j]+wcnt[i][j];
      rbcum[i][j+1]=rbcum[i][j]+bcnt[i][j];
    }
  }

  int wcum[K+1][K+1];
  int bcum[K+1][K+1];
  memset(wcum, 0, sizeof(wcum));
  memset(bcum, 0, sizeof(bcum));

  for (int i=0;i<K;++i){
    for (int j=1;j<=K;++j){
      wcum[i+1][j]=wcum[i][j]+rwcum[i][j];
      bcum[i+1][j]=bcum[i][j]+rbcum[i][j];
    }
  }
  
  

  int best_score=0;
  for (int i=1;i<=K;++i){
    for (int j=1;j<=K;++j){
      int ur=wcum[K][K]-wcum[K][j-1]-wcum[i-1][K]+wcum[i-1][j-1];
      int ul=bcum[K][j-1]-bcum[i-1][j-1];
      int lr=bcum[i-1][K]-bcum[i-1][j-1];
      int lol=wcum[i-1][j-1];
      best_score=max(best_score, ur+ul+lr+lol);
      ur=bcum[K][K]-bcum[K][j-1]-bcum[i-1][K]+bcum[i-1][j-1];
      ul=wcum[K][j-1]-wcum[i-1][j-1];
      lr=wcum[i-1][K]-wcum[i-1][j-1];
      lol=bcum[i-1][j-1];
      best_score=max(best_score, ur+ul+lr+lol);
    }
  }
  cout << best_score << endl;
  return 0;
}

Measured memory_bytes: 26168
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
  int H,W;
  cin>>H>>W;
  int A[H][W];
  int B[H][W];
  REP(i,H)REP(j,W)cin>>A[i][j];
  REP(i,H)REP(j,W)cin>>B[i][j];
  
  int C[H][W];
  REP(i,H)REP(j,W){
    C[i][j] = abs(A[i][j]-B[i][j]);
  }

  int maxA = 80*160;
  bool DP[H][W][maxA];
  REP(i,H)REP(j,W)REP(k,maxA) DP[i][j][k] = false;
  DP[0][0][C[0][0]] = true;

  REP(i,H){
    REP(j,W){
      REP(k,maxA){
        if (DP[i][j][k]){
          if (i<H-1){
            DP[i+1][j][abs(k+C[i+1][j])] = true;
            DP[i+1][j][abs(k-C[i+1][j])] = true;
          }
          if (j<W-1){
            DP[i][j+1][abs(k+C[i][j+1])] = true;
            DP[i][j+1][abs(k-C[i][j+1])] = true;
          }
        }
      }
    }
  }
  int ans = 2<<30;
  REP(k,maxA){
    if (DP[H-1][W-1][k]){
      ans = k;
      break;
    }
  }
  cout<<ans<<endl;





  return 0;
}

Measured memory_bytes: 80384
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

bool f(ll a, ll b, ll c) {
  a -= c;
  b -= c*2;
  if (a < 0) b -= (-a)*2;
  return b >= 0;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll l = 0, r = a+b+1;
  while (l+1 < r) {
    ll c = (l+r)>>1;
    if (f(a,b,c)) l = c; else r = c;
  }
  cout<<l<<endl;
  return 0;
}






















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

int main()
{
    int n, m, x;
    long long ans = 0;
    priority_queue<int> q;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        ans += x;
        q.push(x);
    }
    for (int i = 0; i < m; i++)
    {
        ans -= ((q.top()+1)/2);
        q.push(q.top()/2);
        q.pop();
    }
    cout << ans;
}

Measured memory_bytes: 3880
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 全方位木DP、葉側と根側
N = ir()
graph = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

MOD = 10 ** 9 + 7

fact = [1] * (N + 10)
for n in range(1, N + 10):
    fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
    fact_inv[n - 1] = fact_inv[n] * n % MOD

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    cur = stack.pop()
    order.append(cur)
    for next in graph[cur]:
        if next == parent[cur]:
            continue
        parent[next] = cur
        stack.append(next)

size_down = [0] * (N+1)  # 1-indexed
dp_down = [1] * (N+1)  # 葉側の組み合わせ
for v in order[::-1]:
    dp_down[v] *= fact[size_down[v]]
    dp_down[v] %= MOD
    p = parent[v]
    s = size_down[v] + 1
    size_down[p] += s
    dp_down[p] *= fact_inv[s] * dp_down[v]
    dp_down[p] %= MOD

size_up = [N-x-1 for x in size_down]  # 自分含めない
dp_up = [1] * (N+1)  # 根側の組み合わせ
for v in order[1:]:
    p = parent[v]
    x = dp_down[p]
    x *= dp_up[p]
    x *= fact_inv[size_down[p]]
    x *= fact[size_down[v] + 1]
    x *= pow(dp_down[v], MOD-2, MOD)
    x %= MOD
    x *= fact[size_up[v]-1]
    x *= fact_inv[size_up[p]]
    dp_up[v] = x % MOD

for xd, xu, sd, su in zip(dp_down[1:], dp_up[1:], size_down[1:], size_up[1:]):
    answer = xd * xu * fact[sd+su] * fact_inv[sd] * fact_inv[su] % MOD
    print(answer % MOD)


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

int main(){
  int N, X, Y; cin >> N >> X >> Y;
  vector<int> ans(N);
  ans[0]=0;
  for(int i=1;i<N;i++){
    for(int j=i+1;j<=N;j++){
      int k=min(j-i,abs(X-i)+1+abs(Y-j));
      ans[k]++;
    }
  }
  for(int i=1;i<=N-1;i++){
    cout << ans[i] << endl;
  }
  return 0;
}
  
  
  

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500001
#define INFTY 1000000000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);
int count = 0;

int main(){
  int i,n, A[MAX];
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  
  mergeSort(A,0,n);

  
  for(i = 0; i < n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);

  return 0;
}

void merge(int *A,int left,int mid,int right){
  //printf("in merge func\n");
  int n1,n2,i,j,k,L[MAX],R[MAX];
  n1 = mid - left;
  n2 = right - mid;
  //count++;

  //printf("left: %d, middle: %d, right: %d\n", left, mid, right);

  //printf("debug for 1\n");
  for( i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  //printf("debug for 2\n");
  // error occurs in this for loop
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  
  //printf("debug for 3\n");
  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
  }
  //printf("debug: ");
  for(i = 0;*(A+i) != NULL;i++){
    //printf("%d ",*(A+i));
  }
  //printf("\n");
}

void mergeSort(int *A,int left,int right){
  //static int checknum = 1;
  int i;
  int mid;
  //printf("%d: ", checknum);
  for(i = left;i < right;i++){
    //printf("%d ",*(A+i));
  }
  //checknum++;
  //printf("\n");
  if(left+1 < right){
    //count++;
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);

  }
}

Measured memory_bytes: 5488
#include<iostream>
using namespace std;
int main()
{
    int n,i=0;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0,l=n/2;
    if(n%2)
    {
        cout<<"No"<<"\n";
        return 0;
    }
    for(int i=0;i<n/2;i++,l++)
    {
        if(s[i]==s[l])
            cnt+=2;
         
    }
    if(cnt==n)
    
            cout<<"Yes"<<"\n";
    else
            cout<<"No"<<"\n";
        
    
    return 0;
    
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    string s; cin >> s;
    int ans = 0;
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;

    return 0;
}


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

map<char,int> R;

int main(){
	R['I']=1;
	R['V']=5;
	R['X']=10;
	R['L']=50;
	R['C']=100;
	R['D']=500;
	R['M']=1000;
	string s;
	while(cin >> s){
		if(cin.eof()) break;
		int res=0;
		rep(i,s.size()){
			int cur=R[s[i]];
			if(i+1<s.size()){
				int next=R[s[i+1]];
				if(cur<next)
					res-=cur;
				else
					res+=cur;
			}else
				res+=cur;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
def examA():
    N, A, B = LI()
    ans = min(A*N,B)
    print(ans)
    return

def examB():
    N, D = LI()
    X = [LI() for _ in range(N)]
    ans = 0
    for i,j in itertools.combinations(X,2):
        cur = 0
        for k in range(D):
            cur += (i[k]-j[k])**2
        cur **=0.5
        if cur==int(cur):
            ans +=1
    print(ans)
    return

def examC():
    L, R = LI()
    cur = []; ans = 10**9
    for i in range(L,min(2019+L,R)+1):
        if i%2019==0:
            ans = 0
            break
        else:
            cur.append(i%2019)
    if ans==0:
        print(ans)
        return
    N = len(cur)
    for i,j in itertools.combinations(cur,2):
        ans = min(ans,(i*j)%2019)
    print(ans)
    return

def examD():
    N = I()
    A = LI()
    dis = [0]*N
    for i in range(N):
        cur = A[i-N+1]-A[i-N]
        dis[i] = cur*2
#    print(dis)
    ans = [0]*N
    for i in range(2,2*N,2):
        ans[i-N] = ans[i-N-2] + dis[i-N-2]
#    print(ans)
    ad = (sum(A) - sum(ans))//N
    for i in range(N):
        ans[i] += ad
    print(" ".join(map(str,ans)))
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()


Measured memory_bytes: 86104
// 2019/09/02 Tazoe

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int solve(const int len, const int L[50], const int N)
{
	int DP[51];
	DP[0] = len;

	for(int i=0; i<N; i++){

		int piece_len = 0;
		DP[i+1] = 100000;

		for(int j=i; j>=0; j--){

			piece_len += L[j];

			if(i==N-1 && j==0)
				continue;

			if(piece_len>=len){
				int high = max(piece_len, DP[j]);
				DP[i+1] = min(DP[i+1], high);
			}
		}
	}

	return DP[N]-len;
}


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

	int L[50];
	for(int i=0; i<N; i++){
		cin >> L[i];
	}

	int ans = 100000;

	for(int i= 0; i<N; i++){
		int len = 0;			// 水ようかんのすべての長さ
		for(int j=i; j<N; j++){
			len += L[j];

			int tmp = solve(len, L, N);
			ans = min(ans, tmp);
		}
	}

	cout << ans << endl;

	return 0;
}



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

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  int min1 = min(P, min(Q, R));
  int min2;
  
  if(min1 == P)
  		min2 = min(Q, R);
  
  if(min1 == Q)
  		min2 = min(P, R);
  
  if(min1 == R)
  		min2 = min(Q, P);
    
  cout << min1 + min2 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	int anc = 0;
	
	cin >> a >> b >> c;
	
	while (a <= b){
		if (c % a == 0){
			anc++;
		}
		a++;
	}
	
	cout << anc << endl;
}

Measured memory_bytes: 1160
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(1,len(p)-1):
  if p[i]>p[i-1] and p[i]<=p[i+1]:
    cnt+=1
    
  elif p[i]<=p[i-1] and p[i]>p[i+1]:
    cnt+=1
    
print(cnt)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9+7;
const ll INF = 1e9+7;

ll n, ans = 1;
ll a[30];
string s;

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

  for (ll i = 0; i < n; i++) {
    a[s[i]-'a']++;
  }
  
  for (ll i = 0; i < 26; i++) {
    ans *= a[i] + 1;
    ans %= M;
  }
  
  ans--;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

map<int,int> ma;

int f(int n){
    if(ma[n] != 0)return ma[n];
    return ma[n] = 2*f(n/2)+1;
}

signed main(void) {
    int n;
    cin >> n;
    ma[1] = 1;
    cout << f(n) << endl;

}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int A, B;

    std::cin >> A >> B;

    if (A >= 13) {
        std::cout << B << std::endl;
    } else if (A <= 5) {
        std::cout << 0 << std::endl;
    } else {
        std::cout << B / 2 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n, k;
    cin >> n >> k;
    n = n%k;
    n = min(n,k-n);
    cout << n << endl;
    return 0;
}



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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i = a; i < b; ++i)
#define rep_(i,a,b) for (ll i = a; i > b; --i)
#define endl '\n'
const ll mod = 1e9 + 7;

const ll maxn = 1e3 + 4;

ll n, m, sti, stj, endi, endj, comp[maxn][maxn], numcomps;
char g[maxn][maxn];
unordered_set<int> comp_g[maxn * maxn];

int row_child[4] = {0, 1, -1, 0};
int col_child[4] = {1, 0, 0, -1};

void dfs(int i, int j, int this_comp) {
	if (i < 0 || i >= n) return;
	if (j < 0 || j >= m) return;
	if (g[i][j] == '#') return;
	if (comp[i][j] != -1) return;
	comp[i][j] = this_comp;
	for (int x = 0; x < 4; ++x) {
		dfs(i + row_child[x], j + col_child[x], this_comp);
	}
}

int magic[5] = {-2, -1, 0, 1, 2};
void find_component_edge(int thisi, int thisj) {
	for (int i = 0; i < 5; ++i) {
		for (int j = 0; j < 5; ++j) {
			int jumpi = thisi + magic[i], jumpj = thisj + magic[j];
			if (jumpi < 0 || jumpi >= n) continue;
			if (jumpj < 0 || jumpj >= m) continue;
			if (comp[jumpi][jumpj] == -1 || comp[jumpi][jumpj] == comp[thisi][thisj]) continue;
			comp_g[comp[thisi][thisj]].insert(comp[jumpi][jumpj]);
			comp_g[comp[jumpi][jumpj]].insert(comp[thisi][thisj]);
		}
	}
}

int find_shortest_path(int c1, int c2) {
	if (c1 == c2) return 0;
	queue<int> q;
	q.push(c1);
	int vis[numcomps + 1] = {}, dist = 0;
	vis[c1] = 1;
	while (!q.empty()) {
		++dist;
		int x = q.size();
		for (int i = 0; i < x; ++i) {
			int u = q.front();
			q.pop();
			for (auto v: comp_g[u]) {
				if (vis[v]) continue;
				vis[v] = 1;
				q.push(v);
				if (v == c2) return dist;
			}
		}
	}
	return -1;
}

void solve() {
	cin >> n >> m >> sti >> stj >> endi >> endj;
	--sti;
	--stj;
	--endi;
	--endj;
	for (int i = 0; i < n; ++i) 
		for (int j = 0; j < m; ++j) cin >> g[i][j];
	numcomps = 0;
	memset(comp, -1, sizeof(comp));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (comp[i][j] != -1 || g[i][j] == '#') continue;
			dfs(i, j, ++numcomps);
		}
	}
	//I have numbered components in comp
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (comp[i][j] == -1) continue;
			find_component_edge(i, j);
		}
	}
	cout << find_shortest_path(comp[sti][stj], comp[endi][endj]) << endl;
}

void aux() {
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout<<fixed<<setprecision(10);
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 85772
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using namespace std;

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

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

  int N; cin >>N;
  int ans=0;
  vector<vector<pair<int,int>>> f(N);
  rep(i,0,N) {
    int A; cin >>A;
    rep(j,0,A) {
      int x,y; cin >>x >>y;
      x--;
      f[i].push_back(make_pair(x,y));
    }
  }
  rep(bit,0,1<<N) {
    int flag=1;
    int c=0;
    vi ho(N);
    rep(j,0,N) {
      if (bit>>j&1) {
        ho[j]=1;
      }
    }
    rep(i,0,N) {
      if (ho[i]==1) {
        rep(j,0,f[i].size()) {
          if (ho[f[i][j].first]!=f[i][j].second) {
            flag=0;
          }
        }
      }
    }
    if (flag) {
      rep(i,0,N) {
        c+=ho[i];
      }
    }
    ans=max(ans,c);
  }
  cout <<ans <<'\n';
  return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int n,m,rela,a[20][20],flag[20],sta[20];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d",&rela);
		a[i][0]=rela;
		for(int j=1;j<=rela;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=0;i<m;i++)
		scanf("%d",&sta[i]);
	int ssum=0;
	for(int i=0;i<(1<<n);i++){
		memset(flag,0,sizeof(flag));
		for(int j=0;j<n;j++)
			if(i&(1<<j))
				flag[j+1]=1;
		int flag1=1;
		for(int i1=0;i1<m;i1++){
			int sum=0;
			for(int j1=1;j1<=a[i1][0];j1++)
				if(flag[a[i1][j1]])
					sum++;
			if(sum%2!=sta[i1]){flag1=0;break;}
		}
		if(flag1) 
			ssum++;
	}
	printf("%d\n",ssum);
} 

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

int N;
vector<vector<ll>> a(20, vector<ll>(20, 0));
vector<ll> dp(1 << 16);
vector<ll> SCORE(1 << 16);

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

    cin >> N;
    REP(i, N) REP(j, N) {
        cin >> a.at(i).at(j);
    }

    for (int use = 0; use < (1 << N); use++) {
        auto bituse = bitset<20>(use);
        ll score = 0;
        REP(i, N) {
            for (int j = i; j < N; j++) {
                if (bituse.test(i) && bituse.test(j)) {
                    score += a.at(i).at(j);
                }
            }
        }
        SCORE.at(use) = score;
    }

    for (int used = 0; used < (1 << N); used++) {
        int unused = used ^ ((1 << N) - 1);
        for (int use = unused; use > 0; use = (use - 1) & unused) {
            ll next = dp.at(used) + SCORE.at(use);
            chmax(dp.at(use | used), next);
        }
    }

    cout << dp.at((1 << N) - 1) << endl;
    
    return 0;
}

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

typedef long long LL;

const int N=300000;

int n,m,a[N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

int tr[N*4+9];

void Pushup(int k){tr[k]=max(tr[k<<1],tr[k<<1|1]);}

void Change_ins(int p,int v,int l,int r,int k){
  if (l==r) {tr[k]=max(tr[k],v);return;}
  int mid=l+r>>1;
  p<=mid?Change_ins(p,v,l,mid,k<<1):Change_ins(p,v,mid+1,r,k<<1|1);
  Pushup(k);
}

int Query_max(int L,int R,int l,int r,int k){
  if (L<=l&&R>=r) return tr[k];
  int mid=l+r>>1,res=0;
  if (L<=mid) res=max(res,Query_max(L,R,l,mid,k<<1));
  if (R>mid) res=max(res,Query_max(L,R,mid+1,r,k<<1|1));
  return res;
}

int dp[N+9];

void Get_dp(){
  for (int i=1;i<=n;++i) Change_ins(a[i],dp[i]=Query_max(a[i]-m,a[i]+m,0,N,1)+1,0,N,1);
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",tr[1]);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 10216
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , t = f()
    x = f()

    ans = 0

    x.append(3e9)

    for i in range(n):
        if x[i] + t < x[i+1]:
            ans += t
        else:
            ans += x[i+1] - x[i]

    print(ans)

solve()


Measured memory_bytes: 25708
N = int(input())
HIGH = [int(x) for x in input().split()]
LOW = [int(x) for x in input().split()]

def main():
    first = HIGH.pop(0)
    last = LOW.pop()

    mid_len = len(HIGH)
    mid_sum = 0
    for i in range(mid_len)[::-1]: # reversed
        mid_sum = max(mid_sum, sum(HIGH))
        HIGH[i] = LOW[i]
    mid_sum = max(mid_sum, sum(LOW))
    result = first + mid_sum + last
    print(result)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class37
    {
        static void Main()
        {
            long h = long.Parse(Console.ReadLine());
            long ans = 0;
            
            while (h!=0)
            {
                h /= 2;
                ans = ans * 2 + 1;
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
  int N;
  double b;
  cin >> N;
  vector <int> a(N);
  for(int j=0;j<N;j++) {
    cin >> a.at(j);
  }
  sort(a.begin(),a.end());
  b=a.at(0);
  for(int i=1;i<N;i++){
    b=(b+a.at(i))/2.0;
  }
  cout << b << endl;
  
  
}

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

struct restaurant{
  int id;
  char city[20];
  int point;
};


int asc(const void *a, const void *b);

int
main(int argc, char *argv[])
{
  int n;
  struct restaurant r[100];
  scanf("%d", &n); char s[20]; int c;
  for(int i = 0; i < n; i++){
    scanf("%s %d", s, &c);
    r[i].point = c;
    strcpy(r[i].city, s);
    r[i].id = i + 1;
  }

  qsort(r, n, sizeof(struct restaurant), asc);

  for(int i = 0; i < n; i++) printf("%d\n", r[i].id);

  return 0;
}

int asc(const void *a, const void *b){
  struct restaurant *A = (struct restaurant *)a;
  struct restaurant *B = (struct restaurant *)b;
  if(strcmp(A->city, B->city) > 0 || (strcmp(A->city, B->city) == 0 && A->point < B->point)){
    return 1;
  }
  else if(strcmp(A->city, B->city) == 0 && A->point == B->point) return 0;
  else return -1;
}

Measured memory_bytes: 128
n,m = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for a1 in (-1,1):
  for a2 in (-1,1):
    for a3 in (-1,1):
      l.sort(reverse=True, key=lambda x:a1*x[0] + a2*x[1] + a3*x[2])
      be,de,po = 0,0,0
      for x in l[:m]:
        be += x[0]
        de += x[1]
        po += x[2]
      ans = max(ans,abs(be)+abs(de)+abs(po))
print(ans)

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

int main(){
    int a,b;    cin >> a >> b; 
    if(a <= 9 && b <= 9){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 888
N = int(input())
c=0
if 1 <= N <= 81:
  for i in range(9):
    if (i+1)*1 <= N <=(i+1)*9 and N % (i+1) == 0:
      c+=1
    else:
      c+=0
if c==0:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

const u_int64_t R = 1'000'000'007LL;

u_int64_t dp[100'000][2];

int main()
{
    string L;
    cin >> L;

    for (int i = 0; i < L.size(); i++)
    {
        if (i == 0)
        {
            dp[i][0] = 2LL;
            dp[i][1] = 1LL;
            continue;
        }

        dp[i][0] = (L[i] == '0' ? dp[i - 1][0] : dp[i - 1][0] * 2LL) % R;

        dp[i][1] = dp[i - 1][1];
        dp[i][1] = (dp[i][1] * 3LL) % R;
        dp[i][1] = (dp[i][1] + (L[i] == '0' ? 0LL : dp[i - 1][0])) % R;
    }

    cout << (dp[L.size() - 1LL][0] + dp[L.size() - 1LL][1]) % R << endl;

    return 0;
}

Measured memory_bytes: 2048
/*
Hanit Banga
*/
 
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int N = 5e3 + 5;
 
bool f[N][N] = {0}, g[N][N] = {0};
int a[N];
 
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
 
	sort(a + 1, a + n + 1);
	int ans = n;
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] >= k)
		{
			n = i - 1;
			ans = n;
			break;
		}
	}	
 
	for (int i = 0; i <= n + 1; ++i)
		f[i][0] = g[i][0] = true;
 
	for (int j = 1; j < k; ++j)
	{
		for (int i = 1; i <= n; ++i)
		{
			f[i][j] = f[i - 1][j];
			if (j >= a[i])
				f[i][j] |= f[i - 1][j - a[i]];
		}
 
		for (int i = n; i >= 1; --i)
		{
			g[i][j] = g[i + 1][j];
			if (j >= a[i])
				g[i][j] |= g[i + 1][j - a[i]];
		}
	}
 
	for (int i = 1; i <= n; ++i)
	{
		int l = k - 1, x = 0;
		while (l >= 0 and !f[i - 1][l])
			--l;
 
		x = max(x, l);
		for (int r = 1; r < k; ++r)
		{
			if (!g[i + 1][r])
				continue;
 
			while (l >= 0 and l + r >= k and f[i - 1][l])
				--l;
 
			x = max(x, l + r);
		}
 
		// cout << a[i] << ' ' << x << endl;
		if (x >= k - a[i])
		{
			--ans;
			// cout << a[i] << endl;
		}
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 49152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0024
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "";
            while ((str = Console.ReadLine())!= null)
                {
                double v = double.Parse(str);
                double t = v / 9.8;
                double y = 4.9 * Math.Pow(t, 2);
                double n = (y + 5) / 5;
                double nValue = System.Math.Ceiling(n);

                Console.WriteLine(nValue);
            }
        }
    }
}



Measured memory_bytes: 13848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().ToCharArray();
            var distinct = vals.Distinct();
            if (distinct.Count() != 2)
            {
                Console.WriteLine("No");
            }
            else
            {
                var d = distinct.ToList();
                foreach(var dd in d)
                {
                    if(vals.Where(x => x==dd).Count() != 2)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 13276
struct UnionFind {
    par: Vec<usize>,
    sizes: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            par: (0..n).collect(),
            sizes: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        } else {
            self.par[x] = self.find(self.par[x]);
            self.par[x]
        }
    }

    fn unite(&mut self, mut x: usize, mut y: usize) {
        x = self.find(x);
        y = self.find(y);

        if x == y { return; }

        if self.sizes[x] > self.sizes[y] {
            std::mem::swap(&mut x, &mut y);
        }

        self.par[x] = y;
        self.sizes[y] += self.sizes[x];
    }

    fn size(&mut self, mut x: usize) -> usize {
        x = self.find(x);
        self.sizes[x]
    }
}

fn main() {
    let (n, m): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        let (a, b): (usize, usize) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            )
        };

        uf.unite(a, b);
    }

    let mut ans = 0;
    for i in 0..n {
        ans = std::cmp::max(ans, uf.size(i));
    }
    println!("{}", ans);
}

Measured memory_bytes: 5164
// while( !(succeed == try()) );

#include "bits/stdc++.h"
using namespace std;

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{	
	int n, m;
	cin>>n>>m;

	int arr[m];
	int sum = 0;
	loop(i,0,m) 
	{
		cin>>arr[i];
		sum+=arr[i];
	}

	if(sum > n ) cout<<-1;
	else cout<<n-sum;

}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
	float w;

	while (scanf("%f", &w) != EOF){
		if (w <= 48){
			printf("light fly\n");
		}
		else if (w > 48 && w <= 51){
			printf("fly\n");
		}
		else if (w > 51 && w <= 54){
			printf("bantam\n");
		}
		else if (w > 54 && w <= 57){
			printf("feather\n");
		}
		else if (w > 57 && w <= 60){
			printf("light\n");
		}
		else if (w > 60 && w <= 64){
			printf("light welter\n");
		}
		else if (w > 64 && w <= 69){
			printf("welter\n");
		}
		else if (w > 69 && w <= 75){
			printf("light middle\n");
		}
		else if (w > 75 && w <= 81){
			printf("middle\n");
		}
		else if (w > 81 && w <= 91){
			printf("light heavy\n");
		}
		else if (w > 91){
			printf("heavy\n");
		}
	}

	return (0);
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod ll(1e9+7)
ll exp(ll a,ll b)
{
  if(b==0)
    return 1;
  if(b%2==0)
    return exp(a*a%mod,b/2);
  return a*exp(a*a%mod,(b-1)/2)%mod;
}
int main()
{
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
   int n,k;
   cin>>n>>k;
   vector<int>arr(n+1);
   for(int i=1; i<=n; i++){
    cin>>arr[i];
   }
   int mx=0;
   for(int i=0; i<=k; i++){
    for(int j=0; j<=(k-i); j++){
      if(i+j>=n){
        vector<int>ans;
        int sum=0;
        for(int x=1; x<=n; x++){
          sum+=arr[x];
          ans.push_back(arr[x]);
        }
        sort(ans.begin(),ans.end());
        int num=min(n,k-n);
        for(int x=0; x<num; x++){
          if(ans[x]>=0)
            break;
          sum-=ans[x];
        }
        mx=max(sum,mx);
      }
      else{
        vector<int>ans;
        int sum=0;
        for(int x=1; x<=i; x++){
          ans.push_back(arr[x]);
          sum+=arr[x];
        }
        for(int x=n; x>=(n-j+1); x--){
          ans.push_back(arr[x]);
          sum+=arr[x];
        }
        int num=min(i+j,k-(i+j));
        sort(ans.begin(),ans.end());
        for(int x=0; x<num; x++){
          if(ans[x]>=0)
            break;
          sum-=ans[x];
        }
        mx=max(sum,mx);
      }
    }
   }
   cout<<mx;
   return 0;
}

Measured memory_bytes: 3616
#pragma warning(disable: 4996)
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <set>
#include <map>
#define MOD 1000000007

using namespace std;

int N, M;
int dp[100001];
bool ex[100001];
int main() {
	cin >> N >> M ;
	for(int i = 0; i <= 100000; i++) {
		dp[i] = 0;
		ex[i] = false;
	}

	for(int i = 0; i < M; i++) {
		int t;
		cin >> t;
		ex[t] = true;
	}

	dp[0] = 1;

	if(!ex[1]) {
		dp[1] = dp[0];
	}

	for(int i = 2; i <= N; i++) {
		dp[i] = dp[i - 1] + dp[i - 2];
		if(ex[i]) {
			dp[i] = 0;
		}
		dp[i] %= MOD;
	}
	
	//for(int i = 0; i <= N; i++) {
	//	cout << dp[i] << " ";
	//}
	
	cout << dp[N];

	return 0;
}




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

int main(){
	int H, R;
	cin>>H>>R;
	
	if(R + H == 0) cout<<"0"<<endl;

	if(R + H < 0) cout<<"-1"<<endl;

	if(H + R > 0) cout<<"1"<<endl;

	return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3924
unittest
{
	assert( [ "4 150", "150 140 100 200" ].parse.expand.solve == 2 );
	assert( [ "1 500", "499" ].parse.expand.solve == 0 );
	assert( [ "5 1", "100 200 300 400 500" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto hs = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], hs );
}

auto solve( long k, long[] hs )
{
	return hs.count!( ( h ) => k <= h );
}


Measured memory_bytes: 4348
#include <stdio.h>

int main(){
int a,b;
int ans;
scanf("%d%d", &a,&b);
if((a + b) % 2 > 0){
    ans = (a + b) / 2;
    ans++;
}else{
    ans = (a + b) / 2;
}
printf("%d",ans);
return 0;
}


Measured memory_bytes: 128
# 人数
n = int(input())
# 人数分繰り返す
# 証言の個数を格納するリスト
a = []
# 証言を格納するリスト
xy = []
for i in range(n):
    # 証言の個数
    a_n = int(input())
    # 証言の個数分繰り返す
    xy_n = []
    for i in range(a_n):
        xy_n.append(list(map(int, input().split())))
    a.append(a_n)
    xy.append(xy_n)

def judge(bit):
    # こっちの方が直感的だが...
    # bit = bin(bit).replace('0b', '')
    # for i in bit:

    # bit....n人の証言を検証する
    for i in range(n):
        # 該当ビットが0なら無視
        if not(bit & (1 << i)):
            continue
        # 証言を検証
        for j in xy[i]:
            # その人を正直と言っているが、実際嘘つきだったらだめ
            # 人物番号とbitのズレは解消すること！
            if j[1] == 1 and not(bit & (1 << (j[0]-1))):
                return False

            # 不親切なのに実際は親切
            if j[1] == 0 and (bit & (1 << (j[0]-1))):
                return False

    return True

max_person = 0
# 2**N通りで考える
for bit in range(1 << n):
    if judge(bit):
        count = 0
        # bitに含まれる人数を数える
        for i in range(n):
            if bit & (1 << i):
                count += 1
        if max_person < count:
            max_person = count

print(max_person)

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

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

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  ll a[n];rep(i,n){cin>>a[i];}

  ll result=0;
  rep(i,42){
    int d = 40-i;
    if( d!=-1 && !(k & (1LL<<d)) )continue;

    ll tmp=0;
    rep(j,41){
      ll e=40-j;
      ll mask = 1LL<<e;
      ll num=0;
      rep(i,n)if(mask & a[i])num++;

      if(e>d){
        if(k & mask) tmp += mask*(n-num);
        else tmp += mask*num;
      }else if(e==d){
        tmp += mask*num;
      }else{
        tmp += mask*max(num, n-num);
      }
    }
    result = max(result, tmp);
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int main() {
  // input
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  priority_queue<int> que;
  rep(i, n) {
    int a;
    cin >> a;
    que.push(a);
  }

  // process 0
  if (n < k) {
    cout << 0 << endl;
    return 0;
  } 

  // proccess 1
  rep(i, k) {
    que.pop();
  }

  // process 2
  ll cnt = 0;
  while(!que.empty()) {
    cnt += que.top();
    que.pop();
  }

  // output: 最小の通常攻撃回数
  cout << cnt << endl;
}


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    cout << x + y + z << endl;

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3092
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int s[10];
int main(){
	for(int i=1;i<=4;i++)
		scanf("%1d",&s[i]);
	if(s[1]+s[2]+s[3]+s[4]==7) 
		printf("%d+%d+%d+%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]+s[2]+s[3]-s[4]==7) 
		printf("%d+%d+%d-%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]-s[2]+s[3]+s[4]==7) 
		printf("%d-%d+%d+%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]+s[2]-s[3]+s[4]==7) 
		printf("%d+%d-%d+%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]+s[2]-s[3]-s[4]==7) 
		printf("%d+%d-%d-%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]-s[2]-s[3]-s[4]==7) 
		printf("%d-%d-%d-%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]-s[2]-s[3]+s[4]==7) 
		printf("%d-%d-%d+%d=7\n",s[1],s[2],s[3],s[4]);
	else if(s[1]-s[2]+s[3]-s[4]==7) 
		printf("%d-%d+%d-%d=7\n",s[1],s[2],s[3],s[4]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int stricmp(char* ch1,char* ch2){
	int ch1_length = 0,ch2_length = 0,div;
	for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
	for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
	if(ch1_length != ch2_length) return -1;
	for(int i = 0; ch1[i] != '\0';i++)
	{
		div = ch1[i] -ch2[i];
		if(div != 0 && div != 32 && div != -32)
			return -1;
	}
	return 0;
}

int main(){
	char W[11],T[1001];
	int count = 0;
	scanf("%s",W);
	while(true){
		scanf("%s",T);
		if(strcmp("END_OF_TEXT",T) == 0) break;
		if(stricmp(T, W) == 0) count++;
	}
	printf("%d\n",count);
}


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

# define All(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using ull = unsigned long long;
using ld  = long double;


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector <int> p(a), q(b), r(c+x+y);

    for (auto& pi: p) {
        cin >> pi;
    }

    for (auto& qi: q) {
        cin >> qi;
    }

    sort(All(p), greater<int>());
    sort(All(q), greater<int>());

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

    for (int j=0; j<x; j++, i++) {
        r[i] = p[j];
    }

    for (int j=0; j<y; j++, i++) {
        r[i] = q[j];
    }

    sort(All(r), greater<int>());

    ll ans = 0;
    for (int j=0; j<x+y; j++) {
        ans += r[j];
    }

    cout << ans << endl;    

    return 0;
}


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <cstring>

#define ll long long
#define ld long double
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f3f3f3f3f
#define point complex <double> 
#define pi acos(-1)
#define mod 1000000007


using namespace std;
int arr[200005];


int main() {
	HS
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n);
	int mini = 1e9;
	for (int i = 0; i <n; i++)
	{
		if(arr[i+k-1])
		mini = min(mini, arr[i + k-1] - arr[i]);
	}
	cout << mini << endl;
	return 0;
}

Measured memory_bytes: 3988