akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long N = fs.nextLong();

        long ans = Long.MAX_VALUE;
        for (int i = 1; i <= (int)Math.sqrt(N); ++i) {
            if (N % i == 0) {
                ans = Math.min(ans, (i+(N/i))-2);
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32556
#include <bits/stdc++.h>
using namespace std ; 
#define ll long long
#define flp(i ,a ,b) for(int  i = a ; i<b ; i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define blp(i, a , b) for(int  i = a ; i>=b ; i--)
#define lol 1000000007

ll fact[100001] ; 

void init()
{
	fact[0] = 1  ; 
	for( ll i = 1  ; i<100001 ; i++)
	{
		fact[i]= (i*fact[i-1])%lol ;
	}
}
long long binpow(long long a, long long b, long long m) {
	a %= m;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

ll modInverse(ll n, ll p) 
{ 
    return binpow(n, p-2, p); 
} 


ll solve(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
  
    return (fact[n]* ((modInverse(fact[r], p) *modInverse(fact[n-r], p) ) % p)) % p; 
} 


int main()
{	ios ; 
	ll n , k ; 
	cin>>n>>k; 
	int a[n] ; 
	flp(i,0,n)
	{
		cin>>a[i] ; 
	}
	int dp[n] ;
	dp[0] = 0  ; 
	flp(i,1 , n)
	{
		dp[i]= dp[i-1] + abs(a[i]-a[i-1]);
		for(int j = 2  ; j<=k ; j++)
		{		if(i>=j)
				{
					dp[i] =min(dp[i] ,dp[i-j] + abs(a[i]-a[i-j]));
				}
		}

	} 
	cout<<dp[n-1]<<"\n" ; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

int ans, n, mai;
int val, mark[1000123], f[1000123];
set<int> v;
void solve(){
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d",&val);
        f[val]++;
        v.emplace(val);
    }
    for(int x:v){
        if(!mark[x]){
            for(int j=x+x;j<=1000122;j+=x){
                //printf("%d ",j);
                mark[j]=1;
            }
        }
        if(f[x]>1)mark[x]=1;
        if(mark[x])continue;
        ans++;
        //printf("\n");
    }
    printf("%d\n", ans);
}

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1; //scanf("%d",&t);
    for(int caso=1;caso<=t;caso++){
        solve();
    }
}

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

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
v1 x;

ll ans = INF;

int main(){
    cin >> n;
    x = v1(n);
    for(ll i = 0;i < n;i++){
        cin >> x[i];
    }
    for(ll i = 1;i <= 100;i++){
        ll mem = 0;
        for(ll j = 0;j < n;j++){
            mem += (x[j]-i)*(x[j]-i);
        }
        ans = min(ans,mem);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
n, m = map(int, input().split())

l = list()
la = [0] * (n+1)
ln = [0] * (n+1)

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        la[b] = 1
    elif b == 1:
        la[a] = 1
    if a == n:
        ln[b] = 1
    elif b == n:
        ln[a] = 1

for i in range(n+1):
    if la[i]*ln[i] == 1:
        print("POSSIBLE") 
        exit()

print("IMPOSSIBLE")

Measured memory_bytes: 6132
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];

        for(int i = 0; i <= n; i++)
        	a[i] = sc.nextInt();
        for(int i = 0; i < n; i++)
        	b[i] = sc.nextInt();
        
        long cnt = 0;
        for(int i = 0; i < n; i++) {
        	int cnt1 = Math.min(a[i], b[i]);
        	cnt += cnt1;
        	a[i] -= cnt1;
        	b[i] -= cnt1;
        	if(b[i] > 0) {
        		cnt1 = Math.min(b[i], a[i+1]);
        		cnt += cnt1;
        		a[i+1] -= cnt1;
        	}
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 87972
from collections import defaultdict

n, m = map(int, input().split())

hlist = list(map(int, input().split()))
roadlist = [list(map(int, input().split())) for i in range(m)]

roadgraph = defaultdict(list)

for r in roadlist:
    roadgraph[r[0]].append(r[1])
    roadgraph[r[1]].append(r[0])

ignore_list = [0 for x in range(n + 1)]

count = 0

for i in range(1, n + 1):
    if ignore_list[i] == 0:
        # print('adj list: ', roadgraph[i])
        self = hlist[i - 1]
        skip = False
        for x in roadgraph[i]:
            if hlist[x - 1] >= self:
                skip = True
                break
        if skip:
            continue
        else:
            for x in roadgraph[i]:
                ignore_list[x] = 1
            count += 1


        # print(heights)
        # heightset = set(heights)
        # print(heightset)
        # if len(heightset) > 1:
        #     count += 1
        # print(count)

print(count)


Measured memory_bytes: 48872
import collections

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

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)
if 0 in visited:
    print("No")
else:
    print("Yes")
    print(*visited[1:], sep="\n")

Measured memory_bytes: 38396
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000;
#include <map>

using ll = long long;
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int a[202000] = {0};
    rep(i, n){
        int b;
        cin >> b;
        a[b]++;
    }
    sort(a, a+200200);

    int res=0;
    rep(i, 200200){
        if (a[i]>0) ++res;
    }



    int count=0;
    rep(i, 200200){
        if(res<=k) break;
        else if (a[i]==0) continue;
        else{
            count+=a[i];
            res--;
        }
    }
    cout << count << endl;
    }

Measured memory_bytes: 1024
//include
//------------------------------------------
#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 <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
#define EPS (1e-7)
#define DEF (1e+9 + 7)

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)





int main() {
	long long x = 1;
	long long ans;

	cin >> x;

	ans = x / 11 * 2;
	int i;
	i = x - 11 * ans / 2;
	if (i >= 7 && i <= 10) {
		ans += 2;
	}
	else if (i >= 1 && i <= 6) {
		ans++;
	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

int main() {
    int N; ll K;
    cin>>N>>K;
    vector<ll> a(N),f(N);
    ll total=0ll;
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        total+=a[i];
    }
    for (int i = 0; i < N; ++i) {
        cin>>f[i];
    }
    if(total<=K){
        cout<<0<<endl;
        return 0;
    }
    sort(a.begin(),a.end());
    sort(f.rbegin(),f.rend());
    priority_queue<pair<ll,ll>> pq;
    vector<ll> af(N);

    ll mini=0ll,maxi=(ll)1e18,mid;
    while(maxi-mini>1ll){
        mid=(mini+maxi)/2;
        ll cnt=0ll;
        for (int i = 0; i < N; ++i) {
            cnt+=max(0ll,a[i]-(ll)floor((double)mid/f[i]));
        }
        //cout<<mid<<" "<<cnt<<endl;
        if(cnt<=K){
            maxi=mid;
        }else{
            mini=mid;
        }
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		int M = keyboard.nextInt();
		int X = keyboard.nextInt();
		int[] C = new int[N];
		int[][] A = new int[N][M];
		
		for(int i=0; i<N; i++) {
			C[i] = keyboard.nextInt();
			for(int j=0; j<M; j++) {
				A[i][j] = keyboard.nextInt();
			}
		}
		
		//合計金額の暫定値
		int ans = N*100000+10;
		//最安値更新フラグ
		int flag = 0;
		
		//1:この本とこの本と(以下略)を買う、というのを0(買わない)、1(買う)で決める
		// 例:4個の箱があってそこに0と1を入れたい
		// 0000 から1ずつ足していって、1111までのすべてを試す時 
		// 1<<4によって最大値1111+1=10000を表せる
		int conN = 1 << N;
		//0b0は、bitで表した0のことで、例えば0b10なら数字の2を表せる。
		for(int c=0b0; c<conN; c++) {
			
			//2:1番で決めた組み合わせで本を買ったときに、各スキルのexpがXを超えるかを確認する
			int exp[] = new int[M];
			for(int m =0; m<M; m++) {
				for(int n=0; n<N; n++) {
				//(c>>N)で、bitの右からn桁目(0,1,2,3…)を見る (bitの並びから下n桁を削除する)
				//「右からn桁目」と「1」が両方とも1であることを「&」で確認する
					if(((c>>n)&1) == 1) {
						exp[m] += A[n][m];
					}
				}
			}//2
			
			//点数超えてるフラグ
			boolean ExpIsOK = true;
			
			for(int m2=0; m2<M; m2++) {
				//3-1:合計点数を確認してXを超える場合に、超えてるフラグをONにする
				if(exp[m2] >= X) {
				//何もしない
				}else {
					ExpIsOK = false;
				}
			}
				//3-2:本の合計金額sumが現在の合計金額より安ければansを更新する
			int sum = 0;
			if(ExpIsOK) {
				for(int n2=0; n2<N; n2++) {
					if(((c>>n2)&1) == 1) {
						sum += C[n2];
					}
				}
				if(sum < ans) {
					ans = sum;
				//3-3:ansを一度でも更新したらflagを1にする
					flag = 1;
				}
			}else {
			//3-4:1つでもXを満たせないスキルが出た時点で、次の組み合わせを確認する
			}//3
		}//1
		
		//一通り処理してflagが0(未更新、どの本の組み合わせを買ってもダメ)なら、ansを-1にする
		if(flag == 0) {
			ans = -1;
		}
		
		System.out.println(ans);
		keyboard.close();
	}
}


Measured memory_bytes: 37348
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  var params = inputs.split('\n')[0].split(' ').map(Number);
  (function(a,b,c) {
    if(a < b && b< c){
        console.log('Yes');
    }else{
    console.log('No');
    }//????????????????????????
  }(params[0],params[1],params[2])); 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

signed main(){
  int N,W; cin>>N>>W;
  vector<vector<int>> dp(110,vector<int>(100010,0));
  int v,w;
  for(int i=0;i<N;i++){
    cin>>w>>v;
    for(int j=0;j<=W;j++){
      if(j-w<0){
        dp[i+1][j]=dp[i][j];
      }else{
        dp[i+1][j]=max(dp[i][j-w]+v,dp[i][j]);
      }
    }
  }
  cout<<dp[N][W]<<endl;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    map<ll, int> mp;
    for (int i = 0; i < n; i++)
    {
        int d;
        cin >> d;
        mp[d]++;
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int t;
        cin >> t;
        if (!mp.count(t))
        {
            cout << "NO" << endl;
            return 0;
        }
        if (mp[t] <= 0)
        {
            cout << "NO" << endl;
            return 0;
        }
        mp[t]--;
    }
    cout << "YES" << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
bool solve() {
    string s; cin >> s;
    const ll n = s.size();
    vector<ll> cnt(3, 0);
    each(c, s) cnt[c-'a']++;
    sort(all(cnt), greater<ll>());
    if (cnt[1] == 0 && cnt[2] == 0) {
        return n == 1;
    }
    else if (cnt[2] == 0) {
        return n == 2;
    }
    else {
        rep(i, 3) rep(j, 3) {
            if (abs(cnt[i] - cnt[j]) > 1) return false;
        }
        return true;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (solve()) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


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

int main(){
    string W,T;
    int count = 0;
    
    cin >> W;
    while (true){
        cin >> T;
        if (T=="END_OF_TEXT") break;
        for (int i=0; i<T.size(); i++){
            if (isalpha(T[i])) T[i]=tolower(T[i]);
        }
        if (T==W) count++;
    }
    
    cout << count << "\n";
    
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;
	int n,W;
	cin>>n>>W;
	vector<int> value(n);
	vector<ll> weight(n);
	
for(int i=0;i<n;i++){
	cin>>weight[i]>>value[i];
}
ll sumval=0;
for(int i=0;i<n;i++)
sumval+=value[i];
vector<ll> dp(sumval+1, mod);
dp[0]=0;
for(int item=0;item<n;item++){
	for(ll value_already=sumval-value[item];value_already>=0;value_already--)
	dp[value_already+value[item]]=min(dp[value_already+value[item]],dp[value_already]+weight[item]);
}
int answer=0;
for(ll v=sumval;v>=0;v--){
	if(dp[v]<=W)
{
		answer=v;
	break;
}
}
cout<<answer;
}

Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[100];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
}


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


int main(){
    char str[128];

    while(scanf("%s",str)!=EOF){
        int cur=0,n=strlen(str);
        while(cur<n){
            if(str[cur]!='@')printf("%c",str[cur]);
            else{
                int t=str[++cur]-'0';
                char c=str[++cur];
                for(int i=0;i<t;i++)printf("%c",c);
            }
            cur++;
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1116
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct data{
	int x,y,v;
}a[210001];
char ch[11];
int i,j,k,n,m,w[1101][1101],t1,t2,ans;
void add(int x1,int y1,int x2,int y2,int v){
	x1++;y1++;x2++;y2++;
	w[x1][y1]++;w[x1][y2+1]--;w[x2+1][y1]--;w[x2+1][y2+1]++;
}
int main(){
	scanf("%d%d",&n,&m);memset(w,0,sizeof(w));
	for (i=1;i<=n;i++){
		scanf("%d%d%s",&a[i].x,&a[i].y,ch);a[i].v=(ch[0]=='B')?1:0;
		k=(a[i].x/m+a[i].y/m)%2;a[i].v^=k;
		a[i].x%=m;a[i].y%=m;
	}
	for (i=1;i<=n;i++){
		if (a[i].v){
			if (a[i].x<m-1) add(a[i].x+1,0,m-1,a[i].y,1);
			if (a[i].y<m-1) add(0,a[i].y+1,a[i].x,m-1,1);
		}else{
			add(0,0,a[i].x,a[i].y,1);
			if (a[i].x<m-1&&a[i].y<m-1) add(a[i].x+1,a[i].y+1,m-1,m-1,1);
		}
	}
	for (t1=2*n,t2=-2*n,i=1;i<=m;i++)
	 for (j=1;j<=m;j++){
	 	w[i][j]+=w[i-1][j]+w[i][j-1]-w[i-1][j-1];
	 	t1=min(t1,w[i][j]);t2=max(t2,w[i][j]);
	 }
	ans=max(t2,n-t1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6272
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
sa = set()
sb = set()
for a,b in AB:
    if a==1:
        sa.add(b)
    if b==N:
        sb.add(a)
s = sa & sb
print('POSSIBLE' if len(s) else 'IMPOSSIBLE')

Measured memory_bytes: 37192
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main() {
  int h,w,k;
  cin>>h>>w>>k;
  int vec[h][w];
  string s;
  for(int i=0;i<h;i++){
    cin>>s;
    for(int j=0;j<w;j++){
      if(s.at(j)=='1'){
        vec[i][j]=1;
      }
      else{
        vec[i][j]=0;
      }
    }
  }
  int sumb[h][w]; //[h][0]kara[h][w]番目までにいくつ
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j==0){
        sumb[i][j]=vec[i][j];
        continue;
      }
      sumb[i][j]=sumb[i][j-1]+vec[i][j];
    }
  }
  int sumc[h][w];
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      if(j==0){
        sumc[j][i]=sumb[j][i];
      }
      else{
        sumc[j][i]=sumc[j-1][i]+sumb[j][i];
      }
    }
  }
  int ans=10000,p=0;
  int vecc[h-1]; //vecc[i]=1 between i,i+1 cut
  int vecb[h]; //i行目切る前何個
  int vecd[h]; //
  int vece[h];
  for(int bit=0;bit<(1<<h-1);bit++){
    for(int i=0;i<h;i++){
      vecb[i]=0;
      vecd[i]=0;
      vece[i]=0;
    }
    for(int i=0;i<h-1;i++){
      if(bit&(1<<i)){
        vecc[i]=1;
        p++;
      }
      else{
        vecc[i]=0;
      }
    }
    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
        vecd[j]=sumb[j][i]-vecb[j];
        vece[j]=vecd[j];
      }
      for(int j=0;j<h-1;j++){
        if(vecc[j]==0){
          vece[j+1]+=vece[j];
        }
      }
      for(int j=0;j<h;j++){
        if(vece[j]>k){
          p++;
          if(i==0){
            p+=100000;
            break;
          }
          for(int a=0;a<h;a++){
            vecb[a]=sumb[a][i-1];
          }
          break;
        }
      }
    }
    //cout<<bit<<" "<<p<<endl;
    ans=min(ans,p);
    p=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#!/usr/bin/perl
my ($a,$b) = map { $_ - 0 } split(/\s+/,<STDIN>);
if( $a==0 || $a==$b ){
  print "$b\n";  exit(0);
}
my $rc = 0;
my $ad = 1;
for(my $i=0;$i<42;$i++){
  my $bc = &f($b,$i) - &f($a-1,$i);
  $rc += $ad if $bc % 2 == 1;
  $ad += $ad;
}
print "$rc\n";
exit(0);
sub f {
  my $v = shift;
  my $b1 = 1 << shift;
  my $b2 = $b1 + $b1;
  my $v1 = $v % $b2;
  my $bc = ( $v - $v1 )/2;
  $bc += 1 + $v1 - $b1 if $v1 >= $b1;
  return $bc;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;

	private void mainrun() {
		scan = new Scanner(System.in);

		double a,b,c,d,e,f;
		double x = 0,y;

		while(scan.hasNext()) {
			a = scan.nextDouble();
			b = scan.nextDouble();
			c = scan.nextDouble();
			d = scan.nextDouble();
			e = scan.nextDouble();
			f = scan.nextDouble();

			x = (c * e - b * f) / (a * e - b * d);
			y = (c / b) - (a / b ) * x;

			if(x == -0) { x = 0;}
			if(y == -0) { y = 0;}

			System.out.println(String.format("%.3f", x) + " " + String.format("%.3f", y));
		}

		scan.close();

	}

}


Measured memory_bytes: 28396
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator


#define MOD 1000000009LL
#define EPS 1e-8

vvint G;
vint vis;

void dfs(int v){
	if(vis[v] == 1){ throw v; }
	if(vis[v] == 0){
		vis[v] = 1;
		for(int i = 0; i < G[v].size(); ++i){
			dfs(G[v][i]);
		}
		vis[v] = 2;
	}
}

int main(){
	int n, m, k, s, t;
	char rel[8] = "";
	scanf("%d%d", &n, &m);
	G.resize(n);
	vis.resize(n);

	vvint a, b;
	initvv(a, n, m, 0);
	initvv(b, n, m, 100);

	for(int i = 0; i < n; ++i){
		scanf("%d", &k);
		for(int j = 0; j < k; ++j){
			scanf("%d %s %d", &s, rel, &t);
			--s;
			
			if(rel[0] == '>'){
				a[i][s] = max(a[i][s], t);
			}
			else{
				b[i][s] = min(b[i][s], t);
			}
		}
	}

	bool ok = false;
	try{
		for(int i = 0; i < n; ++i){
			for(int k = 0; k < m; ++k){
				for(int j = 0; j < n; ++j){
					if(b[i][k] < a[j][k]){
						G[i].push_back(j);
					}
				}
			}
		}
		
		for(int i = 0; i < n; ++i){
			dfs(i);
		}
		
		ok = true;
	}catch(...){}
	
	puts(ok ? "Yes" : "No");
}

Measured memory_bytes: 2060
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	long int a[100005];
	map<int, int> m;
	for(int i=0;i<n;i++){
		cin >> a[i];
		m[a[i]]++;
	}
	int count = 0;
	for(auto kv:m){
		if(kv.first==kv.second){
			continue;
		}
		if(kv.second!=0 && kv.first<kv.second){
			count += kv.second-kv.first;
		}
		if(kv.second!=0 && kv.first>kv.second)
			count += kv.second;
	}
	cout << count << endl;
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a%3 && b%3 && (a+b)%3) cout << "Impossible\n";
  else cout << "Possible\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main(){
	int c[] = {6, 4, 3, 2};
	rep(i, 4){
		int a, b;
		cin >> a >> b;
		cout << c[a-1]*b*1000ll << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  int n;
  cin>>n;

  vector<char> a(n);
  vector<char>b(n);
  vector<char>c(n);
  
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }

  for(int i=0;i<n;i++){
    cin>>b.at(i);
  }

  for(int i=0;i<n;i++){
    cin>>c.at(i);
  }

  int cnt=0;
  for(int i=0;i<n;i++){
    if(a.at(i)==b.at(i)&&a.at(i)==c.at(i))
      cnt=cnt;
    else if(a.at(i)==b.at(i))
      cnt++;
    else if(b.at(i)==c.at(i))
      cnt++;
    else if(c.at(i)==a.at(i))
      cnt++;
    else
      cnt+=2;
  }

  cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 3572
S = list(input())
N = len(S)

c=0
i=0
f=0
while(1):
    if i+1 == N or N < 2:
        break
    if S[i] != S[i+1]:
        del S[i:i+2]
        c += 2
        N -= 2
        if i >= 1:
            i -= 2
        else:
            i -= 1
    i += 1
    #print(i,N,S,f)                                                                      
print(c)

Measured memory_bytes: 3956
n,x=map(int,input().split())
ln= list(map(int, input().split()))
result=[]
for i in range(0,100000):
    a=ln[:i]
    b=sum(a)
    result.append(b)
    if b>x:
        break
e=len(result)

if e>n+1:
    print(n+1)
else:
    print(e-1)

Measured memory_bytes: 7064
s = input()
t = input()
N = len(s)
M = len(t)

dp = [[0]*(N+1) for i in range(M+1)]

for i in range(1,M+1):
  for j in range(1,N+1):
    if s[j-1] == t[i-1]:
      dp[i][j] = dp[i-1][j-1]+1
    else:
      dp[i][j] = max(dp[i-1][j],dp[i][j-1])
L = dp[-1][-1]
i = M
j = N
ans = [""]*L
cur = L-1
while i>=0 and j>=0:
  if dp[i][j] != dp[i-1][j] and dp[i][j] != dp[i][j-1]:
    ans[cur] = s[j-1]
    i -= 1
    j -= 1
    cur -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    j -= 1
print("".join(ans))

Measured memory_bytes: 112476
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long pow_5(long x){
    return x*x*x*x*x;
}

bool b_able(long b, long x){
    if(pow_5(b+1) -  pow_5(b) <= x){
        return true;
    }else{
        return false;
    }
}

int main(){
    long x;
    scanf("%ld", &x);
    for(long b = 1; b_able(b, x); b++){
        for(long a = b+1; pow_5(a) - pow_5(b) <= x; a++){
            if(pow_5(a) - pow_5(b) == x){
                printf("%ld %ld\n", a, b);
                return 0;
            }
        }
    }
    for(long a = 0; pow_5(a) <= x; a++){
        for(long b = 1; pow_5(a) + pow_5(b) <= x; b++){
            if(pow_5(a) + pow_5(b) == x){
                printf("%ld -%ld\n", a, b);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int main(void){
  int A, B, C;
  cin >> A >> B >> C;
  // 入力終了

  // Ax = By + C
  // となるx，yがあるかを全探索
  // ただし，xはBまで，yはAまで見ればOK
  
  for(int x=0; x<=B; x++){
    for(int y=0; y<=A; y++){
      if(A*x == B*y+C){
	cout << "YES" << endl;
	return 0;
      }
    }
  }

  // 該当なし
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> cvec;
    rep(i,h) {
        string c;
        cin >> c;
        cvec.push_back(c);
    }
    rep(i,h) {
        cout << cvec[i] << endl;
        cout << cvec[i] << endl;
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
/*
部分問題を考えるといい
回答かしけぇ〜
*/
#define max 9223372036854775807

long long Max(long long a,long long b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

void merge(long long *a,int left,int mid,int right){
        int n1 = mid - left;
        int n2 = right - mid;
        long long L[n1+1],R[n2+1];
        int i;
        for(i=0;i<n1;i++){
            L[i] = a[left + i];
        }
        for(i=0;i<n2;i++){
            R[i] = a[mid + i];
        }
        L[n1]=max;
        R[n2]=max;
        int j=0,k=0;
        for(i=left;i<right;i++){
            if(L[j]<R[k]){
                a[i] = L[j];
                j++;
            }
            else{
                a[i] = R[k];
                k++;
            }
        }

}


void merge_sort(long long *a,int left,int right){
    int middle;
    if(left + 1 < right){
        middle = (left + right)/2;
        merge_sort(a,left,middle);
        merge_sort(a,middle,right);
        merge(a,left,middle,right);
    }
}


int main(void){
    int i,N,M;
    scanf("%d %d",&N,&M);
    long long x[N],y[N],z[N],val1[N],val2[N],val3[N],val4[N],val5[N],val6[N],val7[N],val8[N];
    for(i=0;i<N;i++){
        scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
        val1[i]=x[i]+y[i]+z[i];
        val2[i]=((-1)*x[i])+y[i]+z[i];
        val3[i]=x[i]+((-1)*y[i])+z[i];
        val4[i]=x[i]+y[i]+((-1)*z[i]);
        val5[i]=x[i]+(-1)*(y[i]+z[i]);
        val6[i]=y[i]+(-1)*(x[i]+z[i]);
        val7[i]=z[i]+(-1)*(x[i]+z[i]);
        val8[i]=(-1)*val1[i];
    }
    merge_sort(val1,0,N);
    merge_sort(val2,0,N);
    merge_sort(val3,0,N);
    merge_sort(val4,0,N);
    merge_sort(val5,0,N);
    merge_sort(val6,0,N);
    merge_sort(val7,0,N);
    merge_sort(val8,0,N);
    for(i=N-1;i>0;i--){
        val1[i-1]+=val1[i];
        val2[i-1]+=val2[i];
        val3[i-1]+=val3[i];
        val4[i-1]+=val4[i];
        val5[i-1]+=val5[i];
        val6[i-1]+=val6[i];
        val7[i-1]+=val7[i];
        val8[i-1]+=val8[i];
    }
    long long ans = Max(Max(Max(val1[N-M],val2[N-M]),Max(val3[N-M],val4[N-M])),Max(Max(val5[N-M],val6[N-M]),Max(val7[N-M],val8[N-M])));
    printf("%lld\n",ans);


    return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			int m = sc.nextInt();
			int [] t = new int[m];
			for(int i = 0; i < m; i++){
				t[i] = sc.nextInt();
			}
			
			Arrays.sort(data);
			Arrays.sort(t);
			int ind = 0;
			boolean flg = true;
			for(int i = 0; i < t.length;i++){
				while(true){
					if(t[i] == data[ind]){
						ind++;
						break;
					}
					ind++;
					if(ind >= n){
						flg = false;
						break;
					}
				}
				if(!flg) break;
					
				
			}
			System.out.println(flg ? "YES" :"NO");
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 92088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int n;
	cin>> n;
	int m4=0,m2=0;
	rep(i,n)
	{
		int a;cin >> a;
		if(a%4==0)
		{
			m4++;
			continue;
		}
		if(a%2==0)
		{
			m2++;
		}
	}
	n-= 2*m4;
	if(n<2)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(n-m2<=0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

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

int cnt,m;
vector<int> G;

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

void shellSort(vector<int>& a,int n) {
	cnt = 0;
	m=0;
	int d=n;
	G.resize(n);
	while(1) {
		d=2*d/3;
		if(d<2) {
			G[m]=d;
			++m;
			break;
		}
		G[m]=d;
		++m;
	}
	for(int i=0; i<m; ++i) {
		insertionSort(a, n, G[i]);
	}
}

int main() {
	int n;
	vector<int> a;
	scanf("%d",&n);
	a.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&a[i]);
	}
	shellSort(a,n);
	printf("%d\n",m);
	for(int i=0; i<m-1; ++i) {
		printf("%d ",G[i]);
	}
	printf("%d\n%d\n",G[m-1],cnt);
	for(int i=0;i<n;++i) {
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 10008
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;
int k;

int dp[310][310][310];

int calc(int l, int r, int x) {
    if (l == r) return 1;
    if (l > r) return 0;
    if (dp[l][r][x] < 0) {
        int res = 0;
        if (s[l] == s[r]) {
            res = calc(l+1, r-1, x) + 2;
        } else if (x > 0) {
            res = calc(l+1, r-1, x-1) + 2;
        }
        res = max(res, calc(l+1, r, x));
        res = max(res, calc(l, r-1, x));
        
        dp[l][r][x] = res;
    }
    return dp[l][r][x];
}

int solve() {
    memset(dp, -1, sizeof(dp));
    return calc(0, (int)s.size()-1, k);
}

void input() {
    cin >> s >> k;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 119968
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

n,x = map(int,input().split())
a = list(map(int,input().split()))
d = []
ans = 0
for i in range(n-1):
    d = a[i+1] + a[i]
    if d>=x:
        if a[i+1]>=d-x:
            a[i+1] = a[i+1] - (d-x)
            ans += d-x
        else:
            a[i+1] = 0
            a[i] -= d-x-a[i+1]
            ans += d-x-a[i+1]
    else:
        continue
print(ans)


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

int sum_of_digits(int a) {
    int sum = 0;
    while (a != 0) {
        int x;
        x = a % 10;
        sum = sum + x;
        a = a/10;
    }
    return sum;
}

int main() {

    int N;

    cin >> N;

    int B;
    vector<int> sums;

    for (int i = 1; i < N; i++) {
        B = N - i;
        int x;
        x = sum_of_digits(i) + sum_of_digits(B);
        sums.push_back(x);
    }

    cout << *min_element(sums.begin(), sums.end()) << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P; 
#define INF 100000000
const int MAX = 1000000;
const int MOD = 1000000007;
bool prime(int n){
    for(int i=2;i<=sqrt(n)+1;i++){
        if(n==1) return false;
        else if(n==2) return true;
        if(n%i==0) return false;
    }
    return true;
}
int main(){
   int x;
   cin>>x;
   while(!prime(x)){
       x++;

   }
   OUT(x);
    return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d[i];
    }
    sort(d.begin(),d.end());

    int ans=d[n/2]-d[n/2-1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N = int(input())
ls = list(map(int,input().split()))
keta = []
ans = 'a'
j = 0
while ans == 'a':
    for i in range(N):
        if ls[i]%2 == 0:
            ls[i] = ls[i]//2
        else:
            ans = j
            break
    j += 1
print(ans)

Measured memory_bytes: 9112
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

n = int(input())

c = []
k=0
for i in range(n):
    
    while(not is_prime(5 * k + 2)):
        k = k + 1
    
    c.append(5 *k + 2)
    k=k+1

print(' '.join(map(str, c)))
    
    

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[2]==s[3]&&s[4]==s[5]&&s[1]!=s[2])
        {
            cout<<"Yes"<<endl;
            break;
        }
        else
            cout<<"No"<<endl;
            break;
    }
    return 0;
}


Measured memory_bytes: 256
/**
            ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
            <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

    ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
    ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/

#include <bits/stdc++.h>

#define sz(s) s.size()
#define pb push_back
#define fr first
#define sc second
#define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e5 + 5;

long long a, b;

main()
{
    cin >> a >> b;
    cout << abs( a * b - ( ( a + b ) * 2 - 4 ) );
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define all(a) (a).begin(),(a).end()
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; in(H); in(W);

  map<char, int> m;
  rep(i, H) rep(j, W) {
    char a;
    in(a);
    ++m[a];
  }
  int board[H][W];
  rep(i, (H+1)/2) {
    board[i][0] = board[i][W-1] = i*W;
    board[H-1-i][0] = board[H-1-i][W-1] = i*W;
    loop(j, 1, (W+1)/2) {
      board[i][j] = board[i][W-1-j] = board[i][j-1] + 1;
      board[H-1-i][j] = board[H-1-i][W-1-j] = board[i][j-1] + 1;
    }
  }
  map<int, int> m2;
  rep(i, H) rep(j, W) {
    ++m2[board[i][j]];
  }
  priority_queue<int> q, q2;
  iter(it, m) {
    q.push(it->second);
  }
  iter(it, m2) {
    q2.push(it->second);
  }
  while (!q2.empty()) {
    int p2 = q2.top(); q2.pop();
    int p = q.top(); q.pop();
    if (p2 > p) {
      out("No");
      return 0;
    }
    q.push(p - p2);
  }
  out("Yes");

  return 0;
}


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

int main(){
  int X;
  cin >>X;
  bool suc = 0;
  if (X == 7) suc = 1;
  if (X == 5) suc = 1;
  if (X == 3) suc = 1;
  string ans = (suc) ? "YES" : "NO";
  cout << ans << endl;
}

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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public void go() throws IOException
    {
        StringTokenizer tok = new StringTokenizer(in.readLine());
        int a = Integer.parseInt(tok.nextToken());
        int b = Integer.parseInt(tok.nextToken());
        out.println(Math.max(Math.max(a+b, a-b), a*b));

        out.flush();
        in.close();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int ans;
    rep(i, 4) ans += s[i] == '+' ? 1 : -1;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000010
#define eps 1e-7
#define fir first
#define sec second
#define pb push_back
#define MP make_pair
#define LL long long
#define MOD 1000000007
#define inf 2147483647
#define For(i,x,y) for(int i=(x);i<(y);++i)
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define drep(i,x,y) for(int i=(x);i>=(y);--i)
inline int read(){char ch=getchar();int x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline LL llread(){char ch=getchar();LL x=0,f=1;while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
int main(){
	int A=read(),B=read(),C=read();
	LL ans=min(B,C);
	B-=ans;C-=ans;ans*=2;
	if(B==0){
		ans+=min(A,C);
		if(C>A)++ans;
	}
	else{
		ans+=B;
	}
	cout<<ans;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n;
vl a;
vl b;

int main(){
  cin >> n;
  a = vl(n+1);
  b = vl(n+1);
  for(ll i = 1;i <= n;i++) cin >> a.at(i);
  for(ll i = n;i >= 1;i--){
    ll cnt = 0;
    for(ll j = 1;j*i <= n;j++){
      cnt += b.at(j*i);
    }
    if(cnt%2 == a.at(i)) continue;
    else b.at(i) = 1;
  }
  cout << accumulate(b.begin(),b.end(),0ll) << endl;
  for(ll i = 1;i <= n;i++){
    if(b[i] == 1) cout << i << " ";
  }
  cout << endl;

}


Measured memory_bytes: 3968
package main

import "fmt"

var mod = 1000000007

func isAGC(a int, b int, c int) bool {
	return a == 0 && b == 1 && c == 2
}
func isOK(c int, l int) bool {
	var a [10]int
	for i := l - 1; i >= 0; i-- {
		a[i] = c % 4
		c /= 4
	}
	for i := 1; i+1 < l; i++ {
		if isAGC(a[i-1], a[i], a[i+1]) || isAGC(a[i], a[i-1], a[i+1]) || isAGC(a[i-1], a[i+1], a[i]) {
			return false
		}
		if i-2 >= 0 && isAGC(a[i-2], a[i], a[i+1]) {
			return false
		}
		if i+2 < l && isAGC(a[i-1], a[i], a[i+2]) {
			return false
		}
	}
	return true
}
func main() {
	var N int
	_, _ = fmt.Scan(&N)
	var a [101][64]int
	for i := 0; i < 64; i++ {
		if i == 6 || i == 9 || i == 18 {
			continue
		}
		a[3][i] = 1
	}
	for i := 4; i <= 100; i++ {
		for j := 0; j < 64; j++ {
			for k := 0; k < 4; k++ {
				if isOK(j*4+k, 4) {
					a[i][(j*4+k)%64] += a[i-1][j]
					a[i][(j*4+k)%64] %= mod
				}
			}
		}
	}
	var ans = 0
	for i := 0; i < 64; i++ {
		ans += a[N][i]
		ans %= mod
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
// #define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    vector<ll> a(n);
    f(i,0,n)
        cin>>a[i];
    ll dp[n];
    f(i,0,n)
        dp[i]=INT_MAX;
    dp[0]=0;
    f(i,0,n-1){
        dp[i+1]=min(dp[i+1],abs(a[i+1]-a[i])+dp[i]);
        if(i+2<n)
            dp[i+2]=min(dp[i+2],abs(a[i+2]-a[i])+dp[i]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
var s:ansistring;
    i:longint;
    n,l,r:longint;
    ans:int64;
begin
  readln(s);
  n:=length(s);
  l:=1;
  r:=n;
  while l<r do
  begin
    if (s[l]<>s[r]) then
    begin
      if (s[l]='x') then
      begin
        inc(ans);
        inc(l);
      end else
      if (s[r]='x') then
      begin
        inc(ans);
        dec(r);
      end else
      begin
        writeln(-1);
        exit;
      end;
    end else
    begin
      inc(l);
      dec(r);
    end;
  end;
  writeln(ans);
end.

Measured memory_bytes: 256
main = do
  [sx,sy,tx,ty] <- map read . words <$> getLine :: IO [Int]
  let hori = tx-sx
  let vert = ty-sy
  let there1 = up vert ++ right hori
  let back1 = down vert ++ left hori
  let there2 = "L" ++ up vert ++ "UR" ++ right hori ++ "D"
  let back2 = "R" ++ down vert ++ "DL" ++ left hori ++ "U"
  putStrLn $ there1 ++ back1 ++ there2 ++ back2
    where
      up = flip replicate 'U'
      down = flip replicate 'D'
      right = flip replicate 'R'
      left = flip replicate 'L'


Measured memory_bytes: 1020
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)
    ans = 1000
    for i in range(N-M+1):
        cnt = 0
        for j in range(M):
            if S[i+j] != T[j]:
                cnt += 1
        if cnt < ans:
            ans = cnt
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 73408
#include <stdio.h>

int main(){
    int n, a[100000], i, cnt=0;

    scanf("%d", &n);

    for(i=0; i<n; i++)
        scanf("%d", &a[i]);

    i=1;

    do{
        cnt++;

        if(a[i-1] == 2){
            printf("%d\n", cnt);
            return 0;
        }

        i = a[i-1];

    }while(cnt <= n);

    printf("-1\n");

    return 0;
}

Measured memory_bytes: 512
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
h = inpl()
g = [[] for _ in range(n)]
for _ in range(m):
    a,b = inpl()
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)
res = 0
for i in range(n):
    for j in g[i]:
        if h[j] >= h[i]:
            break
    else:
        res += 1
print(res)

Measured memory_bytes: 100528