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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int par[100000];
int mark[100000];
int uf[100000];
int root(int x){
  if(uf[x] == x) return x;
  return uf[x] = root(uf[x]);
}
int main(){
  int N, Q;
  while(cin>>N>>Q && N){
    par[0] = 0;
    uf[0] = 0;
    mark[0] = 1;
    REP(i, N - 1){
      cin>>par[i + 1];
      par[i + 1]--;
      uf[i + 1] = par[i + 1];
    }
    memset(mark, 0, sizeof(mark));
    char c[100000];
    int v[100000];
    REP(i, Q){
      cin>>c[i]>>v[i];
      v[i]--;
      if(c[i] == 'M'){
        mark[v[i]]++;
      }
    }
    REP(i, N) if(mark[i] > 0){
      uf[i] = i;
    }
    ll ans = 0;
    for(int i = Q - 1; i >= 0; i--){
      if(c[i] == 'M'){
        mark[v[i]]--;
        if(mark[v[i]] == 0){
          uf[v[i]] = par[v[i]];
        }
      }else{
        ans += root(v[i]) + 1;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 2968
#include<stdio.h>
int main(){
  long long int N,h,n,w;
  scanf("%lld",&N);
  for (h=1;h<=3500;h++){
    for (n=1;n<=3500;n++){
      if(4*h*n-N*(n+h)>0 && (N*h*n)%(4*h*n-N*(n+h))==0){
          w=(N*h*n)/(4*h*n-N*(n+h));
          printf("%lld %lld %lld",n,h,w);
          return 0;
        }
      }
    }
}

Measured memory_bytes: 128
from sys import stdin, stdout

s = stdin.readline().strip('\n')
al = [True for i in range(26)]
for i in s:
  al[ord(i) - 97] = False
for i in range(97, 123):
  if al[i - 97]:
    stdout.write(str(chr(i)) + '\n')
    break
else:
  stdout.write('None\n')


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < (n / 2); i++) {
        if (s[i] != s[n - i - 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
const double EPS = 1e-6;

char base36(int n)
{
	if (n >= 10) return 'A'+(n-10);
	return '0'+n;
}

int main()
{
	int N, M, Q;
	while (cin>>N>>M>>Q, N) {
		bool no[50][1000] = {};
		bool swc[50] = {};
		
		rep(i, Q) {
			string S, B;
			cin>>S>>B;
			
			for (int i=0; i<N; i++) {
				swc[i] ^= (S[i]-'0');
			}
			
			for (int i=0; i<N; i++) {
				for (int j=0; j<M; j++) {
					if (swc[i] != B[j]-'0') {
						no[i][j] = true;
					}
				}
			}
		}
		
		for (int b=0; b<M; b++) {
			int can = -1;
			for (int s=0; s<N; s++) {
				if (!no[s][b]) {
					if (can >= 0) {
						can = -2;
					} else if (can == -1) {
						can = s;
					}
				}
			}
			if (can >= 0) {
				cout << base36(can);
			} else {
				cout << '?';
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, P> T;

const ll mod = 1000000007;
const ll INF = 1000000100;

ll N;
ll a[100010];
vector<ll> vec;

ll bit[200100];

ll ans;

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

ll sum_bit(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add_bit(ll i, ll x)
{
	while (i <= 2 * N + 10)
	{
		bit[i] += x;
		i += i & -i;
	}
}

void init()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		vec.push_back(a[i]);
	}
}

void output()
{
	cout << ans << endl;
}

bool kiwosorasetai(ll median)
{
	ll sum[100010];
	ll cnt = 0;
	for (int i = 0; i <= N; i++)
	{
		sum[i] = 0;
	}
	for (int i = 0; i < 200010; i++)
	{
		bit[i] = 0;
	}
	for (int i = 0; i < N; i++)
	{
		if (a[i] < median)
		{
			sum[i + 1] = sum[i] - 1;
		}
		else
		{
			sum[i + 1] = sum[i] + 1;
		}
	}
	for (int i = 0; i <= N; i++)
	{
		cnt += sum_bit(sum[i] + N + 2);
		add_bit(sum[i] + N + 2, 1);
	}
	
	return cnt * 2 >= (N + 1) * N / 2;
}

void solve()
{
	sort(vec.begin(), vec.end());
	
	ll lb = -1, ub = vec.size();
	while (lb + 1 < ub)
	{
		ll mid = (lb + ub) / 2;
		if (kiwosorasetai(vec[mid]))
		{
			lb = mid;
		}
		else
		{
			ub = mid;
		}
	}
	
	ans = vec[lb];
}

int main()
{
	init();

	solve();

	/*ll N, A[20], x[20][20], y[20][20];
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
		for (int j = 1; j <= A[i]; j++)
		{
			cin >> x[i][j] >> y[i][j];
		}
	}

	for (int i = 0; i < 1 << N; i++)
	{
		bool judge = true;
		ll cnt = 0;
		for (int j = 1; j <= N; j++)
		{
			if (i & 1 << (j - 1))
			{
				cnt++;
				for (int k = 1; k <= A[j]; k++)
				{
					if ((1 << (x[j][k] - 1) & i) > 0 && y[j][k] == 0)
					{
						judge = false;
					}
					else if ((1 << (x[j][k] - 1) & i) == 0 && y[j][k] == 1)
					{
						judge = false;
					}
				}
			}
		}
		if (judge)
		{
			ans = max(ans, cnt);
		}
	}

	cout << ans << endl;*/

	output();

	cin >> N;
}

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s,t;
    cin>>s>>t;

    ll l=s.length();
    ll m=t.length();

    
    ll dp[l+1][m+1];


    for(ll i=0;i<=l;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

        }
    }

   // cout<<dp[l][m]<<endl;

    ll index=dp[l][m];

    char ans[index+1];
    ans[index]='\0';

    ll i=l;
    ll j=m;
    
    // cout<<"index is"<<index;
    if(index==0){
        cout<<""; return 0;}
    // cout<<"ans is: "<<ans;

    while(i>0 && j>0 )
    {
        if(s[i-1]==t[j-1])
        {
            ans[index-1]=s[i-1];
            index--;i--;j--;

        }else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
        
        
    }

    cout<<ans;
  

}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
     
    const int m = 2019;
     
    int main() {
        string s;
        cin >> s;
        int n = s.size();
        reverse(s.begin(), s.end());
        int x = 1;
        int total = 0;
        vector<int> cnt(m);
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            cnt[total]++;
            total += (s[i] - '0')*x;
            total %= m;
            ans += cnt[total];
            x = 10*x%m;
        }
        cout << ans << endl;
     
        return 0;
    }

Measured memory_bytes: 3740
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#define MAXN 105
using namespace std;
int a[MAXN];
int k, t;
int main()
{
    cin >> k >> t;
    int sum = 0, maxNum = 0;
    for(int i = 0; i < t; i++)
    {
        cin >> a[i];
        sum += a[i];
        maxNum = max(maxNum, a[i]);
    }
    sum -= maxNum;
    if(maxNum <= sum - 1) puts("0");
    else
    {
        printf("%d\n", maxNum - sum - 1);
    }
    return 0;
}


Measured memory_bytes: 256
//Binary tree search

#include<stdio.h>
#include<stdlib.h>
#define N NULL

typedef struct node
{

  struct node *p, *l, *r;
  int w;

}*tree;

void prepare(tree *root, int w)
{
  (*root) = (tree)malloc(sizeof(struct node));
  (*root)->p = N;
  (*root)->l = N;
  (*root)->r = N;
  (*root)->w = w;
  
}

void ins(tree *root, tree imp)
{
  tree y = N;
  tree x = *root;

  while(x != N)
    {
      y = x;
      if(imp->w < x->w)
	{
	  x = x->l;
	} else {
	x = x->r;
      }
    }

  imp->p = y;


  if(y == N)
    {
      *root = imp;
    }
  else if(imp->w > y->w)
    {
      y->r = imp;
    }
  else y->l = imp;
}

void inorder(tree imp)
{
  if(imp != N)
    {
      inorder(imp->l);
      printf(" %d",imp->w);
      inorder(imp->r);
    }
}

void preorder(tree imp)
{
  if(imp != N)
    {
      printf(" %d",imp->w);
      preorder(imp->l);
      preorder(imp->r);
    }
}

void print(tree root)
{
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

int main()
{
  tree root, imp;

  root = N;

  int n,w,i;
  char arr[10];

  //input data
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf("%s",arr);

      if(arr[0] == 'i')
	{
	  scanf("%d",&w);

	  prepare(&imp,w);

	  ins(&root,imp);
	}

      if(arr[0] == 'p')
	{
	  print(root);
	}
    }

  return 0;
}




Measured memory_bytes: 25176
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

right=0
total=0
xtotal=0
ans = 0
for left in range(N):
    while (right < N and total+A[right]==xtotal^A[right]):
        total += A[right]
        xtotal ^= A[right]
        right += 1
    ans += (right - left)
    if (right==left): right +=1
    else:
        total -= A[left]
        xtotal ^= A[left]
print(ans)

Measured memory_bytes: 25704
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x >= 400 && x <= 599){
            System.out.println(8);
        } else if(x >= 600 && x <= 799){
            System.out.println(7);
        } else if(x >= 800 && x <= 999){
            System.out.println(6);
        } else if(x >= 1000 && x <= 1199){
            System.out.println(5);
        }else if(x >= 1200 && x <= 1399){
            System.out.println(4);
        }else if(x >= 1400 && x <= 1599){
            System.out.println(3);
        }else if(x >= 1600 && x <= 1799){
            System.out.println(2);
        }else if(x >= 1800 && x <= 1999){
            System.out.println(1);
        }
    }
}   

Measured memory_bytes: 35684
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<class T1, class T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template<class T1, class T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
const int MAXN = 100228;


int n;
long long x;
int b[MAXN];
int ls[MAXN], u[MAXN];
vector<pair<long long, int> > g;


long long get(int i, int ost) {
	long long val = 1LL * (b[i] - ost) * ls[i];
	if (ost >= b[i]) {
		val = -1LL * (ost - b[i]) * u[i];
	}
	return val;
}	

bool check(long long mid) {
	long long ans = 0;
	long long cnt = mid / x;
	for (int i = 0; i < cnt; i++) {
		ans += 1LL * (x - b[g[i].second]) * u[g[i].second];
	}
	long long ost = mid % x;
	long long add = 4e18;
	for (int i = cnt; i < n; i++) {
		long long val = get(g[i].second, ost);
		chkmin(add, val - 1LL * b[g[i].second] * ls[g[i].second]);
	}
	ans -= add;
	for (int i = cnt; i < n; i++) {
		ans -= 1LL * b[g[i].second] * ls[g[i].second];
	}
	long long res = ans;
	ans = 0;
	add = 4e18;
	for (int i = 0; i <= cnt; i++) {
		ans += 1LL * (x - b[g[i].second]) * u[g[i].second];
		long long val = get(g[i].second, ost);
		chkmin(add, val + 1LL * (x - b[g[i].second]) * u[g[i].second]);
	}
	ans -= add;
	for (int i = cnt + 1; i < n; i++) {
		ans -= 1LL * b[g[i].second] * ls[g[i].second];
	}
	chkmax(res, ans);
	return res >= 0;
	//score[i] * (cnt - b[i]);
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read("input");
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> b[i] >> ls[i] >> u[i];
	}
	for (int i = 0; i < n; i++) {
		g.pb({1LL * (x - b[i]) * u[i] + 1LL * b[i] * ls[i], i});
	}
	sort(all(g));
	reverse(all(g));
	long long l = 0;
	long long r = 1LL * x * n;
	while (l < r) {
		long long mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

struct Coin {
    int a, b, c;

    bool operator<(const Coin& right) {
        return b-a < right.b - right.a;
    }
};

typedef long long ll;
typedef vector<Coin> coins;
typedef pair<int,int> ii;
#define REP(i,n) for (int i = 0; i < n; ++i)

const int MAX = 1e5+10;
int X, Y, Z;
coins cs;
ll resultX[MAX], resultY[MAX];

int main() {
    cin >> X >> Y >> Z;
    REP (i, X+Y+Z) {
        Coin c;
        cin >> c.a >> c.b >> c.c;
        cs.push_back(c);
    }
    sort(cs.begin(), cs.end());

    priority_queue<ii> q;
    ll XX = 0, YY = 0, ZZ = 0;
    REP (i, X) {
        q.push(make_pair(cs[i].c-cs[i].a, i));
        XX += cs[i].a;
    }
    resultX[0] = XX;
    REP (z, Z) {
        int i = z+X;
        q.push(make_pair(cs[i].c-cs[i].a, i));
        XX += cs[i].a;
        ii t = q.top(); q.pop();
        Coin c = cs[t.second];
        XX -= c.a;
        ZZ += c.c;
        resultX[z+1] = XX + ZZ;
    }

    q = priority_queue<ii>();
    YY = 0, ZZ = 0;
    REP (i, Y) {
        int j = X+Z+i;
        q.push(make_pair(cs[j].c-cs[j].b, j));
        YY += cs[j].b;
    }
    resultY[Z] = YY;
    REP (z, Z) {
        int j = X+Z-z-1;
        q.push(make_pair(cs[j].c-cs[j].b, j));
        YY += cs[j].b;
        ii t = q.top(); q.pop();
        Coin c = cs[t.second];
        YY -= c.b;
        ZZ += c.c;
        resultY[Z-z-1] = YY + ZZ;
    }
    ll ans = 0;
    REP (z, Z+1)
        ans = max(ans, resultX[z] + resultY[z]);
    cout << ans << endl;
}

Measured memory_bytes: 3444
import Data.List

main = do
  n <- readLn
  xss <- mapM (const $ fmap (map read . words) getLine) [1..n]
  print (solve xss)

solve :: [[Int]] -> Int
solve xss =
  if as==bs then 0 else sum bs - foldr f (10^9) xss
  where
    [as,bs] = transpose xss
    f [a,b] c | a > b     = min c b
              | otherwise = c

Measured memory_bytes: 38268
#include <stdio.h>

int main(){
    int h,n;
    scanf("%d%d", &h, &n);
    int a[n],i,p=0;
    for( i = 0; i < n; i++ ){
        scanf("%d", &a[i]);
        p += a[i];
    }
    if( p < h ) printf("No\n");
    else printf("Yes\n");

    return 0;
}



Measured memory_bytes: 512
n,k=map(int, input().split())
s=input()

ruiwa = [0]

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        ruiwa.append(i)
ruiwa.append(n)

if s[0] == "1":
    ans = ruiwa[1]
    if ((len(ruiwa) - 1) // 2) <= k:
        ans = n
    else:
        for i in range(((len(ruiwa)-1)//2)-k+1):
            ans = max(ans,ruiwa[min(2*k+1+2*i,len(ruiwa)-1)] - ruiwa[2*i])
else:
    ans = 0
    if len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 <= k:
        ans = n
    else:
        for i in range(len(ruiwa) - 1 - (len(ruiwa)-1)//2 - k + 1):
            ans = max(ans, ruiwa[min(2*k+2*i, len(ruiwa)-1)] - ruiwa[max(0,2*i-1)])

print(ans)

Measured memory_bytes: 7112
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>h;
vector<int>f;
int main()
{
	int n;
	cin>>n;
	h.push_back(0);
	f.push_back(1);
	for(int i=1;i<=n;i++)
	   {
	   	int t;
	   	scanf("%d",&t);
	   	h.push_back(t);
	   	f.push_back(1);
	   }
	   
	int result=1,pos=n;   
	for(int i=n;i>1;i--)
	   {
	   	 if(h[i-1]>=h[i])
	       f[i-1]=f[i]+1;
	       
	     if(result<f[i-1])
	       result=f[i-1],pos=i-1;
	   }
	cout<<result-1;
	return 0;
}

Measured memory_bytes: 1276
#include<complex>
#include<vector>
#include<cmath>
using namespace std;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};
typedef vector<P> G;
double area2(const G& P) {
  double A = 0;
  for (int i = 0; i < P.size(); ++i) 
    A += cross(curr(P, i), next(P, i));
  return A;
}

int main(){
	int n,k=1; double x,y;
	while(scanf("%d",&n),n){
		G g;
		for(int i=0;i<n;i++)scanf("%lf %lf",&x,&y),g.push_back(P(x,y));
		printf("%d %.1f\n",k++,abs(area2(g)/2));
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

ll solve(ll h){
    if (h==0) return 0;
    if (h==1) return 1;
    return solve(h/2)*2+1;
}
int main() {
    READ(1);
    ll h;cin>>h;
    cout << solve(h);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b;
    cin >> a >> b;
    vector<vector<char>> ans(100, vector<char>(100));
    rep(y, 100) {
        rep(x, 100) {
            if (x < 50) ans[y][x] = '.';
            else ans[y][x] = '#';
        }
    }
    a--; b--;
    ll cx = 51, cy = 1;
    while(a > 0) {
        ans[cy][cx] = '.';
        if (cx == 97) {
            cx = 49;
            cy += 2;
        }
        cx += 2;
        a--;
    }
    cx = 1, cy = 1;
    while(b > 0) {
        ans[cy][cx] = '#';
        if (cx == 47) {
            cx = -1;
            cy += 2;
        }
        cx += 2;
        b--;
    }
    printf("100 100\n");
    rep(y, 100) {
        rep(x, 100) {
            printf("%c", ans[y][x]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n,k;
    cin>>n>>k;
    if(n%k==0){
        cout<<"0"<<endl;
    }else{
        cout<<"1"<<endl;
    }

    return 0;
}


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

const int NMAX = 100010;
vector <int> adia[NMAX];
int h[NMAX];
vector <int> fii[NMAX];
vector <pair <int, int>> ans;
bool ok = 1;

void dfs(int nod)
{
	vector <int> sus;
	for (auto i : adia[nod]) {
		if (!h[i]) {
			h[i] = 1 + h[nod];
			dfs(i);
		}
		if (h[i] < h[nod])
			sus.push_back(i);
	}
	while (fii[nod].size() >= 2) {
		int a = fii[nod].back();
		fii[nod].pop_back();
		int b = fii[nod].back();
		fii[nod].pop_back();
		ans.push_back({ nod, a });
		ans.push_back({ nod, b });
	}
	
	if (!fii[nod].empty()) {
		if (sus.empty()) {
			ok = 0;
			return;
		}
		int a = fii[nod][0];
		int b = sus.back();
		sus.pop_back();
		ans.push_back({ nod, a });
		ans.push_back({ nod, b });
	}
	
	for (auto i : sus)
		fii[i].push_back(nod);
}

int main()
{
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	
	while (m--) {
		scanf("%d%d", &a, &b);
		adia[a].push_back(b);
		adia[b].push_back(a);
	}
	
	h[1] = 1;
	dfs(1);
	
	if (!ok) {
		cout << "-1\n";
		return 0;
	}
	
	for (auto i : ans)
		cout << i.first << ' ' << i.second << '\n';
	
	return 0;
}


Measured memory_bytes: 21364
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
const int M=12;
const int INF=1e9;
int h,w,k;
int pre[M][N];
inline int calc(int x11,int y11,int x22,int y22) {
	return pre[x22][y22]-pre[x11-1][y22]-pre[x22][y11-1]+pre[x11-1][y11-1];
}
int check(int i,int left,int j) {
	int cnt=0,i1;
	for (i1=0;i1<h;i1++) {
		cnt+=calc(i1+1,left,i1+1,j);
		if (cnt>k) return 0;
		if ((i>>i1)&1==1) cnt=0;
	}
	return 1;
}
int main() {
	int left,flag,i,j,ans,cnt;
	string s;
	cin>>h>>w>>k;
	for (i=1;i<=h;i++) {
		cin>>s;
		for (j=1;j<=w;j++)
			pre[i][j]=s[j-1]-'0'+pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
	}
	ans=INF;
	for (i=0;i<(1<<(h-1));i++) {
		cnt=0;
		for (j=0;j<h-1;j++)
			if ((i>>j)&1==1) cnt++;
		left=1; flag=1; j=1;
		while (j<=w) {
			while (j<=w&&check(i,left,j)) j++;
			if (j>w) break;
			if (j==left) {
				flag=0; break;
			}
			cnt++; if (cnt>ans) break;
			left=j;
		}
		if (flag&&cnt<ans) ans=cnt;
//		cout<<i<<' '<<cnt<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String S=sc.next();
        int[]a=new int[3];
        for(int i=0;i<3;i++){
            a[i]=0;
        }
        for(int i=0;i<3;i++){
            if(S.charAt(i)=='a'){
                a[0]++;
            }
            if(S.charAt(i)=='b'){
                a[1]++;
            }
            if(S.charAt(i)=='c'){
                a[2]++;
            }

        }
        if((a[0]>0)&&(a[1]>0)&&(a[2]>0)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
        }
        
        
    }


Measured memory_bytes: 23764
#include <stdio.h>

int main(){
    int W ,H ,x ,y ,r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if(x+r <= W&&x-r >= 0&&y+r <= H&&y-r >=0 ){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string a,b;
	cin >> a >> b;
	a+=b;
	int n = atoi(a.c_str());
	if (floor(sqrt(n)) == n/floor(sqrt(n))){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int h,w,a,b; scanf("%d%d%d%d",&h,&w,&a,&b);
    int x[1010][1010]={};
    rep(i,0,b)rep(j,0,a)x[i][j]=1;
    rep(i,b,h)rep(j,a,w)x[i][j]=1;
    rep(i,0,h){
        rep(j,0,w)printf("%d",x[i][j]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 5248
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

# ポイントの初期値
P = [K - Q] * N
# 正解した人のポイントを1増やす
for i in range(Q):
    P[A[i] - 1] += 1

for i in range(N):
    if P[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10448
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn solve(r: i32, g: i32, b: i32) -> String{
    let num = r*100+g*10+b;
    if num%4 == 0 {
        "YES".to_string()
    }else{
        "NO".to_string()
    }
}

fn main() {
    let s = getline();
    let inp: Vec<_> = s.trim().split(' ').collect();
    let r: i32 = inp[0].parse().unwrap();
    let g: i32 = inp[1].parse().unwrap();
    let b: i32 = inp[2].parse().unwrap();
    println!("{}",solve(r,g,b));
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int n;
	cin >> n;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <functional>

using namespace std;

void topological_sort(vector<vector<int>> G, vector<int>& ans) {
    vector<bool> seen(G.size());

    function<void(int)> visit;
    visit = [&](auto key) {
        if (seen[key])
            return;
        seen[key] = true;
        for (auto x : G[key]) {
            if (seen[x]) {
                continue;
            }
            visit(x);
        }
        ans.push_back(key);
    };

    for (int i = 0; i < G.size(); ++i) {
        visit(i);
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for (int i = 0; i < E; ++i) {
        int s, t;
        cin >> s >> t;
        G[t].push_back(s);
    }

    vector<int> ans;
    topological_sort(G, ans);
    for (auto x : ans) {
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 3992
N, M, X, Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

x_max = max(x)
y_min = min(y)

def check_war():
    for z in range(X+1, Y+1):
        if x_max < z and z <= y_min:
            return 'No War'
    return 'War'

print(check_war())

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
// #define mp make_pair
// #define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define show(x) cout << #x << " = " << x << endl;

int memo[301];

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

}


int main(){
  ll n, m;
  cin >> n;
  ll a, sum=0;
  vll va;
  REP(i,n-1){
    cin >> a;
    sum += a;
    va.push_back(sum);
  }
  cin >> a;
  sum += a;
  SORT(va);
  ll low, llow;
  low = *lower_bound(ALL(va),sum/2);
  if(lower_bound(ALL(va),sum/2) == va.begin()){
    llow = INFll;
  }else llow = *(lower_bound(ALL(va),sum/2)-1);
  cout <<min(abs(sum-low-low),abs(sum-llow-llow)) << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,D,X;cin>>N>>D>>X;
  int sum=X;
  REP(i,N){
    int a;cin>>a;
    sum += (D-1) / a;
    // P(asum);
  }
  P(sum+N);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    int sum = b[0];
    rep(i,n){
      	if(i != n-2 && b[i] >= b[i+1]) sum += b[i+1];
        else sum += b[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var cnt = new long[N];
            var Ai = Sarray();
            foreach (var a in Ai)
                ++cnt[a - 1];
            Array.Sort(cnt);
            var i = 0;
            for (i = 0; cnt[i] == 0; ++i) ;
            var ans = 0L;
            for (var j = i; j < N - K; ++j)
                ans += cnt[j];
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 37468
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int ans;
int nn;
int a,b;
vector<int> hai[10000];
int main()
{
    cin>>n;
    for(int m=2;m<100000;m++)
    {
        if(m*(m-1)==2*n)
        {
            nn=m;
            break;
        }
        if(m*(m-1)>2*n)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    a=0;b=1;
    for(int i=1;i<=n;i++)
    {
        hai[a].push_back(i);
        hai[b].push_back(i);
        if(b!=nn-1)
        {
            b++;
        }
        else{
            a++;
            b=a+1;
        }
    }
    cout<<"Yes"<<endl;
    cout<<nn<<endl;
    rep(i,nn)
    {
        cout<<nn-1;
        rep(j,hai[i].size())
        {
            cout<<" "<<hai[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T,typename U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int largest_rectangle(vector<int>& A){
    int N = A.size()-1;
    int ans = 0;
    stack<P<int,int>> s;
    for(int i=0;i<=N;i++){
        int pos = i;
        while(!s.empty() && s.top().first>=A[i]){
            P<int,int> p = s.top(); s.pop();
            ans = max(ans,p.first*(i-p.second+(i!=N)));
            pos = p.second;
        }
        s.push({A[i],pos});
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vvec<char> S(H,vec<char>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin >> S[i][j];

    auto check = [&](int i,int j){
        if(i==H-1 || j==W-1) return true;
        int c = 0;
        for(int k=i;k<i+2;k++) for(int l=j;l<j+2;l++) c += (S[k][l]=='#');
        return (c==0 || c==2 || c==4);
    };

    int ans = 0;
    vvec<int> level(H,vec<int>(W,0));
    for(int i=0;i<H;i++){
        vec<int> hist(W+1,0);
        for(int j=0;j<W;j++){
            if(i==0){
                level[i][j] = 1;
                hist[j] = 1;
                continue;
            }
            level[i][j] = ((j==W-1 || check(i-1,j))? level[i-1][j]+1:1);
            hist[j] = level[i][j];
        }
        hist[W] = 0;
        ans = max(ans,largest_rectangle(hist));
    }
    cout << ans << endl;
}

Measured memory_bytes: 19968
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = [None] * (10 ** 5 * 2 + 1)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx == gy is not None:
            continue
        elif gx is not None is not gy:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        nx = sum(xy > 0 for xy in xys)
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print(main())

Measured memory_bytes: 105436
N = int(input())
ans = [0]*(N)
 
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      a = (x+y+z)**2 - (x*y + y*z + z*x)
      if a <= N:
      	ans[a-1] += 1
 
for x in ans:
  print(x)

Measured memory_bytes: 74556
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int h, w; cin >> h >> w;

    vector<vector<char>> g(h, vector<char> (w));
    queue<P> q;

    rep(i,h){
        rep(j,w){
            cin >> g[i][j];
            if(g[i][j] == '.') q.push(P(i,j));
        }
    }

    int dh[] = {1,0,-1,0,1,-1,-1,1};
    int dw[] = {0,1,0,-1,1,1,-1,-1};

    while(!q.empty()){
        P p = q.front(); q.pop();
        int ans = 0;
        rep(i,8){
            int nh = p.first + dh[i], nw = p.second + dw[i];
            if(nh <= -1 || nh >= h || nw <= -1 || nw >= w) continue;
            if(g[nh][nw] == '#') ans++;
        }
        g[p.first][p.second] = ans + '0';
    }

    rep(i,h){
        rep(j,w){
            cout << g[i][j];
        }
        cout << endl;
    }
}


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

int main() {
  int k,s;
  cin >> k >> s;
  
  int x,y,z,cnt=0;
  for(x=0; x<=k; x++){
    for(y=0; y<=k; y++){
      z = s - x -y;
      if(z>=0 && z<=k) cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[1100][1<<12];
int rev[1100][1<<12];
int c[1500];
int out[1500];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%d",c+i);
		for(int i=0;i<=a;i++)for(int j=0;j<(1<<b);j++)
			dp[i][j]=0;
		for(int i=0;i<(1<<b);i++){
			if(__builtin_popcount(i)==c[0]){
				dp[1][i]=1;
			}
		}
		for(int i=1;i<a;i++){
			for(int j=0;j<(1<<b);j++){
				if(!dp[i][j])continue;
				int to=j/2;
				int tmp=__builtin_popcount(to);
				if(tmp<c[i]-1)continue;
				if(tmp>c[i])continue;
				if(tmp==c[i]){
					if(!dp[i+1][to]){
						dp[i+1][to]=1;
						rev[i+1][to]=j%2;
					}
				}else{
					if(!dp[i+1][to+(1<<(b-1))]){
						dp[i+1][to+(1<<(b-1))]=1;
						rev[i+1][to+(1<<(b-1))]=j%2;
					}
				}
			}
		}
		bool yet=true;
		for(int i=0;i<(1<<b);i++){
			if(dp[a][i]){
				yet=false;
				int ind=0;
				for(int j=b-1;j>=0;j--){
					if(i&(1<<j))out[ind++]=1;
					else out[ind++]=0;
				}
				int at=(i*2+rev[a][i])%(1<<b);
				for(int j=a-1;j>0;j--){
					out[ind++]=at%2;
					at=(at*2+rev[j][at])%(1<<b);
				}
				for(int j=ind-1;j>=0;j--)printf("%d",out[j]);
				printf("\n");
				break;
			}
		}
		if(yet)printf("Goofy\n");
	}
}

Measured memory_bytes: 35832
#include <iostream>
int main(int argc, char const *argv[]) {
    long long x;
    std::cin >> x;
    long long a = x / 11;
    int b = x % 11;
    if (b > 6) {
        std::cout << 2 * a + 2 << '\n';
    } else if (b == 0) {
        std::cout << 2 * a << '\n';
    } else {
        std::cout << 2 * a + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 2019
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}


int32_t main()
{
  io
int n,k;
cin>>n>>k;
int R,S,P;
cin>>R>>S>>P;
map<char,int>price;
price['r']=R;
price['s']=S;
price['p']=P;
string st;
map<char,char>tt;
tt['s']='r';
tt['p']='s';
tt['r']='p';
cin>>st;
string r={};
for(int i=0;i<st.length();i++)
{
  if(st[i]=='r')
    r+='p';
  else if(st[i]=='p')
    r+='s';
  else
  {
    r+='r';
  }
}
int nn=r.length();
 for(int i=k;i<nn;i++)
 {
    if(r[i-k]==r[i])
    {
     
      if(i+k<nn)
     { 
      if(r[i]==r[i+k])
       r[i]=st[i];
      else
       r[i]='r'+'s'+'p'-r[i-k]-r[i+k];
     }
     else
     {
       r[i]=st[i];
     }
    }
 }
 int ans=0;
 for(int i=0;i<nn;i++)
 {
  if(r[i]==tt[st[i]])
  ans+=price[r[i]];
 }
//cout<<r<<endl;
cout<<ans<<endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


template <typename T>
class RMQ {
	T query(int l, int r, int a, int b, int k){
		if( l <= a && b <= r ){
			return seg[k];
		}else if( l < b && a < r ){
			int m = (b+a)/2;
			T vl = query(l,r, a, m, k*2);
			T vr = query(l,r, m, b, k*2+1);
			return min(vl, vr);	// merge
		}
		return INF;	// default value
	}
public:
	vector<T> seg;	// セグメントツリー (親:k/2  子:k*2,k*2+1)
	int N;
	RMQ(int size){
		N = 1;
		while( N < size ) N<<=1;
		seg.assign(N*2, INF);		// default value
	}
	void update(int pos, T v){
		for(int k=N+pos; k>0; k/=2){
			seg[k] = v;
			v = min(seg[k], seg[k^1]);	// merge
		}
	}
	// [l,r)
	T get(int l, int r){
		return query(l, r, 0, N, 1);
	}
	T get(int pos){		// =get(pos, pos+1)
		return seg[N+pos];
	}
	void add(int pos, T val){
		update(pos, get(pos) + val);
	}
	void chmin(int pos, T val){
		if(get(pos) > val) update(pos, val);
	}
};


int cnt[2][500005];
int check[500005];
int main(){
	ios_base::sync_with_stdio(false);
	int N, K;
	string S, T;

	cin >> N >> K;
	cin >> S >> T;
	S += "#";
	T += "#";

	rrep(i,N) cnt[0][i] = cnt[0][i+1] + (T[i] == 'B' && T[i+1] != 'B');
	rrep(i,N) cnt[1][i] = cnt[1][i+1] + (T[i] == 'W' && T[i+1] != 'W');
	rrep(i,N) check[i] = (T[i] == 'B');

	vector<RMQ<int>> dp(2, N+2);
	rep(k,2) rep(i,N+1) dp[k].update(i, cnt[k][i]);
	rep(i,N){
		int nex = INF;
		if( S[i] == T[i] ) chmin(nex, dp[0].get(i) - cnt[0][i]);
		rep(k,2) chmin(nex, dp[k].get(max(0,i-K+1), i+1) - cnt[k][i] + (check[i]^k) + 1);
		rep(k,2) dp[k].add(i+1, nex);
	}

	int ans = INF;
	rep(k,2) chmin(ans, dp[k].get(N));

	cout << ans << endl;

	return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int n, l;
  cin >> n >> l;

  vector<string> s(n);
  rep(i, n) cin >> s[i];

  sort(all(s));

  rep(i, n) cout << s[i];
  cout << endl;

  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int y;
	cin >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n - i; j++) {
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
				cout << i << " " << j << " " << n - i - j << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

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

int n, k, A[100005];

signed main(){
  
  cin>>n>>k;
  
  for(int i=0;i<n;i++) cin>>A[i];
  
  cout<<1+(n-k)/(k-1)+((n-k)%(k-1)!=0)<<endl;
  
  return 0;
}


Measured memory_bytes: 1024
a, b = (int(i) for i in input().split())
while a != 0 and b != 0:
    cow = '#'
    for i in range(1, b):
        cow += '#'
    print('{0}'.format(cow))
    for i in range(1, a-1):
        row = '#'
        for j in range(1, b-1):
            row += '.'
        row += '#'
        print('{0}'.format(row))
    cow = '#'
    for i in range(1, b):
        cow += '#'
    print('{0}\n'.format(cow))
    a, b = (int(i) for i in input().split())

Measured memory_bytes: 7736