akhauriyash/Code-Regression huggingface dataset:
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var e = int.Parse(Console.ReadLine().Trim());
            if (e == 0) break;
            Console.WriteLine(getM(e));
        }
    }
    public static int getM(int e)
    {
        var ret = 999999999;

        for (int z = 0; z * z * z <= e; z++)
        {
            var z3 = z * z * z;
            var y = (int)Math.Sqrt(e - z3);
            var y2 = y * y;
            var x = e - z3 - y2;
            ret = Math.Min(ret, x + y + z);
        }
        return ret;
    }
}

Measured memory_bytes: 9200
// C - Synthetic Kadomatsu
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vi A(3); for(int i=0; i<3; ++i) cin>>A[i];
	vi L(N); for(int i=0; i<N; ++i) cin>>L[i];

	int ans = INT_MAX, E = 1<<16;
	for(int i=0; i<E; ++i){

		vi B(3), C(3);
		for(int j=0; j<N; ++j){
			int b = (i>>(j*2)) & 3;
			if(b==3) continue;// not use
			++C[b];
			B[b] += L[j];
		}

		if(min({B[0], B[1], B[2]})!=0){//each requires at least one
			int sum = 0;
			for(int j=0; j<3; ++j){
				sum += abs(A[j] - B[j]);
				if(C[j]>=2) sum += (C[j] - 1) * 10;
			}
			ans = min(ans, sum);
		}

	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

//Library for input and output
// "strconv" //For conversion of strings to ints and vice versa
//i, err := strconv.Atoi("-42")
//s := strconv.Itoa(-42)
// "sort"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	h := make([]int, N+1)
	c := make([]int, N+1)

	for i := 1; i <= N; i++ {
		fmt.Scan(&h[i])
	}

	if N == 1 {
		fmt.Println(0)
		return
	}

	for i := 2; i <= N; i++ {
		c[i] = 2e9 + 1
		for j := Max(1, i-K); j < i; j++ {
			c[i] = Min(c[i], c[j]+Abs(h[j]-h[i]))
		}
	}

	fmt.Println(c[N])
}

// Reverse a string s
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// Abs returns the absolute value of x.
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// Min returns the min of x and y
func Min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

// Max returns the min of x and y
func Max(x int, y int) int {
	if x < y {
		return y
	}
	return x
}


Measured memory_bytes: 6312
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

ll work[100010][4];


int main(void){
	string s;
	cin>>s;
	rep(i,s.length()+10){
		rep(j,4){
			work[i][j]=0;
		}
	}
	work[0][0]=1;
	for(int i=1;i<=s.length();i++){
		if(s[i-1] == 'A'){
			work[i][0]=work[i-1][0];
			work[i][1]=work[i-1][1]+work[i-1][0];
			work[i][2]=work[i-1][2];
			work[i][3]=work[i-1][3];
			rep(j,4)work[i][j]%=MAX;
		}
		else if(s[i-1] == 'B'){
			work[i][0]=work[i-1][0];
			work[i][1]=work[i-1][1];
			work[i][2]=work[i-1][2]+work[i-1][1];
			work[i][3]=work[i-1][3];
			rep(j,4)work[i][j]%=MAX;
		}
		else if(s[i-1] == 'C'){
			work[i][0]=work[i-1][0];
			work[i][1]=work[i-1][1];
			work[i][2]=work[i-1][2];
			work[i][3]=work[i-1][3]+work[i-1][2];
			rep(j,4)work[i][j]%=MAX;
		}
		else{
			work[i][0]=work[i-1][0]*3;
			work[i][1]=work[i-1][1]*3+work[i-1][0];
			work[i][2]=work[i-1][2]*3+work[i-1][1];
			work[i][3]=work[i-1][3]*3+work[i-1][2];
			rep(j,4)work[i][j]%=MAX;
		}
		//cout<<work[i][0]<<" "<<work[i][1]<<" "<<work[i][2]<<" "<<work[i][3]<<endl;
	}
	cout<<work[s.length()][3]<<endl;
	return 0;
}


Measured memory_bytes: 3584
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 50

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int N;
int P[MAX];

int selectionSort(int a[MAX], int n) {
    int t, sw = 0;
    int mini;
    REP(i, n-1) {
        mini = i;
        for(int j=i; j<n;j++) {
            if(a[j] < a[mini]) {
                mini = j;
            }
        }
        t = a[i];
        a[i] = a[mini];
        a[mini] = t;
        if(i!=mini) {
            sw++;
        }
    }
    return sw;
}
int main() {
    cin >> N;
    REP(i, N) {
        cin >> P[i];
    }
    int ans = selectionSort(P, N);

    if(ans>1) {
        print("NO");
    } else {
        print("YES");
    }
    return 0;
}



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

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;
		static T MIN<T>(params T[] args) => args.Min();
		static T MAX<T>(params T[] args) => args.Max();

		static void Main(string[] args)
		{
			var n = RI;
			var list = new List<long>();
			var lia = new List<int>();
			var lib = new List<int>();
			var dic = new Dictionary<long, List<int>>();
			var aa = new List<ob>();
			for (int i = 0; i < n; i++)
			{
				var ab = RIs;
				var a = ab[0];
				var b = ab[1];
				var o = new ob();
				o.obj1 = a;
				o.obj2 = b;
				o.param = a + b;
				aa.Add(o);
			}
			aa.Sort();
			aa.Reverse();
			long ans = 0;
			for(int i = 0;i < n;i++)
			{
				if(i % 2 == 0)
				{
					ans += aa[i].obj1;
				}
				else
				{
					ans -= aa[i].obj2;
				}
			}
			Out(ans);
		}
		
		class ob : IComparable
		{
			public int obj1;
			public int obj2;
			public long param;

			public int CompareTo(object obj)
			{
				return param.CompareTo(((ob)obj).param);
			}
		}
	}
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

template<class K, class V>
vector<V> values(map<K, V> const& m) {
  vector<V> result;
  for (auto e: m) result.push_back(e.second);
  return result;
}

template<class T>
vector<T> grep(std::function<bool(T)> const& f, vector<T> const& v) {
  vector<T> result;
  for (auto e: v) if (f(e)) { result.push_back(e); }
  return result;
}

int main() {
  int H, W; cin >> H >> W;
  map<char, int> mp;
  rep(i, H * W) {
    char ch; cin >> ch;
    mp[ch]++;
  }
  auto vs = values(mp);

  if (H == 1 || W == 1) {
    auto len = max(H, W);
    if (len % 2 == 0 &&
        grep<int>([](int n){ return n % 2 == 0; }, vs).size() == vs.size()) {
      cout << "Yes\n";
    }
    else if (len % 2 &&
        grep<int>([](int n){ return n % 2 == 0; }, vs).size() == vs.size() - 1) {
      cout << "Yes\n";
    }
    else {
      cout << "No\n";
    }
    return 0;
  }

  if (grep<int>([](int n){ return n % 4 == 0; }, vs).size() == vs.size()) {
    cout << "Yes\n";
    return 0;
  }

  int even_limit = 0;
  if (H % 2) even_limit += W / 2;
  if (W % 2) even_limit += H / 2;

  int odd_limit = 0;
  if ((H % 2) && (W % 2)) odd_limit = 1;

  int even_cnt = 0, odd_cnt = 0;
  for (auto e: vs) {
    if (e % 4 == 0) continue;
    if (e % 2 == 0) even_cnt++;
    else odd_cnt++;
  }
  if (even_cnt <= even_limit && odd_cnt <= odd_limit) {
    cout << "Yes\n";
    return 0;
  }

//  cout << even_cnt << " " << even_limit << ", " << odd_cnt << " " << odd_limit << "\n";
  cout << "No\n";
}


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

bool cmp(pair<string,pair<int,int> > a, pair<string,pair<int,int> > b)
{
	if(a.first==b.first)
		return a.second.first>b.second.first;
	else
		return a.first<b.first;
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	
	vector<pair<string,pair<int,int> > > vi;
	for(int i=0;i<n;i++)
	{
		string s;
		int curr;
		cin>>s>>curr;
		vi.push_back({s,{curr,i+1}});
	}
	sort(vi.begin(),vi.end(),cmp);
	for(auto i:vi)
		cout<<i.second.second<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
namespace IO
{
	const int __S=(1<<20)+5;char __buf[__S],*__H,*__T;
	inline char getc()
	{
		if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin);
		if(__H==__T) return -1;return *__H++;
	}
	template <class __I>inline void read(__I &__x)
	{
		__x=0;int __fg=1;char __c=getc();
		while(!isdigit(__c)&&__c!='-') __c=getc();
		if(__c=='-') __fg=-1,__c=getc();
		while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc();
		__x*=__fg;
	}
	inline void readd(double &__x)
	{
		__x=0;double __fg=1.0;char __c=getc();
		while(!isdigit(__c)&&__c!='-') __c=getc();
		if(__c=='-') __fg=-1.0,__c=getc();
		while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc();
		if(__c!='.'){__x=__x*__fg;return;}else while(!isdigit(__c)) __c=getc();
		double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc();
		__x=__x*__fg;
	}
	inline void reads(char *__s,int __x)
	{
		char __c=getc();int __tot=__x-1;
		while(__c<'!'||__c>'~') __c=getc();
		while(__c>='!'&&__c<='~') __s[++__tot]=__c,__c=getc();
		__s[++__tot]='\0';
	}
	char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr;
	inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;}
	inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();}
	template <class __I>inline void print(__I __x)
	{
		if(!__x) putc('0');
		if(__x<0) putc('-'),__x=-__x;
		while(__x) __qu[++__qr]=__x%10+'0',__x/=10;
		while(__qr) putc(__qu[__qr--]);
	}
	inline void prints(const char *__s,const int __x)
	{
		int __len=strlen(__s+__x);
		for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]);
	}
	inline void printd(double __x,int __d)
	{
		long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t;
		while(__d--)
		{
			double __y=__x*10.0;__x*=10.0;
			int __c=(int)floor(__y);
			putc(__c+'0');__x-=floor(__y);
		}
	}
	inline void el(){putc('\n');}inline void sp(){putc(' ');}
}using namespace IO;
struct nod{int x,y,z,c,v;}p[400005];char o[5][10];
int n,m,K,tot,A1,A2,B1,B2,x[400005],y[400005],z[400005],c[400005],vis[400005],a[400005],las[400005],s[400005],v[400005];
inline bool cmp(nod a,nod b)
{
	if(a.c!=b.c) return a.c<b.c;
	if(a.c==b.c&&a.c==1) return a.y<b.y;if(a.c==b.c&&a.c==2) return a.x<b.x;
	if(a.c==b.c&&a.c==3) return a.y>b.y;if(a.c==b.c&&a.c==4) return a.x>b.x;
}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=K;i++)
	{
		scanf("%d%d%d%d",&A1,&B1,&A2,&B2);
		if(((A1==0||A1==n)||(B1==0||B1==m))&&((A2==0||A2==n)||(B2==0||B2==m))) 
			x[++tot]=A1,y[tot]=B1,z[tot]=1,v[tot]=i,x[++tot]=A2,y[tot]=B2,z[tot]=-1,v[tot]=i;
	}
	for(int i=1;i<=tot;i++)
	{
		if(x[i]==0&&y[i]>0) c[i]=1;if(x[i]>0&&y[i]==m) c[i]=2;
		if(x[i]==n&&y[i]<m) c[i]=3;if(x[i]<n&&y[i]==0) c[i]=4;
	}
	for(int i=1;i<=tot;i++) p[i]=(nod){x[i],y[i],z[i],c[i],v[i]};
	sort(p+1,p+tot+1,cmp);for(int i=1;i<=tot;i++) a[i]=p[i].v;
	for(int i=tot;i;i--) if(!vis[a[i]]) vis[a[i]]=i,las[i]=tot+1;else las[i]=vis[a[i]];
	for(int i=1;i<=tot;i++) if(las[i]!=tot+1) s[i]++,s[las[i]]--;
	for(int i=1;i<=tot;i++) s[i]+=s[i-1];
	for(int i=1;i<=tot;i++) if(las[i]!=tot+1&&s[las[i]]-s[i-1]!=0){puts("NO");goto gg;}
	puts("YES");gg:;
}

Measured memory_bytes: 19968
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        int Q = sc.nextInt();
        var S = sc.next();
        var l = new List<int>();
        var r = new List<int>();
        for (int i = 0; i < Q; i++) {
            l.Add(sc.nextInt());
            r.Add(sc.nextInt());
        }

        var lst = new List<int>();
        var bef = "";
        var cnt = 0;
        for (int i = 0; i < N; i++) {
            if (bef + S[i] == "AC") {
                cnt++;
            }
            bef = S[i].ToString();
            lst.Add(cnt);
        }

        for (int i = 0; i < Q; i++) {
            WriteLine(lst[r[i]-1] - lst[l[i]-1]);
        }
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 21564
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, a, b) for(ll (i)=(a);(i)<=(b);i++)
#define rFOR(i, a, b) for(ll (i)=(b);(i)>=(a);i--)
#define REP(i, n) for(ll i=0;i<n;i++)
using namespace std;

int main() {
  int N,T[100],M,P[100],X[100];
  cin>>N;
  REP(i,N) cin>>T[i];
  cin>>M;
  REP(i,M) cin>>P[i]>>X[i];
  REP(i,M){
    int sum=0;
    FOR(n,1,N){
      if (n==P[i]){
        sum+=X[i];
      }else{
        sum+=T[n-1];
      }
    }
    cout<<sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;

int main()
{
    const int mod=1000000007;
    bool flag=true;
    int n,m,a,tmp=-1; cin>>n>>m;
    long long int ans=1;
    vector<bool>safe(n+1,true);
    vector<long long int>dp(n+2,0);
    for(int i=0;i<m;i++){
        cin>>a;
        safe[a]=false;
        if(a-tmp==1)flag=false;
        tmp=a;
    }
    dp[0]=1;
    dp[1]=1;
    for(int i=2;i<n+1;i++){
        
        if(i==2 and safe[1]==false){
            dp[1]=0;
            dp[2]=1;
            continue;   
        }
            
        if(safe[i]){
            dp[i]=dp[i-1]+dp[i-2];
            dp[i]%=mod;
        }else{
            ans*=dp[i-1];
            ans%=mod;
            dp[i]=0;
            dp[i+1]=1;
            i++;
        }
    }
    ans*=dp[n];
    
    
    
    if(flag) cout<<ans%mod<<endl;
    else cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 1024
N = input()
A = map(int, raw_input().split())
B = []
flag = 2
flag2 = 0
k = 0
minabs = 0
for i in range(N):
	k = abs(A[i])
	B.append(k)
	if(k != 0 and (k < minabs or minabs == 0)):
		minabs = k
	if(i == N - 1):
		if(A[i] == 0 or flag2 == 1):
			flag2 = 1
		elif((flag == 1 and A[i] < 0) or (flag == 0 and A[i] > 0)):
			flag2 = 1
		else:
			flag2 = 0
	else:
		if(flag == 2):
			if(A[i] > 0):
				flag = 0
			elif(A[i] == 0):
				flag2 = 1
			else:
				flag = 1
		elif((A[i] > 0 and flag == 0) or (A[i] < 0 and flag == 1)):
			flag = 0
		elif((A[i] < 0 and flag == 0) or (A[i] > 0 and flag == 1)):
			flag = 1
		else:
			flag2 = 1
if(flag2 == 1):
	print(sum(B))
else:
	print(sum(B)- minabs * 2)

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    string s,h="hi",t; cin>>s;
    rep(i,s.size()/2) t+=h;
    if(t==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int H = 12;
const int W = 1002;
const int INF = (int)1e9;

int h, w, k;
char dat[H][W];
int preSum[H][W];

int query(int r1, int c1, int r2, int c2) {
	int ret = preSum[r2][c2];
	if (r1 == 0 && c1 == 0) return ret;
	if (r1 == 0) return ret - preSum[r2][c1-1];
	if (c1 == 0) return ret - preSum[r1-1][c2];
	return ret - preSum[r2][c1-1] - preSum[r1-1][c2] + preSum[r1-1][c1-1];
}

bool isCuttable(vi onBit, int c) {
	for (int i = 1; i < sz(onBit); i++) {
		int res = query(onBit[i-1]+1, c, onBit[i], c);
		if (res > k) return false;
	}
	return true;
}

int getResult(int mask) {
	// printf("mask = %d\n", mask);
	vi onBit;
	onBit.push_back(-1);
	for (int i = 0; i < h-1; i++) {
		if (mask & (1<<i)) {
			onBit.push_back(i);
		}
	}
	onBit.push_back(h-1);
	int ret = 0;
	int lastColumnCut = 0;
	for (int c = 0; c < w; c++) {
		bool cut = false;
		for (int i = 1; i < sz(onBit); i++) {
			int res = query(onBit[i-1]+1, lastColumnCut, onBit[i], c);
			// printf("res = %d\n", res);
			if (res > k) {
				cut = true;
			}
		}

		if (cut) {
			if (isCuttable(onBit, c)) {
				ret++;
				lastColumnCut = c;
			}
			else {
				return INF;
			}
		}
	}
	// printf("ret = %d\n", ret);
	return ret;
}

int main() {
	scanf("%d %d %d", &h, &w, &k);
	for (int i = 0; i < h; i++) {
		scanf("%s", dat[i]);
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			preSum[i][j] = (dat[i][j] - '0');
			if (i > 0 && j > 0) preSum[i][j] += preSum[i-1][j] + preSum[i][j-1] - preSum[i-1][j-1];
			else if (i > 0) preSum[i][j] += preSum[i-1][j];
			else if (j > 0) preSum[i][j] += preSum[i][j-1];
			// printf("%d ", preSum[i][j]);
		}
		// printf("\n");
	}
	int ans = INF;
	for (int mask = 0; mask < (1 << (h-1)); mask++) {
		ans = min(ans, __builtin_popcount(mask) + getResult(mask));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a,unsigned long long b)
  {   return b==0?a:gcd(b,a%b);
  }
unsigned long long lcm(unsigned long long a,unsigned long long b)
  {   return a*(b/gcd(a,b));
  }
int main()
{
   int n;unsigned long long ans,a;
     cin>>n;
     cin>>ans;
      n--;
     while(n--)
     { cin>>a;
       ans=lcm(ans,a);
     }
     cout<<ans;
	     
	return 0;
}

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

int main()
{
	int k, s, ans;

	cin >> k >> s;

	for (int i = 0; i <= k; i++){
		for (int j = 0; j <= k; j++){
			if (i + j <= s && k + i + j >= s){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return (0);
}	


Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
from functools import reduce
from operator import xor,add
from collections import Counter

N,M = map(int, input().split())
A = list(map(int, input().split()))

mlist = [0]
powlist = []
bitcount = Counter()
bitunseencount = {}
s = 0
x = 2**s

while x <= M:
    powlist.append(x)
    s += 1
    x = 2**s

for a in A:
    for i,p in enumerate(powlist):
        bitcount[i] += (a&(1<<i))>>i

for i, p in enumerate(powlist):
    bitunseencount[i] = N - bitcount[i]

importance = []
for i,p in enumerate(powlist):
    importance.append( (1<<i) * bitcount[i])

unseenimportance = []
for i,p in enumerate(powlist):
    unseenimportance.append( (1<<i) * bitunseencount[i])


MASK = 0
for i,p in enumerate(powlist):
    if unseenimportance[i] > importance[i]:
        if M >= MASK|(1<<i):
            MASK |= 1<<i

ans = reduce(add, map(lambda x: x^MASK, A))
# -------------------
MASK = 0
for i,p in list(enumerate(powlist))[::-1]:
    # print(i,p)
    if unseenimportance[i] > importance[i]:
        if M >= MASK|(1<<i):
            MASK |= 1<<i

ans = max(ans, reduce(add, map(lambda x: x^MASK, A)))
print(ans)
exit(0)
# 
#     
#    
# 
# print("bit count : ", bitcount)
# print("bitunseen : ", bitunseencount)
# print("importance: ", importance)
# print("unseen rtance: ", unseenimportance)
#         
#         
# exit(0)
# 
# ans = 0
# for m in mlist:
#     # print("m : ", m )
#     # print("sum: " , reduce(add,  map(lambda x: x^m, A)))
#     ans = max(ans, reduce(add,  map(lambda x: x^m, A)))
# 
# print(ans)



Measured memory_bytes: 68696
const MAX_N: usize = 100010;

fn dfs(pos: usize, colors: &mut Vec<i32>, edges: &Vec<Vec<(usize, usize)>>) -> bool {
    for &(nxt, weight) in edges[pos].iter() {
        if colors[nxt] != -1 {
            continue;
        }
        if weight % 2 == 0 {
            colors[nxt] = colors[pos];
            dfs(nxt, colors, edges);
        } else {
            if colors[pos] == 0 {
                colors[nxt] = 1;
            } else {
                colors[nxt] = 0;
            }
            dfs(nxt, colors, edges);
        }
    }
    true
}
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut edges: Vec<Vec<(usize, usize)>> = vec![Vec::new(); MAX_N];
    for _ in 0..n - 1 {
        let u: usize = sc.read::<usize>() - 1;
        let v: usize = sc.read::<usize>() - 1;
        let w: usize = sc.read();
        edges[u].push((v, w));
        edges[v].push((u, w));
    }
    let mut colors = vec![-1; MAX_N];
    colors[0] = 0;
    dfs(0, &mut colors, &edges);
    for i in 0..n {
        println!("{}", colors[i]);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 20988
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

int seiyaku_check(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	
	int a,b,c,d,e;
	cin >> a >> b;
	
	seiyaku_check(a,0,1000000000);
	seiyaku_check(b,0,1000000000);
	
	if((a+b)%2 !=0){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << (a+b)/2 << endl;
	}
	
	
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n;
	if (!scanf( "%d", &n )){
		return -1;
	}
	char* str = new char[n+1];
	if (!scanf( "%s", str )){
		return -1;
	}
	if (n%2 != 0){
		printf("No\n");
		return 0;
	}
	int b = n/2;
	bool is_correct = true;
	rep(i,0,b){
		if (str[i] != str[i+b]){
			is_correct = false;
			break;
		}
	}
	if(is_correct)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};
int n,k;

int main() {
  vector<int> a(3);
  for(int i=0;i<3;i++)
    cin >> a.at(i);
  
  sort(a.begin(),a.end());
  
  cout << a.at(2)*10+a.at(1)+a.at(0) << endl;
  
  
}

Measured memory_bytes: 1024
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	public void run()
	{
		Scanner file = new Scanner(System.in);
		int N = file.nextInt();
		long[] ints = new long[N];
		for(int i = 0;i<N;i++)
			ints[i] = file.nextLong();
		long[][] dp = new long[ints.length][2];
		dp[ints.length-1][0] = -ints[ints.length-1];
		dp[ints.length-1][1] = ints[ints.length -1];
		for(int i = ints.length-2;i>=0;i--)
		{
			for(int j = 0;j<2;j++)
			{
				if(j == 0)
				{
					dp[i][j] = Math.max(-ints[i]+dp[i+1][1],ints[i]+dp[i+1][0]);
				}else {
					dp[i][j] = Math.max(ints[i]+dp[i+1][1],-ints[i]+dp[i+1][0]);
				}
			}
		}
		System.out.println(dp[0][1]);
	}
	
	int gcd(int a, int b)
	{
		return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
	}
	
}


Measured memory_bytes: 62204
#include <iostream>

using namespace std;
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	int n,p,i=1,swap_num=0;
	cin >> n;
	while(n){
		cin >> p;
		if(i != p) swap_num++;
		if(swap_num > 2){
			cout << "NO\n";
			return 0;
		}
		i++;
		n--;
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 256
S = input()

c = 0
m = 0

for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" :
        c += 1
        m = max(c,m)
    elif S[i] == "G" or S[i] == "T" :
        c += 1
        m = max(c,m)
    else :
        m = max(c,m)
        c = 0

print(m)


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

typedef pair<int, string> P;

const char rgb[] = "RGB";
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int x, y;

bool check(string& s)
{
    char start = s[0];
    for (char c : s){
        if (c != start) return false;
    }
    return true;
}

void change(string& s, int cx, int cy, char from, char to)
{
    if (cx < 0 || x <= cx || cy < 0 || y <= cy || s[cy * x + cx] != from) return;
    s[cy * x + cx] = to;
    for (int i = 0; i < 4; i++){
        change(s, cx + dx[i], cy + dy[i], from, to);
    }
}

int main()
{
    while (scanf("%d %d", &x, &y), x){
        char grid[128] = {0};
        for (int i = 0; i < x * y; i++){
            scanf(" %c", grid + i);
        }

        string s(grid);
        set<string> exist;
        queue<P> que;
        for (exist.insert(s), que.push(P(0, s)); ; que.pop()){
            P p = que.front();

            if (check(p.second)){
                printf("%d\n", p.first);
                break;
            }

            for (char c : rgb){
                string tmp = p.second;

                if (tmp[0] != c){
                    change(tmp, 0, 0, tmp[0], c);
                    if (exist.find(tmp) == exist.end()){
                        exist.insert(tmp);
                        que.push(P(p.first + 1, tmp));
                    }
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

class UnionFind{
public:
  //親の番号を格納する変数。数値がマイナスの場合は親であり、その絶対値のサイズのグループを持っている
  vector<int> Parent;
  
  //コンストラクタ。-1で初期化する。
  UnionFind(int N){
    Parent = vector<int>(N,-1);
  }
  
  //Aが何処のグループに属しているか返す
  int root(int A){
    if(Parent[A] < 0) return A; //0以下の時は自分が親。自分のグループなので自分を返す
    return Parent[A] = root(Parent[A]); //根でなかった場合は再帰的に関数を呼ぶ。ついでにParent[A]を更新して次の時高速化する。
  }
  
  //自分の親の頂点数を返す。マイナスでグループのサイズを持っているので反転して返す。
  int size(int A){
    return -Parent[root(A)];
  }
  
  //AとBを連結する関数
  bool connect(int A, int B){
    A = root(A); //Aの親を持ってくる
    B = root(B); //Bの親を持ってくる
    if (A==B){ //親が同じだったらくっつけない
      return false;
    }
    
    //Aが必ず大きい数にする
    if (size(A) < size(B)) swap(A,B);
    
    //AにBのグループをくっつける。
    Parent[A] += Parent[B];
    //Bの親をAにする。
    Parent[B] = A;
    
    return true;
  }
};
const ll MAX = 100005;
ll n;
vector<ll> x,y;

int main(){
  cin >> n;
  UnionFind uf(MAX*2);
  x.resize(n);y.resize(n);
  rep(i,n){
    cin >> x[i] >> y[i];
    uf.connect(x[i],y[i]+MAX);
  }
  map<int,ll> mx,my;
  rep(i,MAX) mx[uf.root(i)]++;
  for(int i = MAX; i < MAX*2;i++) my[uf.root(i)]++;
  ll ans = 0;
  rep(i,MAX*2) ans += mx[i] * my[i];
  cout << ans - n << endl;
  
  return 0;
}

Measured memory_bytes: 27648
#include <iostream>
using namespace std;
int main(){
  
  int n, m;
  cin>>n>>m;
  int total = 0;
  while(m--){
    int temp;
    cin>>temp;
    total += temp;
  }
  
  if(n-total < 0){
      cout<<-1<<endl;
  }else{
      cout<<n-total<<endl;
  }
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
AliceScore = 0
BobScore = 0
for i in range(N):
    if(i%2==0):
        AliceScore += A[i]
    else:
        BobScore += A[i]
score = AliceScore - BobScore
print(score)


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < K; i++){
    sum += p.at(i);
  }
  cout << sum;
}

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

int main() {
    int K, T;
    cin >> K >> T;

    vector<int> a(T);
    for (int i = 0; i < T; i++) {
        cin >> a[i];
    }

    int prev = -1, ans = 0;
    for (int i = 0; i < K; i++) {
        int cur = -1;
        for (int j = 0; j < T; j++) {
            if (a[j] == 0 or prev == j) continue;
            if (cur < 0 or a[cur] < a[j]) cur = j;
        }
        if (cur < 0) {
            cur = prev;
            ans++;
        }
        a[cur]--;
        prev = cur;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// Copyright 2017 wu_qing
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
const int N = 2e3 + 10, INF = ~0u >> 1;
int n, t1, t2, k, tot = INF, cur;
bool v[N];
std::vector<int> to[N];
std::pair<int, int> e[N];
inline void dfs(int p, int d) {
    v[p] = true;
    if (d > k)
        cur++;
    for (std::vector<int>::iterator it = to[p].begin();
            it != to[p].end(); it++)
        if (!v[*it])
            dfs(*it, d + 1);
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &t1, &t2);
        to[t1].push_back(t2);
        to[t2].push_back(t1);
        e[i] = std::make_pair(t1, t2);
    }
    if (k & 1) {
        k /= 2;
        for (int i = 1; i < n; i++) {
            memset(v, false, sizeof v);
            cur = 0;
            v[e[i].first] = v[e[i].second] = true;
            dfs(e[i].first, 0);
            dfs(e[i].second, 0);
            tot = std::min(tot, cur);
        }
    } else {
        k /= 2;
        for (int i = 1; i <= n; i++) {
            memset(v, false, sizeof v);
            cur = 0;
            v[i] = true;
            dfs(i, 0);
            tot = std::min(tot, cur);
        }
    }
    printf("%d\n", tot);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    long long n ;
    cin >> n;
    string ans = "";
    while(n){
        int rem = n%26;
        n/=26;
        if(rem == 0){
            ans+='z';
            n--;
        }
        else{
            char ch = 'a' + rem - 1;
            ans+=ch;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
 
}







Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,k;
bool vis[105][105];
int main()
{
    scanf("%d %d",&n,&k);
    if(k>(n-2)*(n-1)/2)
        printf("-1\n");
    else
    {
        printf("%d\n",n*(n-1)/2-k);
        for(int i=1;i<=n-2&&k;i++)
            for(int j=i+1;j<=n-1&&k;j++)
            {
                k--;
                vis[j][i]=vis[j][i]=true;
            }
        for(int i=1;i<=n;i++)
            for(int j=1;j<i;j++)
        if(vis[i][j]==false)
            printf("%d %d\n",i,j);
    }
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll h,w;
  cin>>h>>w;
  ll cnt=0;
  vector<vector<char>> v(h,vector<char>(w));
  rep(i,h) rep(j,w) cin>>v[i][j];
  rep(i,h) rep(j,w) if(v[i][j]=='#') cnt++;
  if(cnt==h+w-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define int long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
void solve() {
    int n;
    cin>>n;
    int vec[n][3];
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<3;++j)
        {
            cin>>vec[i][j];
        }

    }
    int dp[n][3]={0};
    dp[0][0]=vec[0][0];
    dp[0][1]=vec[0][1];
    dp[0][2]=vec[0][2];
    for(int i=1;i<n;++i)
    {
        dp[i][0]=max(dp[i-1][1]+vec[i][0],dp[i-1][2]+vec[i][0]);
        dp[i][1]=max(dp[i-1][0]+vec[i][1],dp[i-1][2]+vec[i][1]);
        dp[i][2]=max(dp[i-1][0]+vec[i][2],dp[i-1][1]+vec[i][2]);
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--) solve();

}


Measured memory_bytes: 8248
#include <iostream>
#include <cstring>

using namespace std;

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

int w, h, vis[2][64][64];
char a[64][64];

void rec(int x, int y, bool color){
	
	if(x < 0 || w <= x || y < 0 || h <= y || a[y][x] != '.' || vis[color][y][x])
		return;
	
	vis[color][y][x] = true;
	
	for(int i=0; i<4; ++i){
		rec(x+dx[i], y+dy[i], color);
	}
}
 
int main(){
	
	while(cin>>w>>h, (w||h)){
		
		int sqw=0, sqb=0;
		memset(vis, 0, sizeof(vis));
		
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				cin>>a[i][j];
			}
		}
		
		for(int y=0; y<h; ++y){
			for(int x=0; x<w; ++x){
			
				if(a[y][x]!='.'){
				
					for(int i=0; i<4; ++i){
						rec(x+dx[i], y+dy[i], a[y][x]=='B');
					}
				}
			}
		}
		
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				
				if(vis[0][i][j] ^ vis[1][i][j]){
					
					if(vis[0][i][j])
						sqw++;
					else if(vis[1][i][j])
						sqb++;
				}
			}
		}
		
		cout << sqb << " " << sqw << endl;
	}
	
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,p;cin >> n >> p;
	int even=0;
	rep(i,n){
		int a;
		cin >> a;
		if(a%2==0) even++;
	}
	if(n==even && p==0) cout << (ll)pow(2,n) << endl;
	else if(n==even) cout << 0 << endl;
	else cout << (ll)pow(2,n-1) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
	int N;
	int a[200000];
	int j = 0, k=1, l =0,o = 0;


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

		cin >> a[i];
	}

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

		if (a[i] == k) {
			l = l + j;
			j = 0;
			k++;
		}
		else {
			j++;
		}

	}

	if (k == 1) {
		cout << "-1";
		return 0;
	}
	if (k != N){
		l = l + j;
		}

	cout << l;
}

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

#define int long long
#define endl '\n'
int32_t main()
{

    int mod;
    cin>>mod;
    int start=7%mod;
    for(int i=1;i<(int)1e7;i++)
    {
    	if(start==0)
    	{
    		cout<<i;return 0;
    	}
    	start=(start*10+7)%mod;
    }
    cout<<"-1";
   
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll dp[105][100005];
int main()
{
   ll a , b , c , d;
   cin >> a >> b >> c >> d;
   ll v1= a*c;
   ll v2 = a*d;
   ll v3 =b*c;
   ll v4 = b*d;
   cout << max(v1 , max(v2 , max(v3,v4))) << '\n';
}





Measured memory_bytes: 3628
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
  int l,r, largest;
  l = 2*i;
  r = 2*i+1;

  if(l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;


  if(largest != i) {
    swap(A[i] , A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  cin >> H;

  for(int i = 1; i <= H; i++ ) cin >> A[i];

  for(int i = H/2; i >= 1; i-- ) maxHeapify(i);

  for(int i = 1; i <= H; i++ ) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;

}

Measured memory_bytes: 3116
var f1,f2:boolean; ch:char;
begin
  while not(eoln) do
  begin
    read(ch);
    if ch='C' then f1:=true;
    if (f1)and(ch='F') then 
    begin
      f2:=true; break;
    end;
  end;
  if f2 then writeln('Yes') else writeln('No');
end.

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = b * d;
    ans = max(ans, c * a);
    ans = max(ans, d * a);
    ans = max(ans, b * c);
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3648
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused_imports)]
use std::io::Write;
use std::collections::*;
use template::*;

#[macro_use]
pub mod template {
	macro_rules! debug {
	    ($($v: expr),*) => {
	    	$(let _ = write!(std::io::stderr(), "{} = {:?} ", stringify!($v), $v);)*
	        let _ = writeln!(std::io::stderr(), "@ {}:{}", file!(), line!());
	    }
	}
	macro_rules! mat {
		($e:expr) => { $e };
		($e:expr; $d:expr $(; $ds:expr)*) => { vec![mat![$e $(; $ds)*]; $d] };
	}
	pub trait FromLn {
		fn fromln(s: &str) -> Self;
	}	
	pub fn readln<T: FromLn>() -> T {
		let mut buf = String::new();
		let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
		T::fromln(buf.trim())
	}
	pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
		let mut vs = vec![];
		for _ in 0..n { vs.push(readln()); }
		vs
	}
	macro_rules! fromln_primitives {
		($($t:ty),*) => { $(
			impl FromLn for $t {
				fn fromln(s: &str) -> $t {
					s.parse().unwrap()
				}
			}
		)* }
	}
	fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
	impl<T> FromLn for Vec<T> where T: FromLn {
		fn fromln(s: &str) -> Vec<T> {
			s.split_whitespace().map(T::fromln).collect()
		}
	}
	impl FromLn for Vec<char> {
		fn fromln(s: &str) -> Vec<char> {
			s.chars().collect()
		}
	}
	macro_rules! fromln_tuple {
		($($t:ident: $i:expr),*; $n:expr) => {
			impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
				fn fromln(s: &str) -> ($($t),*) {
					let ss = s.split_whitespace().collect::<Vec<_>>();
					assert_eq!(ss.len(), $n);
					($($t::fromln(ss[$i])),*)
				}
			}
		}
	}
	fromln_tuple!(A:0, B:1; 2);
	fromln_tuple!(A:0, B:1, C:2; 3);
	fromln_tuple!(A:0, B:1, C:2, D:3; 4);
	pub trait SetMin {
		fn setmin(&mut self, v: Self) -> bool;
	}
	impl<T> SetMin for T where T: PartialOrd {
		fn setmin(&mut self, v: T) -> bool {
			*self > v && { * self = v; true }
		}
	}
	pub trait SetMax {
		fn setmax(&mut self, v: Self) -> bool;
	}
	impl<T> SetMax for T where T: PartialOrd {
		fn setmax(&mut self, v: T) -> bool {
			*self < v && { * self = v; true }
		}
	}
}
fn main() {
	let _ = writeln!(std::io::stderr(), "----- {} -----", file!());
	let _ = std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn run() {
	let mut x: i64 = readln();
	let mut n = (x / 11) * 2;
	x %= 11;
	if x > 0 {
		x -= 6;
		n += 1;
		if x > 0 {
			n += 1;
		}
	}
	println!("{}", n);
}


Measured memory_bytes: 8572
import java.util.*;
import java.io.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		int ans = 0;
		
		for (int i=0; i<n; i++) {
			int min = i;
			boolean b = false;
			for (int j=i; j<n; j++) {
				if (list.get(j) < list.get(min)) {
					min = j;
					b = true;
				}
			}
			
			if (b == true) ans++;
			
			Collections.swap(list, i, min);
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(ans);
		
	}
}



Measured memory_bytes: 26480
import sys
from collections import deque

def bfs(maze, visited):
    sy,sx=0,0
    gy,gx=H-1,W-1
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]

        p=[]
        if x>0 : p.append([0,-1])
        if x<W-1: p.append([0,1])
        if y>0: p.append([-1,0])
        if y<H-1: p.append([1,0])
        for j, k in p:
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and \
                visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    return -1

H,W=map(int,input().split())
m=[input() for i in range(H)]

visited=[[-1]*W for i in range(H)]
ans=sum(m[i].count(".") for i in range(H))
p=bfs(m,visited)
print( p if p==-1 else ans-p-1)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-------------------------------------------------

int w, h, c;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

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

    cin >> w >> h >> c;
	int g = gcd(max(w, h), min(w, h));
	cout << (w / g) * (h / g) * c << endl;

	return 0;
}




Measured memory_bytes: 3236