akhauriyash/Code-Regression huggingface dataset:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a1 = list(myinput())
a2 = list(myinput())

ans = 0
for i in range(n):
    ans1 = sum(a1[:i+1])
    ans2 = sum(a2[i:])
    ans = max( ans, ans1+ans2 )
print(ans)

Measured memory_bytes: 38640
class Heap
  def initialize(xs = [], &block)
    @que = xs
    @size = xs.size
    @cmp = block || lambda{ |a,b| a < b }
  end
 
  def push(x)
    i = @size
    while i > 0 do
      j = (i - 1) / 2
      break unless @cmp.call(x, @que[j])
      @que[i] = @que[j]
      i = j
    end
    @que[i] = x
    @size += 1
  end
 
  def replace
    m = @que[0]
    x = yield m
    i = 0
    while (ii = i * 2 + 1) < @size do
      j1 = ii
      j2 = ii + 1
      j1 = j2 if j2 < @size && @cmp.call(@que[j2], @que[j1])
      break unless @cmp.call(@que[j1], x)
      @que[i] = @que[j1]
      i = j1
    end
    @que[i] = x
    m
  end
end
 
def get_target(l, h, n, fs)
  r = 0
  fs.each do |f| r += h / f end
 
  # t0 = (l*h/r).ceil, t = (l*h/(r+n)).ceil
  lh = l * h
  t0 = (lh + r - 1) / r
  t = (lh + r + n - 1) / (r + n)
 
  raise if (t0 >= t + 2)
 
  t
end
 
n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
fs = gets.split.map(&:to_i)
 
l = as.inject(:+) - k
 
if (l <= 0)
  p 0
  exit
end
 
# O(n * log(n))
afs = as.sort.zip(fs.sort.reverse).sort_by do |item| item[0]*item[1] end
 
acc = 0
# O(n)
a_sums = afs.map do |a,_| acc += a end
 
# O(n * log(n))
m = (0...n).bsearch do |i|
  a_i, f_i = afs[i]
  af = a_i * f_i
 
  s = a_sums[i]
  (i+1...n).each do |j| s += af / afs[j][1] end
  s > l
end
 
if (m > 0)
  afs = afs.drop(m)
  n -= m
  l -= a_sums[m-1]
end
 
max_f = 0
 
# O(n)
fs = afs.map do |a, f|
  max_f = f if f > max_f
  f
end
 
# O(n)
t = get_target(l, l * max_f * max_f, n, fs)
 
max_af = 0
 
# O(n)
xs = fs.map do |f|
  l -= (a = t / f)
  af = a * f
  max_af = af if af > max_af
  [af + f, f]
end
 
if (l == 0)
  p max_af
else
  # O(n * log(n))
  xs = xs.sort_by do |item| item[0] end
  # O(n * log(n))
  q = Heap.new(xs) do |a,b| a.first < b.first end
 
  raise if (l > 2*n)
 
  # O(n * log(n))
  af, = q.replace do |a| [a[0] + a[1], a[1]] end while (l -= 1) >= 0
  p af
end

Measured memory_bytes: 60628
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <iomanip>

typedef long long ll;

 ll gcd( ll n1,  ll n2) {
    return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

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

    int n;
    cin >> n;
    vector<double> a;
    //powers of two range from 34 to -9
    //powers of five range from to -9 to 9
    long long twofives[44][19];
    for (int i = 0; i < 44; i++) {
        for (int j = 0; j < 19; j++) {
            twofives[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        int twos = 9;
        int fives = 9;
        long long num = 0;
        long long den = 1;
        long long pw = 1;
        bool decseen = false;
        for (char c : s) {
            if (c == '.') {
                decseen = true;
                continue;
            }
            num *= 10;
            num += (c - '0');
            if (decseen) {
                den *= 10;
            }
        }

        ll nm = num;
        ll dn = den;
        //cout << nm << "/" << dn << endl;
        while (nm % 2 == 0) {
            nm /= 2;
            twos++;
        }
        while (dn % 2 == 0) {
            dn /= 2;
            twos--;
        }
        while (nm % 5 == 0) {
            nm /= 5;
            fives++;
        }
        while (dn % 5 == 0) {
            dn /= 5;
            fives--;
        }
        //cout << twos - 9 << " " << fives - 9 << endl;
        twofives[twos][fives]++;
        
    }
    long long ans = 0;
    for (int x = 0; x < 44; x++) {
        for (int y = 0; y < 44; y++) {
            for (int a = 0; a < 19; a++) {
                for (int b = 0; b < 19; b++) {
                    if (x + y >= 18 && a + b >= 18) {

                        ans += twofives[x][a] * twofives[y][b];
                        if (x == y && a == b) ans -= twofives[x][a];
                    }
                }
            }
        }
    }
    cout << ans / 2 << endl;
   
   
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

int n;

void init()
{
	scanf("%d",&n);
}

void work()
{
	if(!(n&n-1))
		puts("No");
	else
	{
		puts("Yes");
		puts("1 2");puts("2 3");
		printf("3 %d\n",n+1);
		printf("%d %d\n",n+1,n+2);
		printf("%d %d\n",n+2,n+3);
		for (int i=4;i<n;i+=2)
			printf("1 %d\n1 %d\n%d %d\n%d %d\n",i,i+1,i,n+i+1,i+1,n+i);
		if(!(n&1))
		{
			for (int i=4;i<=n;i++)
			{
				int j=n^1^i;
				if(j<n&&j!=3)
				{
					printf("%d %d\n%d %d\n",i,n,j,n+n);
					break;
				}
			}
		}
	}
}

int main()
{
	init();
	work();
	return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstdio>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    char c;
    cin>>c;
    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')cout<<"vowel\n";
    else cout<<"consonant\n";
}


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

namespace B___String_Palindrome
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if (new string(S.Reverse().ToArray()) == S)
                if (new string(S.Take((S.Length - 1) / 2).Reverse().ToArray()) == new string(S.Take((S.Length - 1) / 2).ToArray()))
                {
                    Console.WriteLine("Yes");
                    return;
                }

            Console.WriteLine("No");
        }
    }
}


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

int main(){
	int n; string s;
	cin>>n>>s;
	int p = s.size();
	
	for(int i = 0; i<p; i++){
		s[i] += n;
		if(s[i] > 90) s[i] -= 26;
	}
	
	cout<<s;
	return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    int ans = a+b;
    if(ans < 10) cout << ans << endl;
    else cout << "error" << endl;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    ll p[30];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
    }
    ll result = 0;
    for (int i = 0; i < n-2; i++) {
        if( p[i+1] != max({p[i],p[i+1],p[i+2]}) && p[i+1] != min({p[i],p[i+1],p[i+2]}) ){
            result++;
        }
    }
    std::cout << result << std::endl;
}


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

int main() {
  string s,t;
  cin >> s >> t;
  int lens = s.size(), lenn = t.size(),count,ans = 1001;
  for(int i = 0;i < lens-lenn+1;i++) {
    count = 0;
    for(int j = 0;j < lenn;j++) {
      if(s[i+j] != t[j]) count++;
    }
    ans = min(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> ans(N+1, 0);
    for (int i = 0; i < N-1; i++)
    {
        int b;
        cin >> b;
        ans[b]++;
    }

    for (int i = 1; i < N+1; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define scan(a) scanf("%d",&a)
#define scan2(a,b) scanf("%d %d",&a,&b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define print(x) printf("%d\n",x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<pair<int,int> > vpii;
static const int INF = 0x3f3f3f3f;
static const ll INFL = 0x3f3f3f3f3f3f3f3fLL;


int main()
{
    int n,k;
    scan2(n,k);
    for(int i=0;i<=n;++i)
    {
        for(int j=0;j<=n;++j)
        {
            if( i+j > n)
                continue;
            int temp = 10000*i + 5000*j + (n - i-j)*1000;
            if( temp == k)
            {
                printf("%d %d %d",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

int n,m,a[1001];

ll d[201][201]={};
bool count[1001][1001]={};
vector<int> v1[1001],load[1001];
string str;
ll ans=0;
queue<int> que;
set<P> st;
int s=0;
ll hea=0;
bool c=0;
char v;
int main() {
	cin>>n;
	rep(i,0,n){
		rep(j,0,n){
			cin>>v;
			d[i][j]=v-'0';
			if(d[i][j]==0)d[i][j]=INF;
			if(i==j)d[i][j]=0;
		}
	}
	for(int k=0;k<n;k++){       // 経由する頂点
	    for(int i=0;i<n;i++){    // 始点
	      for(int j=0;j<n;j++) {  // 終点
	        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	      }
	    }
	}

	ans=-1;
	ll ma=0;
	bool f=0;
	for(int k=0;k<n;k++){
		ma=0;// 経由する頂点
		f=0;
	    for(int i=0;i<n;i++){    // 始点
	      for(int j=0;j<n;j++) {  // 終点
	        ma=max(ma,d[k][j]+1);
	        if(d[k][i]==d[k][j]&&d[i][j]==1)f=1;
	      }
	    }
	    if(!f)ans=max(ans,ma);
	}
	if(ans==-1){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) - 1);
const int MAX = 1e9;

int main() {
	int n, k;
	cin >> n >> k;
	int ar[n];
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}

	int arriba = MAX, abajo = 1;
	int sol = MAX;

	while (abajo <= arriba) {
		int mid = abajo + (arriba - abajo)/2;
		int cortes = 0;
		for (int i = 0; i < n; i++) {
			cortes += (ar[i] == mid ? 0 : ar[i]/mid);
		}
		
		if (cortes <= k) {
			arriba = mid - 1;
			sol = min(sol, mid);
		} else {
			abajo = mid + 1;
		}
	}

	cout << sol << '\n';

}


Measured memory_bytes: 4364
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    string s;
    cin >> s;
    n = s.size();
    vector<bool> c(26,false);
    REP(i,n){
        int ch = s[i]-'a';
        c[ch]=true;
    }
    REP(i,26){
        if(!c[i]){
            put((char)(i+'a'));
            return 0;
        }
    }
    put("None");
    return 0;
}


Measured memory_bytes: 512
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(i,n) for(long long i = 0;i < n;++i)
long long n, k, m;
long long dp[202][202][1 << 12];
int main() {
	cin >> n >> k >> m;
	n *= 2;
	for (int i = n - 1; n - i <= k&&i >= 1; --i) {
		dp[n][i][(1 << (n - i - 1))] = 1;
	}
	for (int i = n; i >= 2; i--) {
		for (int q = i - 1; i - q <= k&&q >= 1; --q) {
			for (int j = 0; j < (1 << k); ++j) {
				if (dp[i][q][j] == 0) continue;
				int left = -1;
				for (int t = 0;;++t) {
					if (((1 << t) & j) == 0) {
						left = t;
						break;
					}
				}
				long long next_t = j >> (left + 1);
				//now taking left
				int next_i = i - left - 1;
				if (i - next_i > k) continue;
				if (next_i <= 0) continue;
				int target = i - q - left - 1;
				for (int t = max(target,0); t < k; ++t) {
					int nya = 1 << t;
					if ((nya& next_t) == 0) {
						//can fit
						int next_q = q - (t-target) - 1;
						if (next_q <= 0) continue;
						if (q - next_q > k) continue;
						if (next_i - next_q > k) continue;
						dp[next_i][next_q][next_t + nya] += dp[i][q][j];
						dp[next_i][next_q][next_t + nya] %= m;
					}
				}
			}
		}
	}
	long long ans = 0;
	for (int i = k + 1; i >= 2; --i) {
		ans += dp[i][1][(1 << (i-1)) - 1];
		ans %= m;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11996
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

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

    for (int i = 0; i < 8; i++) {
        string exp;
        int calc = abcd[0] - '0';
        exp += abcd[0];
        for (int j = 1, k = 1; j < 8; j *= 2, k++) {
            if ((i & j) == j) {
                exp += '+';
                calc += abcd[k] - '0';
            }
            else {
                exp += '-';
                calc -= abcd[k] - '0';
            }
            exp += abcd[k];
        }
        if (calc == 7) {
            exp += "=7";
            cout << exp << endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
int main()
{
	int n;sca(n);
	if(n>=30)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long int ll;
using namespace std;

int main()
{
  int n,k;
  cin >> n >> k;
  int k2 = (n-1)*(n-2)/2;
  if(k > k2){
    cout << "-1\n";
    return 0;
  }
  
  vector<pair<int, int>> ans;
  FOR(i,1,n) ans.emplace_back(0, i);
  
  FOR(i,1,n) FOR(j,i+1,n){
    if(k2==k) break;
    ans.emplace_back(i,j);
    k2--;
  }
  cout << ans.size() << '\n';
  for(auto p: ans) cout << p.first+1 << " " << p.second+1 << '\n';
  return 0;
}

Measured memory_bytes: 384
n = int(input())
h = list(map(int, input().split()))
i = n - 1
curr_num = h[n - 1]
while i >= 0:
    if h[i] > curr_num + 1:
        print('No')
        exit()
    if h[i] < curr_num + 1:
        curr_num = h[i]
    i -= 1
print('Yes')

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

main(){
  int n, ans;
  string s, t;
  string s_cp,t_cp;

  cin >> n;
  cin >> s;
  cin >> t;
  
  ans = n * 2;
    
  for ( int i = 0; i < n ; i++) {// i = start of s , n-i-1 = end of t
    
    int cnt = 0;
    int p;
    for ( int j = i,p = 0; p < n-i ; p++,j++){
      if ( s[j] == t[p] ){
	cnt++;
      }
    }

    if( cnt == n-i ){
      ans = min(ans,(2*n)-(n-i));
    }
      
  }

  cout << ans << endl;

  return (0);
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

string int_to_string(int x){
    stringstream ss;
    ss << x;
    return ss.str();
}

vector<pair<int,string>> nv(const vector<pair<int,string>>& v,const vector<pair<int,string>>& tmp,const vector<int>& idxs,char op){
    auto x=v[idxs[0]],y=v[idxs[1]];
    pair<int,string> p;
    if(op=='+') p=make_pair(x.first+y.first,"("+x.second+" + "+y.second+")");
    else if(op=='-') p=make_pair(x.first-y.first,"("+x.second+" - "+y.second+")");
    else if(op=='*') p=make_pair(x.first*y.first,"("+x.second+" * "+y.second+")");
    auto res=tmp; res.emplace_back(p);
    return move(res);
}

string dfs(vector<pair<int,string>> v){
    if(v.size()==1){
        if(v[0].first==10) return v[0].second;
        else return "";
    }

    string res="";
    rep(b,0,1<<v.size()){
        if(__builtin_popcount(b)!=2) continue;
        vector<pair<int,string>> tmp;
        vector<int> idxs;
        rep(i,0,v.size()){
            if((1&(b>>i))==0) tmp.emplace_back(v[i]);
            else idxs.emplace_back(i);
        }

        res=max(res,dfs(nv(v,tmp,idxs,'+')));
        res=max(res,dfs(nv(v,tmp,idxs,'*')));
        res=max(res,dfs(nv(v,tmp,idxs,'-')));
        swap(idxs[0],idxs[1]);
        res=max(res,dfs(nv(v,tmp,idxs,'-')));
    }
    return res;
}

void solve(){
    int a,b,c,d;
    while(cin >> a >> b >> c >> d){
        if(a==0 and b==0 and c==0 and d==0) break;
        vector<pair<int,string>> v;
        v.emplace_back(make_pair(a,int_to_string(a)));
        v.emplace_back(make_pair(b,int_to_string(b)));
        v.emplace_back(make_pair(c,int_to_string(c)));
        v.emplace_back(make_pair(d,int_to_string(d)));
        string ans=dfs(v);

        if(ans.empty()) cout << 0 << endl;
        else cout << ans << endl;
    }
}

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

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

int main()
{ ll i, k, n, kn, val, tmp, suma, maxa;

  cin>>n>>kn;
  vl1 veka(n+1), dp(n+1);
  for(i=1;i<=n;i++) cin>>veka[i];

  dp[1]=0;

  for(i=2;i<=n;i++)
    { if(kn<i) maxa=kn; else maxa=i-1;
      suma=LLONG_MAX;
      for(k=1;k<=maxa;k++)
       { val=veka[i]-veka[i-k];
         if(val<0) val=-val;
         if(dp[i-k]+val<suma) suma = dp[i-k]+val;
       }
      dp[i]+=suma;
    }
  cout << dp[n] << endl;
  return 0;
}
/*
5 3
10 30 40 50 20
*/


Measured memory_bytes: 4700
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int X,Y,Z;

    cin >> X >> Y >> Z;

    int num = 0;

    while((Y+Z)*num <= (X-Z)){
        num++;
    }

    cout << num-1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

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

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  vl v(3); rep(i,3) cin >> v[i];

  sort(all(v));
  ll s = v[0]*v[1];
  ll divide1 = v[2]/2LL;
  ll divide2 = v[2] - divide1;
  cout << s*(divide2-divide1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (a = 0; a < b; a++)

int junban(string _str, char _c){
  
  for (int i = 0; i < _str.size(); i++){
    if (_str[i] == _c){
       return i;
    }
  }
  return -1;
}


int main(){
  
  string str = "abcdefghijklmnopqrstuvwxyz";
  int num;
  char c;
  cin >> c;
  num = junban(str, c);
  
  cout << str[num + 1] << endl;
}

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


int main(){
	int a[9],b[9];
	int t;
	cin>>t;
	while(t--){
		int m,d=0;
		string s;
		cin>>s;
		m=s.size()-1;
		for(int i=0;i<s.size();i++){
			d+=s[i]-'0';
			if(10<=d){
				d=d%10+1;
				m++;
			}
		}
		cout<<(m%2?"Fabre":"Audrey")<<" wins."<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main {
	static int N = 123459 * 2;
	static boolean[] primes = new boolean[N]; 
	public static void main(String[] args) {
		for (int i = 0; i < N; i++) {
			primes[i] = true;
		}
		primes[0] = false;
		primes[1] = false;
		for (int i = 2; i < N; i++) {
			if (primes[i]) {
				for (int j = i * 2; j < N; j += i) {
					primes[j] = false;
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		int n;
		while ((n = sc.nextInt()) != 0) {
			int cnt = 0;
			for (int i = n + 1; i <= 2 * n; i++) {
				if (primes[i]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n, x, cnt;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) return 0;
        cnt = 0;
        REP(i, n){
            for(int j = i; j < n; j++){
                for(int k = j; k < n; k++){
                    ll p = i + 1, q = j + 1, r = k + 1;
                    if(q == p || r == q || r == p) continue;
                    if(p + q + r == x) cnt++; 
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int inf = 1e8;

vector<int> dx = {1,-1,0,0}, dy = {0,0,1,-1};

signed main(){
   IOS;
   int h, w, k;
   int x1, y1, x2, y2;
   cin >> h >> w >> k;
   cin >> x1 >> y1 >> x2 >> y2;
   x1--, y1--, x2--, y2--;
   vector<string> g(h);
   for(auto &it : g) cin >> it;
   vector<vector<int> > d(h, vector<int>(w, inf));
   d[x1][y1] = 0;
   priority_queue<pair<int, pair<int,int>> > q;
   q.push(make_pair(0,make_pair(x1,y1)));
   while(!q.empty()) {
      pair<int,int> now = q.top().second; 
      int dist = -q.top().first; q.pop();
      if(dist > d[now.first][now.second]) continue;
      for(int i = 0; i < 4; i++) {
         for(int j = 1; j <= k; j++) {
            int x = now.first + dx[i] * j;
            int y = now.second + dy[i] * j;
            if(x>=0 and x<h and y>=0 and y<w) {
               if(g[x][y] == '@') break;
               if(dist + 1 > d[x][y]) break;
               if(dist + 1 < d[x][y]) {
                  d[x][y] = dist + 1;
                  q.push(make_pair(-(dist+1),make_pair(x,y)));
               }
            }
            else break;
         }
      }
   }
   cout << ((d[x2][y2] == inf) ? -1 : d[x2][y2]) << "\n";
}

Measured memory_bytes: 19824
#include<bits/stdc++.h>
using namespace std;
map<string,long long>s1;
long long n;
int main(){
	cin>>n;
	for(long long i=0;i<n;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		s1[s]++;
	}
	long long cnt=0;
	map<string,long long>::iterator it;
	for(it=s1.begin();it!=s1.end();it++){
//		cout<<(it->second-1)<<endl;
		long long ans=0;
		ans=(it->second);
		cnt=cnt+(ans*(ans-1)/2);
	}
	printf("%lld\n",cnt);
	return 0;
} 

//1 0
//2 1
//3 3
//4 6
//5 10
//n*(n-1)/2

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

int main() {
  string S;
  cin >> S;
  if(S[1] == 'B'){
    S[1] = 'R';
  }else{
    S[1] = 'B';
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 3568
# 入力
data = input().split()
 
# プレイヤ人数
player = int(data[0])
# はじめのポイント
initPoint = int(data[1])
# 質問回数
question = int(data[2])
 
# 正解しない場合のプレイヤのポイント
playerPoint = []
 
for i in range(player):
  playerPoint.append(initPoint - question)
 
# 問題解答
for i in range(question):
  # 正解者
  corrPlayer = int(input())
  # 正解者のポイントを+1(減らさない)
  playerPoint[corrPlayer -1] = playerPoint[corrPlayer -1] + 1
  
# 解答
for i in range(player):
  if playerPoint[i] <= 0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 7848
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <utility>
#include <queue>
#include <stdio.h>
#include <string>
#include <map>
#include <stack>
#include <complex>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000007
const double eps = 1e-11;
using namespace std;
typedef long long int ll;
typedef complex<double> xy;

int main(){
    double x1,y1,x2,y2,x3,y3,px,py;
    while(cin >> x1 >>y1>>x2>>y2>>x3>>y3>>px>>py){
        xy aa=xy(x1-px,y1-py),bb=xy(x2-px,y2-py),cc=xy(x3-px,y3-py);
        double a,b,c;
        a =((conj(aa)*bb).imag());
        b =((conj(bb)*cc).imag());
        c =((conj(cc)*aa).imag());
        cout << (abs(a)+abs(b)+abs(c)==abs(a+b+c) ? "YES" : "NO")<<endl;
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
using ll = 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 repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n - 1) {
    int num;
    cin >> num;
    --num;
    ++a[num];
  }
  rep(i, n) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
int dp[101010],a[25];
int n,m,kotae;
int main(){
  cin>>n>>m;
  rep(i,m)cin>>a[i];
  dp[0]=0;
  for(int i=1;i<=n;i++){
    dp[i]=i;
    rep(j,m){
      if(i-a[j]>=0){
        if(dp[i-a[j]]+1<dp[i]){
          dp[i]=dp[i-a[j]]+1;
        }
      }
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int N;
    cin >> N;
    int res = 0;
    for(int i=1; i < N; i++){
        const auto &pf = prime_factorize(N-i);
        long long tmpres = 1;
        for (auto p : pf) tmpres *= p.second + 1;
        res+=tmpres;
    }
    cout << res << "\n"; 
    return 0;
}

Measured memory_bytes: 3652
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> h(n+1,0);
	rep(i,n) std::cin >> h[i+1];

	const int INF = 1e16;
	std::vector<std::vector<std::vector<int> > > dp(n+1,std::vector<std::vector<int> >(k+1,std::vector<int>(n+1,INF)));
	dp[0][0][0]=0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<=k;j++) {
			for(int l=0;l<=i;l++) {
				if(dp[i][j][l]==INF) continue;
				dp[i+1][j][i+1] = std::min(dp[i+1][j][i+1],dp[i][j][l]+std::max(0ll,h[i+1]-h[l]));
				if(j<k) dp[i+1][j+1][l] = std::min(dp[i+1][j+1][l],dp[i][j][l]);
			}
		}
	}
	int min = INF;
	for(int j=0;j<=k;j++) {
		for(int l=0;l<=n;l++) {
			min = std::min(min,dp[n][j][l]);
		}
	}
	print(min);

	return 0;
}


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

using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<ll> h(n),p(n);
    vector<pair<ll,ll>> php(n);
    for(int i=0;i<n;i++){
        cin>>h[i]>>p[i];
        php[i]={h[i]+p[i],h[i]};
    }
    sort(php.begin(),php.end());
    for(int i=0;i<n;i++){
        h[i]=php[i].second;
        p[i]=php[i].first-php[i].second;
    }
    ll INF=1e15;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,INF));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            if(j==0){
                dp[i][j]=0;
            }
            else{
                dp[i+1][j]=dp[i][j];
                if(h[i]>=dp[i][j-1]){
                    dp[i+1][j]=min(dp[i+1][j],dp[i][j-1]+p[i]);
                }
            }
        }
    }
    int res=0;
    for(int i=0;i<=n;i++){
        if(dp[n][i]<INF){
            res=i;
        }
    }
    cout<<res<<endl;
    return 0;

}

Measured memory_bytes: 196096
n = int(input())
a = list(map(int,input().split()))

cash = 1000
stock = 0

for i in range(n-1):
    if(a[i] > a[i+1]):
        cash += stock * a[i]
        stock = 0
    elif(a[i] < a[i+1]):
        stock += cash // a[i]
        cash %= a[i]
cash += stock * a[n-1]

print(cash)



Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    ll n, ans; cin >> n;
    vl a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    if (n & 1) {
        ans = abs(a[n/2] - b[n/2]) + 1;
    } else {
        ans = 2 * abs((a[n/2]+a[n/2-1])/2.0 - (b[n/2]+b[n/2-1])/2.0) + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6356
def main():
    import sys
    input=sys.stdin.buffer.readline
    n=int(input())
    b=129
    M=2**61-1
    x,y=1,0
    f=[x]*(n+2)
    h=[y]*(n+2)
    for i,c in enumerate(input()):
        f[i+1]=x=x*b%M
        h[i+1]=y=(y*b+c)%M
    ok,ng=0,n//2+1
    while ng-ok>1:
        mid=ok+ng>>1
        d={}
        for i in range(0,n-mid+1):
            k=(h[i+mid]-h[i]*f[mid])%M
            if k in d:
                if d[k]+mid<=i:
                    ok=mid
                    break
            else:
                d[k]=i
        else:
            ng=mid
    print(ok)
main()

Measured memory_bytes: 4196
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    i = 0
    tmp = []
    while i < N- 1:
        if A[i] == A[i + 1]:
            tmp.append(A[i])
            i += 1
        i += 1
    if len(tmp) > 1:
        ret = tmp[0] * tmp[1]
    else:
        ret = 0
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15988
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

char other(char a,char b){
    if(a=='R'){
        if(b=='G') return 'B';
        if(b=='B') return 'G';
    }else if(a=='G'){
        if(b=='R') return 'B';
        if(b=='B') return 'R';
    }else{
        if(b=='R') return 'G';
        if(b=='G') return 'R';
    }
    return 'N';
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<char> s(n);
    vl r,g,b;
    rep(i,n){
        char c;
        cin >> c;
        s[i] = c;
        if(c=='R') r.push_back(i);
        else if(c=='G') g.push_back(i);
        else b.push_back(i);
    }

    ll ans = 0;
    rep(i,n){
        rep(j,i+1,n){
            if(s[i]==s[j]) continue;
            char let = other(s[i],s[j]);
            if(let=='R'){
                auto itr = upper_bound(all(r),j);
                if(itr==r.end()) continue;
                ans += distance(itr,r.end());
                auto res = find(itr,r.end(),2*j-i);
                if(res != r.end()) ans--;
            }
            if(let=='G'){
                auto itr = upper_bound(all(g),j);
                if(itr==g.end()) continue;
                ans += distance(itr,g.end());
                auto res = find(itr,g.end(),2*j-i);
                if(res != g.end()) ans--;
            }
            if(let=='B'){
                auto itr = upper_bound(all(b),j);
                if(itr==b.end()) continue;
                ans += distance(itr,b.end());
                auto res = find(itr,b.end(),2*j-i);
                if(res != b.end()) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll max_num = 0;
    rep(i, n) rep(j, i) {
        max_num = max(max_num, abs(a[i]-a[j]) );
    }
    cout << max_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

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

	int h, w;
	cin >> h >> w;
	string* s = new string[h];
	rep(i, h) cin >> s[i];

	queue<pii> pre, next;
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				pre.push(pii(i, j));
			}
		}
	}

	int ans = 0;
	while (!pre.empty()) {
		while (!pre.empty()) {
			int x = pre.front().first;
			int y = pre.front().second;

			if (x != 0 && s[x - 1][y] != '#') {
				s[x - 1][y] = '#';
				next.push(pii(x - 1, y));
			}

			if (x != h - 1 && s[x + 1][y] != '#') {
				s[x + 1][y] = '#';
				next.push(pii(x + 1, y));
			}

			if (y != 0 && s[x][y - 1] != '#') {
				s[x][y - 1] = '#';
				next.push(pii(x, y - 1));
			}

			if (y != w - 1 && s[x][y + 1] != '#') {
				s[x][y + 1] = '#';
				next.push(pii(x, y + 1));
			}

			pre.pop();
		}

		swap(pre, next);
		++ans;
	}

	cout << ans - 1 << "\n";

	return 0;
}


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

long long cnt;
int n;
int A[1000000];
vector<int> G;

void insertionSort(int A[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    for (int a = 1; ;) {
        if (a > n) break;
        G.push_back(a);
        a = a * 3 + 1;
    }

    for (int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        cout << G[i];
        if (i == 0) cout << endl;
        else cout << ' ';
    }
    cout << cnt << endl;

    for (int i = 0; i < n; i++) {
        cout << A[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5172
import java.util.Scanner;

public class Main {
  public static void main (String args[]){
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int[][] countHeadEnd = new int[10][10];
      
      int count = 0;
      for (int i = 1; i <= N; ++i) {
        String strI = Integer.toString(i);
        int firstDigit = strI.charAt(0) - '0';
        int lastDigit = strI.charAt(strI.length() - 1) - '0';
        
        if (firstDigit == lastDigit) {
          ++count;
        }
        
        if (lastDigit != '0') {
          count += countHeadEnd[lastDigit][firstDigit] * 2;
        }
        
        ++countHeadEnd[firstDigit][lastDigit];
      }
      
      System.out.println(count);
    }
  }
}

Measured memory_bytes: 38884
#include<bits/stdc++.h>
#define pb push_back
#define ef(i,u) for(int i=b[u];i;i=nxt[i])
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,vis[N],a[N];
ll k;
VI Cir;
int main(){
    cin>>n>>k;
    rep(i,1,n)read(a[i]);
    int now=1,cnt=0,pre=0,len=0;
    while(1){
        if(vis[now]){len=cnt-vis[now]+1;pre=cnt-len;break;}
        Cir.pb(now);
        vis[now]=++cnt;
        now=a[now];
    }
    //rep(i,0,cnt-1)cout<<Cir[i]<<' ';
    //cout<<'\n';
    if(k<=pre){
        cout<<Cir[k]<<'\n';
        return 0;
    }
    k-=pre;
    cout<<Cir[(int)(k%(ll)(len)+pre)]<<'\n';
	return 0;
}


Measured memory_bytes: 5884
FB = (1..15).map{|x|a=[[:Fizz][x%3],[:Buzz][x%5]]*'';a==''?x: a}
loop do
  m, n = gets.split.map(&:to_i)
  break if m == 0
  pos = []
  ret = Array.new(m){|i|i+1}
  (FB*(n/15)+FB[0,n%15]).map.with_index{|v,i| v.is_a?(Integer) ? (i+1).to_s : v}.zip(n.times.map{gets.chomp}).map.with_index{|(a,b),i| i if a!=b}.compact[0,m-1].unshift(0).each_cons(2).with_index{|(a,b),i| pos << (b-a)%(m-i)}
  pos.reduce(0){|s,t| ret.slice!(t=(s+t)%ret.size); t-1}
  puts ret.join(' ')
end 

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

int main(){
	int n;
	cin>>n;
	int a[n+1]={0};
	for(int i=1;i<n;i++){
		int x;cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}

	return 0;
}


Measured memory_bytes: 4360
//https://www.cnblogs.com/yoyoball/p/9476080.html
//copy from yoyoball

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define Pr pair<int,int>
#define mp make_pair
using namespace std;
const int N=310,MOD=1e9+7;
vector<Pr> rec[N];
int f[N][N][N];
int n,m,ans;
void update(int &x,int y){x=(1LL*x+y+MOD+MOD)%MOD;}
void solve(){
    int sz,l,x;
    f[1][0][0]=1;
    for (int i=1;i<=n;++i){
        sz=rec[i].size();
        for (int p=0;p<sz;++p){
            l=rec[i][p].first; x=rec[i][p].second;
            for (int j=0;j<i;++j)
                for (int k=0;k<=max(0,j-1);++k){
                    if (x==1){
                        if (l<=j) f[i][j][k]=0;
                    }
                    else if (x==2){
                        if (l<=k||j<l) f[i][j][k]=0;
                    }
                    else{
                        if (k<l) f[i][j][k]=0;
                    }
                }
        }
        if (i==n) break;
        for (int j=0;j<i;++j)
            for (int k=0;k<=max(j-1,0);++k){
                if (!f[i][j][k]) continue;
                update(f[i+1][j][k],f[i][j][k]);
                update(f[i+1][i][k],f[i][j][k]);
                update(f[i+1][i][j],f[i][j][k]);
            }
    }
    ans=0;
    for (int j=0;j<n;++j)
        for (int k=0;k<=max(0,j-1);++k)
            update(ans,f[n][j][k]);
    ans=1LL*ans*3%MOD;
}

int main(){
    int l,r,x;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;++i){
        scanf("%d%d%d",&l,&r,&x);
        rec[r].push_back(mp(l,x));
    }
    solve();
    printf("%d\n",ans);
}

Measured memory_bytes: 112896
#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()
{
    string s;
    cin >> s;
    rep(i, 3)
    {
        if (s[i] == '1')
            s[i] = '9';
        else if (s[i] == '9')
            s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	int cnt=0;
	REP(i,n){
		int a;
		cin>>a;
		if(a&1) cnt++;
	}
	
	cout<<((cnt&1)?"NO":"YES")<<endl;
}

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

int main(){
	int n, k, a, b, ans = 0, pasta[101] = {}, dp[101][4][4] = {};
	
	cin >> n >> k;
	for(int i = 0; i < k; i++){
		cin >> a >> b;
		pasta[a] = b;
	}
	
	for(int i = 1; i <= 3; i++){
		if(pasta[1] > 0 && i != pasta[1]){
			continue;
		}
		dp[1][1][i] = 1;
	}
	
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= 3; j++){
			for(int l = 1; l <= 3; l++){
				if(pasta[i] > 0 && l != pasta[i]){
					continue;
				}
	
				dp[i][j][l] = dp[i - 1][1][j] + dp[i - 1][2][j] + dp[i - 1][3][j];

				if(i > 2 && j == l && dp[i][j][l] > 0 && dp[i - 1][j][l] > 0){
					dp[i][j][l] -= dp[i - 1][j][l];
				}
	
				dp[i][j][l] %= 10000;
			}
		}
	}
	
	for(int j = 1; j <= 3; j++){
		for(int l = 1; l <= 3; l++){
			ans += dp[n][j][l];
		}
	}
	
	cout << ans % 10000 << endl;
	
	return 0;
}

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

int main() {
	int a, b, c, d, e, f, g, h, i;
	string s;


	cin >> a >>b;




	//for (i = 0; i < ; i++) {
	
	
	
	
	//}

	if(a>=13)
	cout << b;
	if (a >= 6 && a <= 12)
		cout << b / 2;
	if (a < 6)
		cout << b * 0;

	return 0;

}

Measured memory_bytes: 256