akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

int N;
int d[50][50];

int main()
{
    while (cin >> N, N)
    {
        rep(i, 10) rep(j, 10) d[i][j] = iINF;
        rep(i, N)
        {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = c;
            d[b][a] = c;
        }

        rep(i, 10) d[i][i] = 0;

        rep(k, 10) rep(i, 10) rep(j, 10) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

        int ans = iINF, num;

        rep(i, 10)
        {
            int sum = 0;
            rep(j, 10)
            {
                if (d[i][j] == iINF)
                    break;
                sum += d[i][j];
            }

            if (sum < ans && sum != 0)
            {
                num = i;
                ans = sum;
            }
        }

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


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

int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int anum = sa.size();
    int bnum = sb.size();
    int cnum = sc.size();
    string turn = "a";
    string ans;

    while (1)
    {
        if (turn == "a") {
            if (sa.size() == 0) {
                ans = "A";
                break;
            }
            turn = sa[0];
            sa.erase(sa.begin());
            anum --;
        } else if (turn == "b") {
            if (sb.size() == 0) {
                ans = "B";
                break;
            }
            turn = sb[0];
            sb.erase(sb.begin());
            bnum --;
        } else {
            if (sc.size() == 0) {
                ans = "C";
                break;
            }
            turn = sc[0];
            sc.erase(sc.begin());
            cnum --;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int n, x,count = 0;

	for (;;){
		cin >> n >> x;

		if (n == 0 && x == 0){
			break;
		}

		for (int oo = 1; oo <= n; oo++){
			for (int ooo = 1; ooo <= n; ooo++){
				for (int oooo = 1; oooo <= n; oooo++){
					if (oo != ooo && oo != oooo && ooo != oooo){
						if (oo + oooo + ooo == x){
							count += 1;
						}
					}
				}
			}
			
		}
		count = count / 6;
		cout << count << endl;
		count = 0;
	}




}


Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-')	f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*f;
}

int main()
{
	ll n,m;
	ll ans=0;
	cin>>n>>m;
	if (n>m) swap(n,m);
	if (n==1)
	{
		if (m==1)
			cout<<1;
		else 
			cout<<m-2;
		return 0;
	} 
	ans=(ll)n*m;
	ans-=(ll)(n+n+m+m);
	ans+=4;
	cout<<ans;
	return 0;
}


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

int main()
{
    int z=0, a[5], n[5], i, m;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
        n[i]=a[i]%10;
    }
    m=n[0];
    for(i=1;i<5;i++)
    {
        if(n[i]!=0&&n[i]<m)
            m=n[i];
    }
    for(i=0;i<5;i++)
    {
        if(n[i]==0)
            z=z+a[i];
        else
            z=z+(a[i]/10+1)*10;
    }
    if(m!=0)
    z=z-10+m;
    else
    ;
    printf("%d\n",z);
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import java.math.*;

public class Main{
	static final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static int tc;
	static final int MOD=1_000_000_007;
	public static int[] inputArray(String str){
		String[] s=str.split(" ");
		int[] array=new int[s.length];
		for(int i=0;i<s.length;i++) {
			array[i]=Integer.parseInt(s[i]);
		}
		return array;
	}
	public static void main(String[] args)throws IOException {
		//tc=Integer.parseInt(br.readLine());
		tc=1;
		while(tc-->0) {
			int n=Integer.parseInt(br.readLine());
			int[] input=inputArray(br.readLine());
			int max=0,count=0;
			for(int i=0;i<n-1;i++) {
				if(input[i]>=input[i+1]) {
					count++;
					max=Math.max(max, count);
				}else {
					count=0;
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 45140
def main():
    n = int(input())
    p = [int(input()) for _ in range(n)]

    idx = make_index(p)
    c = count_sequence(p, idx)
    ans = n - c
    print(ans)

def make_index(p):
    idx = dict()
    for i, v in enumerate(p):
        idx[v] = i
    return idx

def count_sequence(p, idx):
    cmax = 0
    c = 0
    i = -1

    x = 1
    while True:
        j = idx.get(x, None)
        if j is None:
            cmax = max(cmax, c)
            break
        elif j < i:
            cmax = max(cmax, c)
            c = 1
            i = j
        else:
            c += 1
            i = j
        x += 1

    return cmax

main()


Measured memory_bytes: 35080
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
LL sum[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	LL k;
	cin >> n >> k;
	while (n--)
	{
		int a, b;
		cin >> a >> b;
		sum[a] += b;
	}
	for (int i = 1; i < N; i++)
	{
		k -= sum[i];
		if (k <= 0)
		{
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n, k = IN()
	pl = list(IN())
	ppl=[(v+1)/2 for v in pl]
	#pa(ppl)
	ss=sum(ppl[:k])
	ret=ss
	#pa((ss,ret))
	for i in range(n-k):
		ss-=ppl[i]
		ss+=ppl[i+k]
		ret=max(ret,ss)
		#pa((ss,ret))
		
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
bool is_bad[100005];
/***** MAIN *****/
signed main() {
  int n = in();
  int m = in();
  int heights[n];
  REP(i,n) {
    cin >> heights[i];
  }
  int ans = n;
  REP(i,m) {
    int a = in(), b = in();
    --a; --b;
    if(heights[a] == heights[b]) {
      if(!is_bad[a]) {
        --ans;
        is_bad[a] = true;
      }
      if(!is_bad[b]) {
        --ans;
        is_bad[b] = true;
      }
    } else if(heights[a] < heights[b]) {
      if(!is_bad[a]) {
        --ans;
        is_bad[a] = true;
      }
    } else {
      if(!is_bad[b]) {
        --ans;
        is_bad[b] = true;
      }
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 4508
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO
  LL a, b, c, d;
  cin >> a >> b >> c >> d;
  LL opt = a * c;
  max_self(opt, a * d);
  max_self(opt, b * c);
  max_self(opt, b * d);

  cout << opt << '\n';
  return 0;
}



Measured memory_bytes: 3528
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc101/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N, K;
    cin >> N >> K;
    int x[N];
    rep(i, N){
        cin >> x[i];
    }
    ll ans = INF;
    for(int i = 0; i <= N - K; i++){
        ll width = x[i + K - 1] - x[i];
        ll a = min(abs(x[i + K - 1]), abs(x[i]));
        if(a + width < ans) ans = a + width;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, S;
int seq[300000];

int main() {
  while (scanf("%d %d", &n, &S), n|S) {
    REP(i, n) {
      scanf("%d", &seq[i]);
    }
    seq[n] = 1 << 30;
    sort(seq, seq + n);
    ll ans = 0;
    REP(i, n) {
      int v = S - seq[i];
      if (seq[i] * 2 > S) { ans--; }
      int ng = upper_bound(seq, seq + n, v) - seq;
      ans += n - ng;
    }
    ans /= 2;
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 0
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let s: String = read();

  let mut hash = HashMap::new();
  let mut a: String = String::from("Sunny");
  let mut a_val: String = String::from("Sunny");
  let mut b: String = String::from("Cloudy");
  let mut b_val: String = String::from("Cloudy");
  let mut c: String = String::from("Rainy");
  let mut c_val: String = String::from("Rainy");

  hash.insert(a, b_val);
  hash.insert(b, c_val);
  hash.insert(c, a_val);

  println!("{}", hash.get(&s).unwrap());
}

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

ll N;
vector<ll> g[MAX];
map<P, ll> eid;
map<P, ll> eclr;
ll K=0;

void bfs(ll p, ll u) {
  chmax(K, g[u].size());
  
  ll i;
  ll c=0;
  for(i=0; i<g[u].size(); i++) {
    ll v=g[u][i];
    
    if(p!=-1) {
      if(v==p) continue;
      if(eclr[{min(p, u), max(p, u)}]==c) c++;
    }
    
    eclr[{min(u, v), max(u, v)}]=c;
    c++;
    bfs(u, v);
  }
  
}

int main(void) {
  cin >> N;
  ll i;
  
  for(i=0; i<N-1; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
    eid[{min(a, b), max(a, b)}]=i;
  }
  
  bfs(-1, 0);
  
  vector<P> res;
  for(auto it=eid.begin(); it!=eid.end(); it++) {
    res.pb({it->sc, eclr[{it->ft.ft, it->ft.sc}]});
  }
  
  
  pt(K);
  sort(res.begin(), res.end());
  for(i=0; i<N-1; i++) {
    pt(res[i].sc+1);
  }
}












Measured memory_bytes: 21116
#include <iostream>
using namespace std;
int main()
{
	int n;
	int A[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
	while (cin >> n){
		int i = 0, k;
		while (n != 0){
			k = n;
			n = n / 2;
			if (1 == k % 2){
				cout << A[i];
				if (n != 0)
					cout << " ";
			}
			++i;
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( 1 )
	{
		int max_no = -1;
		int max_value = 0;
		for ( int i = 0; i < 5; i++ )
		{
			int a, b;
			cin >> a >> b;
			if ( a == 0 && b == 0 )
				break;
			if ( a+b > max_value )
			{
				max_no = i;
				max_value = a+b;
			}
		}
		if ( max_no == -1 )
			break;
		cout << (char)('A'+max_no) << " " << max_value << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std
 
Willy Indrayana Komara;

bool besarDulu(const int &a, const int &b)
{
    return a > b;
}

bool tupleSort(tuple<int, int, int> &a, tuple<int, int, int> &b)
{
    return get<2>(a) > get<2>(b);
}

using ll = long long int;
const int MAX = 1000000000;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if (s[0] != 'h' || s.length() % 2 == 1)
    {
        puts("No");
        return 0;
    }
    for (int i = 0; i < s.length(); i+=2)
    {
        if (!(s[i] == 'h' && s[i+1] == 'i'))
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

int main()
{
	int n;
	int a[100];
	int ans;

	while (1) {
		cin >> n;
		if (n == 0) break;
		ans = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i]; 
		}
		sort(a, a + n);
		for (int i = 1; i < n - 1; i++) {
			ans += a[i];
		}
		ans /= n - 2;
		cout << ans << endl;
	}

	

	return (0);
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
  // #endif 

   
   int a,b,k;
   cin>>a>>b>>k;

    
    int x=min(a,k); a-=x; k-=x;
    b-=min(b,k);
    cout<<a<<" "<<b<<"\n";

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef unsigned long long ll;


int main(void){
    int n,ans=0,max=0;
    cin>>n;
    vector<int> h(n);
    vector<int> g(n,0);
    rep(i,n){
        cin>>h[i];
        max=std::max(max,h[i]);
    }
    bool f=false;
    rep(j,max){
        f=false;
        rep(i,n){
            if(!f&&g[i]<h[i]){
                f=true;
                ++ans;
                ++g[i];
            }
            else if(f&&g[i]<h[i]){
                ++g[i];
            }
            else if(f&&g[i]==h[i]){
                f=false;
            }
        }
    }
    cout<<ans;
}
/*
*/

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 3e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn], b[maxn];

int solve(int val)
{
	for (int i = 0; i < 2 * n - 1; i++)
		b[i] = (a[i] >= val);

	int pos = n - 1;
	for (int i = 0; i < n - 1; i++)
	{
		if ((b[pos - i] && b[pos - i - 1]) || (b[pos + i] && b[pos + i + 1]))
			return 1;
		if ((!b[pos - i] && !b[pos - i - 1]) || (!b[pos + i] && !b[pos + i + 1]))
			return 0;
	}
	return b[0];
}

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

	cin >> n;
	for (int i = 0; i < 2 * n - 1; i++)
		cin >> a[i];
	
	int l = 0, r = 2 * n, mid;
	while (r - l > 1)
	{
		mid = (l + r) / 2;
		if (solve(mid))
			l = mid;
		else
			r = mid;
	}
	cout << l << endl;
}



Measured memory_bytes: 1792
#include<stdio.h>
 int main(void)

{
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a<b){
printf("a < b\n",a,b);
}
if(a==b){
printf("a == b\n",a,b);
}
if(a>b){
printf("a > b\n",a,b);
}
return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int n,k;
  cin >>n >>k;
  k=min(k,50);
  int l[n],r[n];
  int g[n];
  rep(i,n)cin >> g[i];
  int a[n];

  rep(times,k){
    rep(i,n)a[i]=0;
    for(int i=1;i<=n;i++){
      l[i-1]=max(i-g[i-1]-1,0),r[i-1]=min(i+g[i-1],n);//始点を+1,終点を-1加える(もし始点と終点が同じ場合があるなら、--lだけにする)
      a[l[i-1]]++;
      a[r[i-1]]--;
    }

    rep(i,n){
      if(0<i)a[i]+=a[i-1];//シュミレーションする
    }
    rep(i,n)g[i]=a[i];
  }
  rep(i,n)cout << min(a[i],n) << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    
    ll n,x;
    cin >> n >> x;
    ll right,left,cnt;
    cnt = 0;

    right = 0;
    
    rep(i,n){

        left = right;
        cin >> right;
        ll sum = left + right;
        if(sum > x){
             right -= (sum - x);
             cnt += sum - x;
        }
        
    }
    cout << cnt << endl;

}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

template<typename T> struct BIT {
    int S;
    vector<T> v;

    BIT<T>(int _S) {
        S = _S;
        v.resize(S+1);
    }

    void update(int i, T k) {
        for(i++; i<=S; i+=i&-i)
            v[i] = v[i] + k;
    }

    T read(int i) {
        T sum = 0;
        for(i++; i; i-=i&-i)
            sum = sum + v[i];
        return sum;
    }

    T read(int l, int r) {
        return read(r) - read(l-1);
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int N;
    cin >> N;

    vi a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    vi vals = a;
    sort(all(vals));
    vals.erase(unique(all(vals)), vals.end());

    ll medians = N * 1ll * (N - 1) / 2 + N;

    BIT<int> bit(2 * N);

    int ans = vals.size() - 1;
    int lo = 0, hi = vals.size() - 2;
    while (lo <= hi) {
        int mi = (lo + hi) / 2;

        fill(all(bit.v), 0);

        ll sub = 0;
        int cur = 0;
        bit.update(N + 0 + 1, 1);
        for (int i = 0; i < N; i++) {
            if (a[i] <= vals[mi])
                cur++;
            else
                cur--;
            sub += bit.read(N + cur);
            bit.update(N + cur + 1, 1);
        }

        if (sub > medians / 2) {
            ans = mi;
            hi = mi - 1;
        } else {
            lo = mi + 1;
        }
    }

    cout << vals[ans] << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> youbou(m); 
    REP(i,m){
        cin>>youbou[i].second>>youbou[i].first;
    }
    sort(youbou.begin(), youbou.end());

    vector<int> cut;
    int result = 1;
    cut.push_back(youbou[0].first - 1);

    FOR(i,1,m){

        for(auto x:cut){
            if(youbou[i].second<=x&&x<youbou[i].first){
                goto END;
            }
        }

        result++;
        cut.push_back(youbou[i].first - 1);

    END:;

    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1024
import math

abcd = int(input())

a = abcd // 1000
b = (abcd - a * 1000) // 100
c = (abcd - a * 1000 - b * 100) // 10
d = abcd % 10

for i in range(2**3):
    siki = []
    for j in range(3):
        if(i >> j & 1):
            siki.append("+")
        else:
            siki.append("-")
    siki2 = str(a) + siki[0] + str(b) + siki[1] + str(c) + siki[2] + str(d)
    if(eval(siki2) == 7):
        print(siki2+"=7")
        break

Measured memory_bytes: 38384
S = input()
n = len(S)
dp1, dp2 = [-1]*n, [-1]*n
dp1[0] = 1
dp2[1] = 1
if S[0] != S[1]:
  dp1[1] = 2
for i in range(2, n):
  if S[i-1] == S[i]:
    dp1[i] = dp2[i-1] + 1
  else:
    dp1[i] = max(dp2[i-1]+1, dp1[i-1]+1)
  if S[i-3:i-1] == S[i-1:i+1]:
    dp2[i] = dp1[i-2] + 1
  else:
    dp2[i] = max(dp1[i-2]+1, dp2[i-2]+1)
print(max(dp1[-1], dp2[-1]))

Measured memory_bytes: 19160
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	int a,b;cin>>a>>b;
	int y=(b-2*a)/2;
	int x=a-y;
	if(2*x+4*y==b&&x>=0&&y>=0&&x<=a&&y<=a&&x+y<=a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}	
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()

struct event{
    long time, where; int flag;
    event(long t, long w, int f):time(t),where(w),flag(f){}
    bool operator<(const event & another) const{
        if(time != another.time) return time < another.time;
        else return flag < another.flag;
    }
};

int main(){
    int N, Q; cin>>N>>Q;
    vector<event> E;

    rep(i,N){
        long S, T, X; cin>>S>>T>>X;
        E.push_back(event(S-X, X, 1));
        E.push_back(event(T-X, X, 0));
    }
    sort(all(E));

    set<long> stopped; int k = 0;
    rep(i,Q){
        long D; cin>>D;
        while(k < E.size()){
            event e = E[k];
            if(e.time > D) break;
            if(e.flag) stopped.insert(e.where);
            else stopped.erase(e.where);
            k++;
        }
        if(stopped.empty()) cout << -1 << endl;
        else cout << *(stopped.begin()) << endl;
    }
}

Measured memory_bytes: 21864
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<int> a(n+2);
    rep(i, n) cin >> a[i+1];
    a[0] = a[n+1] = 0;
    int total = 0;
    rep(i, n+1) {
        total += abs(a[i]-a[i+1]);
    }
    //cout << total;
    for (int i=1; i<=n; i++) {
        int x = total
              -(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))
              +(abs(a[i-1]-a[i+1]));
        cout << x << endl;
    }
}


Measured memory_bytes: 1664
import numpy as np
import math

N, K = map(int, input().split())
P = 0

if K<=N:
    for i in range(K-1):
        m = math.ceil(np.log2(K/(i+1)))
        P += float(0.5**m)
    print(float((N-K+1+P)/N))
else:
    for i in range(N):
        m = math.ceil(np.log2(K/(i+1)))
        P += float(0.5**m)
    print(float(P/N))

Measured memory_bytes: 21272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  string s;
  cin >> s;

  string ans = "Yes";
  for (int i = 0; i < s.size(); i++) {
    char c = s.at(i);

    if ((i + 1) % 2 == 0) {
      if (c == 'R') ans = "No";
    } else {
      if (c == 'L') ans = "No";
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

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

int func(long long n) {
	if (n < 10)return 1;
	return func(n/10)+1;
}
int a[100010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	REP(i, N) {
		scanf("%d", &a[i]);
		a[i]--;
	}
	int x = 0;
	REP(i, 100010) {
		if (x == 1) {
			cout << i << endl;
			return 0;
		}
		x = a[x];
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  ll m;
  cin>>m;
  
  ll num[m+1][3];
  
   for(int j=1;j<=m;j++){
  for(int i=1;i<=2;i++){
    num[j][i]=0;
   ll a;
    cin>>a;
      num[j][i]=a;
    }
  }
  

  ll cnt=0;
  for(int i=1;i<=m;i++){
    cnt+=(ll)num[i][1]*num[i][2];
  }
  
  ll ans=0;
  
  ll mz=0;
  for(int i=1;i<=m;i++){
    mz+=num[i][2];
  }
  
  if(mz<=1){
    cout<<0<<endl;
    return 0;}
  

  ans=(cnt-1)/9;
  ans+=mz-1;
  
  cout<<ans<<endl;
  return 0;
  
  
  
  
 
 
}

Measured memory_bytes: 4992
s = input()
s += 'R'
n = len(s)

ans = [0 for i in range(n-1)]

def move(block):
    blen = len(block)
    lidx = block.find('L')
    if lidx ==-1:
        return
    ans[restart+lidx] = blen//2
    ans[restart+lidx-1] = blen//2
    if blen %2 ==1:
        if lidx %2 ==0:
            ans[restart+lidx]+=1
        else:
            ans[restart+lidx-1]+=1
    

restart = 0
while True:
    sep = s.find('LR')
    block = s[0:sep+1]
    move(block)
    restart += sep+1
    s = s[sep+1:]
    if sep ==-1:
        break

print(*ans)

Measured memory_bytes: 6312
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	int n;
	string s,t;
	cin>>n>>s>>t;
	rep(i,n){
		cout<<s[i];
		cout<<t[i];
	}
}				

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=2; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using Edge = pair<ll,ll>;
using Graph =vector<vector<int>>;
ll inf=1000000000000000000;

int main() {
  ll n;
  cin >>n;
  vector<pair<ll,int>> fs;
  for(ll i=2;i*i<=n;i++){
    int x=0;
    while(n%i==0){
      x++;
      n/=i;
    }
    fs.emplace_back(i,x);
  }
  if(n!=1)fs.emplace_back(n,1);
  int ans=0;
  for(auto p:fs){
    int x=p.second;
    int b=1;
    while(b<=x){
      x-=b;
      b++;
      ans++;
    }
  }
  cout<<ans<<endl;
}


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


int main() {
    int n;
    cin >> n;
    vector<pair<string,int>> data(n,pair<string,int>());
    rep(i,n)cin >> data.at(i).first >> data.at(i).second;
    string x;
    cin >> x;
    bool asleep = false;
    int sum = 0;
    rep(i,n){
        if(asleep)sum += data.at(i).second;
        if(data.at(i).first == x)asleep = true;
    }
    cout << sum << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import math
N,M = map(int, input().split())
N_num = 0
M_num = 0

if N >= 2:
  N_num = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
if M >= 2:
  M_num = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))

print(N_num + M_num)

Measured memory_bytes: 3060
//-----------------------------------------------------------
// すぐ使える
//-----------------------------------------------------------
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        

		// 1行目数字
		long N = Integer.parseInt(br.readLine());

		// 2行目、複数数字
		String[] ss0 = br.readLine().trim().split(" ", 0);
		long[] ll = new long[ss0.length];  //0で初期化される
		for(int i=0; i<ll.length; i++) ll[i] = Long.parseLong(ss0[i]);

				//	checkInput(ll);

		Arrays.sort(ll);
				//	checkInput(ll);

		long ans = 0;
		long sam = 0;
		long l = ll[0];
		for(int i=0; i+1<ll.length; i++) {
			//自分より一つ上を吸収できるなら、生き残れる
			if ( (l*2) >= ll[i+1] ) {
				//吸収して大きくなる
				l += ll[i+1];
				ans += 1;
				//System.out.print("OK ");
				//System.out.println(i+" sam="+sam+"  l="+l);
			} else {
				//吸収できない場合
				l = ll[i+1] + ll[i] + sam;
				ans = 0;
				//System.out.print("NG ");
				//System.out.println(i+" sam="+sam+"  l="+l);
			}
			sam += ll[i];
		}

		System.out.println(ans + 1);
        return;
    }
    //-----------------------------------------------------------------

	//-----------------------------------------------------------------
	// 入力値確認
	static void checkInput(long[] i1) {
		StringBuilder sb = new StringBuilder();
			for(long i: i1) sb.append("[" + i + "]");
			sb.append(System.getProperty("line.separator"));
		System.out.println(sb);
	}

}


Measured memory_bytes: 47256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(void){
	ll n, x[2020];
	fill(x, x + 2020, 0);
	cin >> n;
	ll koma[n + 1];
	for(int i = 1; i <= n; i++){
		int num;
		cin >> num;
		koma[i] = num;
		x[num] = 1;
	}
	ll m;
	cin >> m;
	for(int i = 0; i < m; i++){
		int num;
		cin >> num;
		if(x[koma[num] + 1] == 0 && koma[num] != 2019){
			x[koma[num] + 1] = 1;
			x[koma[num]] = 0;
			koma[num]++;
		}
	}
	for(int i = 1; i <= n; i++) cout << koma[i] << endl;
	return 0;
}


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

int main() {
  string C ;
  cin >> C ;
  
  if(C == "a"){
    cout << "b" << endl;
  }
  if(C == "b"){
    cout << "c" << endl;
  } 
  if(C == "c"){
    cout << "d" << endl;
  } 
  if(C == "d"){
    cout << "e" << endl;
  } 
  if(C == "e"){
    cout << "f" << endl;
  } 
  if(C == "f"){
    cout << "g" << endl;
  } 
  if(C == "g"){
    cout << "h" << endl;
  } 
  if(C == "h"){
    cout << "i" << endl;
  } 
  if(C == "i"){
    cout << "j" << endl;
  }
  if(C == "j"){
    cout << "k" << endl;
  }
  if(C == "k"){
    cout << "l" << endl;
  }
  if(C == "l"){
    cout << "m" << endl;
  }
  if(C == "m"){
    cout << "n" << endl;
  }
  if(C == "n"){
    cout << "o" << endl;
  }
  if(C == "o"){
    cout << "p" << endl;
  }
  if(C == "p"){
    cout << "q" << endl;
  }
  if(C == "q"){
    cout << "r" << endl;
  }
  if(C == "r"){
    cout << "s" << endl;
  }
  if(C == "s"){
    cout << "t" << endl;
  }
  if(C == "t"){
    cout << "u" << endl;
  }
  if(C == "u"){
    cout << "v" << endl;
  }
  if(C == "v"){
    cout << "w" << endl;
  }
  if(C == "w"){
    cout << "x" << endl;
  }
  if(C == "x"){
    cout << "y" << endl;
  }
  if(C == "y"){
    cout << "z" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;


void solve()
{
    int n;
    cin>>n;
    int arr[n+1];
    memset(arr, 0, sizeof(arr));
    for(int i=1;i<=n;i++)
    {
        int cur=i;
        while(cur<=n)
        {
            arr[cur]++;
            cur+=i;
        }
    }
    // for(int i=1;i<=n;i++)
    //     cout<<arr[i]<<" ";
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        cnt+=i*arr[i];
    }
    cout<<cnt<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 81760
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    auto h = vector<int>(n);
    for (auto &h_i : h)
        cin >> h_i;

    sort(h.begin(), h.end(), less<int>());
    for (auto &c : h)
        cerr << c << " ";

    h.resize(max(0, n - k));
    auto sum = accumulate(h.begin(), h.end(), 0LL);

    cout << sum;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
int n,m;
int a[N],ans1,ans2,tmp;
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; ++i)
        scanf("%d",&a[i]);
    sort(a,a+n);
    ans1 = a[n-1];
    m = -1;
    for (int i = 0; i < n- 1; ++i){
        tmp = min(a[i], ans1 - a[i]);
        if (tmp > m) m = tmp, ans2 = a[i];
    } 
    printf("%d %d\n",ans1,ans2);

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <array>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
    array<pair<int, int> const, 4> const p[7] ={
        {{{0,0}, {1,0}, {0,1}, {1,1}}},
        {{{0,0}, {0,1}, {0,2}, {0,3}}},
        {{{0,0}, {1,0}, {2,0}, {3,0}}},
        {{{0,0}, {-1,1}, {0,1}, {-1,2}}},
        {{{0,0}, {1,0}, {1,1}, {2,1}}},
        {{{0,0}, {0,1}, {1,1}, {1,2}}},
        {{{0,0}, {1,0}, {-1,1}, {0,1}}},
    };

    string e;
    do {
        bool b[20][20] = {};
        int fx = -1, fy = -1;
        for( int y=4; y<8+4; ++y ) {
            for( int x=4; x<8+4; ++x ) {
                char c;
                cin >> c;
                b[x][y] = c == '1';
                if ( b[x][y] && fx == -1 && fy == -1) {
                    fx = x;
                    fy = y;
                }
            }
        }

        for( int i=0; i<7; ++i ) {
            if ( b[fx+p[i][0].first][fy+p[i][0].second]
                 && b[fx+p[i][1].first][fy+p[i][1].second]
                 && b[fx+p[i][2].first][fy+p[i][2].second]
                 && b[fx+p[i][3].first][fy+p[i][3].second]
                ) {
                cout << static_cast<char>( 'A' + i ) << endl;
                break;
            }
        }

    } while( getline( cin, e ) );
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n;
ll a[16][16];
ll dp[(1 << 16)];

ll rec(ll s) {
	if (dp[s] != -LLINF)
		return dp[s];

	for (ll t = s; t >= 1; t = (t - 1) & s) {
		if (t == s) {
			ll sum = 0;
			REP(i, n) {
				for (ll j = i + 1; j < n; j++) {
					if ((t >> i) & 1 && (t >> j) & 1)
						sum += a[i][j];
				}
			}

			dp[s] = sum;
		}
		else
			dp[s] = max(dp[s], rec(t) + rec(s ^ t));
	}



}

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

	cin >> n;
	REP(i, n)REP(j, n)cin >> a[i][j];
	REP(i, (1 << 16))dp[i] = -LLINF;
	dp[0] = 0;

	ll s = (1 << n);
	rec(s-1);

	cout << dp[s - 1] << endl;

}




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

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 200003;
int a[N_MAX];
int gcd(int x, int y) {
  return y == 0 ? x : gcd(y, x % y);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  bool round = 0;
  while (1) {
    round ^= 1;
    int cntO = 0;
    bool flag = 0;
    for (int i = 1; i <= n; ++i)
      cntO += a[i] & 1, flag |= a[i] == 1;
    if (cntO > 1 || flag) {
      cout << (((n - cntO) & 1) == round ? "First" : "Second") << '\n';
      return 0;
    }
    else {
      for (int i = 1; i <= n; ++i)
        if ((a[i] & 1) == 1) {
          --a[i];
          break;
        }
      int g = 0;
      for (int i = 1; i <= n; ++i)
        g = gcd(a[i], g);
      for (int i = 1; i <= n; ++i)
        a[i] /= g;
    }
  }
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
string s;
 
int getarea(int a,int b){
  int res=0,h=0;
  stack<P> st;
  for(int i=a;i<=b;i++){
    if(s[i]=='\\')st.push(P(h,i)),h--;
    if(s[i]=='/'){
      h++;
      if(!st.size())continue;
      P t=st.top();
      if(t.first==h)res+=i-t.second,st.pop();
    }
  }
  return res;
}
 
int check(int x){
  int h=0;
  for(int i=x;i<s.size();i++){
    if(s[i]=='\\')h--;
    if(s[i]=='/'){
      h++;
      if(!h)return i;
    }
  }
  return -1;
}
 
int main(){
  int h=0,ans=0;
  vector<int> v;
  cin>>s;
  for(int i=0;i<s.size();i++)
    if(s[i]=='\\'){
      int r=check(i);
      if(r>=0){
    int area=getarea(i,r);
    v.push_back(area);
    ans+=area,i=r-1;
      }
    }
  cout<<ans<<endl;
  cout<<v.size();
  if(v.size())cout<<' ';
  for(int i=0;i<v.size();i++){
    if(i)cout<<' ';
    cout<<v[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3232
import itertools

H,W,M=[int(i) for i in input().split(" ")]

target=[]
for i in range(M):
    target.append(tuple([int(j)-1 for j in input().split(" ")]))

target=set(target)

tate=[0 for i in range(H)]
yoko=[0 for i in range(W)]
for t in target:
    tate[t[0]]+=1
    yoko[t[1]]+=1



tate_max=max(tate)
yoko_max=max(yoko)

tate_max_ind=[]
for i,t in enumerate(tate):
    if t==tate_max:
        tate_max_ind.append(i)

yoko_max_ind=[]
for i,y in enumerate(yoko):
    if y==yoko_max:
        yoko_max_ind.append(i)

for iter in itertools.product(tate_max_ind,yoko_max_ind):
    if (iter in target)==False:
        print(tate_max+yoko_max)
        break

else:
    print(tate_max+yoko_max-1)


Measured memory_bytes: 218316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, long[] A)
        {
            long min = long.MaxValue;
            long max = 0;
            long[] mins = new long[N - 1];
            long[] maxs = new long[N - 1];
            for (int i = 0; i < N - 1; ++i)
            {
                int j = N - 1 - i;
                min = Math.Min(A[i], min);
                max = Math.Max(A[j], max);
                mins[i] = min;
                maxs[j - 1] = max;
            }
            var dict = new Dictionary<long, int>();
            foreach (long a in A)
            {
                if (!dict.ContainsKey(a)) { dict[a] = 0; }
                ++dict[a];
            }
            var range = Enumerable.Range(0, N - 1).Max(i => maxs[i] - mins[i]);
            var tuples = new HashSet<Tuple<long, long>>();
            for (int i = 0; i < N - 1; ++i)
            {
                if (maxs[i] - mins[i] == range) { tuples.Add(new Tuple<long, long>(mins[i], maxs[i])); }
            }
            int count = 0;
            foreach (var tuple in tuples)
            {
                count += Math.Min(dict[tuple.Item1], dict[tuple.Item2]);
            }
            return count;
        }
        static void Main(string[] args)
        {
            int[] v = ReadInts();
            long[] A = ReadLongs();
            Console.WriteLine(Solve(v[0], A));
        }
    }
}


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


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

  int w,r,n;
  cin >> n;
  string s;
  cin >> s;
  r=w=0;
  rep(i,s.size()){
    if(s[i]=='R') r++;
  }
  int ans = n;
  rep(i,s.size()){
    ans = min(ans, max(r,w));
    if(s[i]=='W') w++;
    else r--;
    // cout << ans << endl;
  }
  ans = min(ans, max(r,w));
  cout << ans << endl;
  
  return 0;
    

}


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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  int n,m;
  cin >> n >> m;
  string s; cn(s)
  vector<int> ans;
  int pos = n;
  bool sw = true;
  while(true){
    bool sw = true;
    for( int i=m; 0<i; --i ){
      if (i<=n&&s[n-i]=='0'){
        ans.push_back(i);
        n -= i;
        sw = false;
        break;
      }
    }
    if (n==0)break;
    if (sw){
      puts("-1");
      return 0;
    }
  }
  rep(i,ans.size()){
    cout << ans[ans.size()-i-1] << " ";
  }
  cout << endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct BIT{
    // [1,n]
    int n; vector<ll> bit;
    // 初期化
    BIT(int _n){
        n = _n;
        bit = vector<ll>(n+1,0);
    }
    // sum of [1,i]
    ll sum(int i){
        ll s = 0;
        while(i>0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // add x in i-th element
    void add(int i, ll x){
        while(i<=n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

typedef pair<int,int> pi;
vector<pi> range[101010];

int main()
{
    int N,M;
    scanf(" %d %d", &N, &M);
    rep(i,N)
    {
        int l,r;
        scanf(" %d %d", &l, &r);
        range[r-l+1].pb(pi(l,r));
    }

    BIT bit(M+1);
    int up_d=N;
    for(int d=1; d<=M; ++d)
    {
        for(pi p:range[d])
        {
            bit.add(p.fi,1);
            bit.add(p.se+1,-1);
            --up_d;
        }

        int ct=0;
        for(int i=d; i<=M; i+=d) ct+=bit.sum(i);

        printf("%d\n", up_d + ct);
    }
    return 0;
}

Measured memory_bytes: 8448
N = int(input())
abc = [list(map(int, input().split(' '))) for i in range(N)]
# これまでの幸福度の最大，但し前回でそれぞれa,b,cをchoice
max_value = [abc[0][0], abc[0][1], abc[0][2]]


for i in range(1, N):
    next_max_value = [0, 0, 0]
    for j in range(3):
        value = max(max_value[(j+1) % 3], max_value[(j+2) % 3])
        next_max_value[j] = value + abc[i][j]
    max_value = next_max_value
print(max(max_value))


Measured memory_bytes: 30580