akhauriyash/Code-Regression huggingface dataset:
import Control.Arrow
import Data.List
import qualified Data.IntMap.Strict as M

main = do
  getLine
  as <- map read . words <$> getLine
  print (together as)

(!?) m k = M.findWithDefault 0 k m

together as = foldr (\a acc -> max acc (ans!?a + ans!?(a-1) + ans!?(a+1))) 0 [minimum as .. maximum as]
  where
     ans = M.fromDistinctAscList $ map (head &&& length) $ group $ sort as



Measured memory_bytes: 27004
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

string st;
int ait;
vector<int>getnum() {
	vector<int>nums;
	while (ait != st.size()&&st[ait] != '+' && st[ait] != '=') {
		if (st[ait] == 'X') {
			nums.emplace_back(-1);
		}
		else {
			nums.emplace_back(st[ait] - '0');
		}
		ait++;
	}
	return nums;
}
int main() {
	while (getline(cin, st)) {
		vector<vector<int>>nums(3);
		{
			ait = 0;
			nums[0] = getnum();
			ait++;
			nums[1] = getnum();
			ait++;
			nums[2] = getnum();
		}
		bool zero_ok = true;
		for (int i = 0; i < 3; ++i) {
			if (nums[i].size()>=2&&nums[i][0] == -1)zero_ok = false;
		}

		
		size_t max_size = max(nums[0].size(), max(nums[1].size() ,nums[2].size()))+1;
		for (int i = 0; i < 3; ++i) {
			int rest = max_size - nums[i].size();
			for (int j = 0; j < rest; ++j) {
				nums[i].insert(nums[i].begin(),0);
			}
		}

		int ans = -1;
		for (int x = 0; x < 10; ++x) {
			if (!x&&!zero_ok)continue;
			else {
				vector<vector<int>>anums(nums);
				for (auto& anum : anums) {
					for (auto& n : anum) {
						if (n == -1)n = x;
					}
				}
				vector<int>sum(max_size);
				for (int i = 0; i < sum.size(); ++i) {
					sum[i] = anums[0][i] + anums[1][i];
				}
				for (int i = sum.size()-1; i >0; --i) {
					int up = sum[i] / 10;
					sum[i] %= 10;
					sum[i - 1] += up;
				}
				if (sum == anums[2]) {
					ans = x;
					break;
				}
			}
		}
		if (ans == -1) {
			cout << "NA" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

int main()
{
    set<ll> a;
    for (ll i = 0; i < 3; i++)
    {
        ll x;
        cin >> x;
        a.insert(x);
    }

    println(a.size());
}

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

typedef long long ll;
const int mod = 998244353;
char s[105];
int n;
ll g[105];
map<ll, int> f[52];
ll calc(ll d, int m) {
	if (!m) return 1;
	if (f[m].find(d) != f[m].end()) return f[m][d];
	ll ret = ((d & 1) + 1) * calc(d >> 1, m - 1) % mod;
	for (int j = 1; j <= m; j++) {
		for (int k = 2; j * k <= m; k++) {
			ll d2 = (1 << j) - 1, d3 = d;
			for (int u = 1; u <= k; u++) {
				d2 &= d3;
				d3 >>= j;
			}
			ret = (ret + (ll)calc(d2, j) * calc(d3, m - j * k) % mod) % mod;
		}
	}
	return f[m][d] = ret;
}

int main() {
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; i++) s[i] -= '0';
	g[n] = 1;
	for (int i = n - 1; ~i; i--) {
	//	cout << i << endl;
		g[i] = (s[i] + 1) * g[i + 1] % mod;
		for (int j = 1; j <= n - i; j++) {
			for (int k = 2; k * j <= n - i; k++) {
				ll d = (1ll << j) - 1;
				for (int u = 0; u < j * k; u++) {
					d &= ~((ll)!s[i + u] << (u % j));
				}
				g[i] = (g[i] + calc(d, j) * g[i + j * k]) % mod;
			}
		}
		
	//	cout << g[i] << " " << endl;
	}
	cout << g[0] << endl;
}

Measured memory_bytes: 3072
A,B = map(int,input().split())
L = ['0','1','2','3','4','5','6','7','8','9']
s = str(input())
for i in range(len(s)):
  if i == A:
    if s[A] != '-':
      print('No')
      exit()
  else:
    b = s[i]
    if b not in L:
      print('No')
      exit()
print('Yes')
      


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    int n,k;
    cin>>n>>k;
    Vi a(n+1,0),b(n+1);
    REP(i,1,n+1) cin>>a[i];
    REP(i,1,n+1) b[i]=b[i-1]+a[i];
    
    set<int> se;
    REP(i,0,n+1) REP(j,i+1,n+1) se.insert(b[j]-b[i]);
    for(int mask=(1ll<<60); mask>0; mask>>=1){
        set<int> se2;
        for(auto x : se) if(x&mask) se2.insert(x);
        if(se2.size()>=k) se=se2;
    }
    int ans=*se.begin();
    for(auto x : se) ans&=x;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(void){
  int size;
  cin>>size;

  vector<int64_t> vec(size+1);
  vec.at(0)=2;
  vec.at(1)=1;
  for(int i=2;i<=size;i++){
    vec.at(i)=(vec.at(i-1)+vec.at(i-2));
  }
  cout<<vec.at(size)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
 
int main() {
	int n;
	string s;
	cin>>n>>s;
	vector<int> whsum(n+1,0);
	vector<int> blsum(n+1,0);
	rep(i,n){
		whsum[i+1]=whsum[i]+(s[i]=='.' ? 1 : 0);
		blsum[i+1]=blsum[i]+(s[i]=='#' ? 1 : 0);
	}

	ll res=INF;
	for(int left=0;left<=n;left++){
		ll tmp=0;
		tmp+=blsum[left]-blsum[0];
		tmp+=whsum[n]-whsum[left];
		res=min(res,tmp);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 2180
s = input()
ans = 0
mita = set()
def f(x):
        global ans
        if x in mita:
                return
        ans += eval(x)
        mita.add(x)
        for i in range(1,len(x)):
                if x[i-1] != "+" and x[i] != "+":
                        f(x[:i]+"+"+x[i:])
f(s)
print(ans)

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

using namespace std;

const int MAXN = 100010;
int N;
int H[MAXN];

int DP[MAXN];

int main(){

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    DP[1] = abs(H[1] - H[1 - 1]);

    for (int i = 2; i < N; i++) {
        DP[i] = min(
                    DP[ i - 1] + abs(H[i] - H[i - 1]),
                    DP[i - 2] + abs(H[i] - H[i - 2]));
    }

    cout << DP[N - 1];



    return 0;
}


Measured memory_bytes: 1024
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for h in range(H) :
        if h == 0 or h == H-1 :
            print("#" * W)
        else :
            print("#", "." * (W-2), "#", sep="", end="")
            print()
    print()



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

namespace arc098_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var WL = new int[N];
            var EL = new int[N];

            var ec = 0;
            for (int i = 0; i < N; i++) 
            {
                if (S[i] == 'E') ec++;
                EL[i] = ec;
            }

            var wc = 0;
            for (int i = N-1; i >= 0; i--)
            {
                if (S[i] == 'W') wc++;
                WL[i] = wc;
            }

            int rm = int.MaxValue;
            for (int i = 0; i < N; i++)
            {
                int r = 0;
                r += WL[0] - WL[i];
                r += EL.Last() - EL[i];
                if (rm > r) rm = r;
            }

            Console.WriteLine(rm);

        
        }
    }
}


Measured memory_bytes: 14560
// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> r(n, 0), g(n, 0), b(n, 0);
    vector<ll> r_rui(n + 1, 0), g_rui(n + 1, 0), b_rui(n + 1, 0);
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') {
            r[i] = 1;
        }
        if(s[i] == 'G') {
            g[i] = 1;
        }
        if(s[i] == 'B') {
            b[i] = 1;
        }
    }
    for(int i = 0; i < n; i++) {
        r_rui[i + 1] = r_rui[i] + r[i];
        g_rui[i + 1] = g_rui[i] + g[i];
        b_rui[i + 1] = b_rui[i] + b[i];
    }
    ll ans = 0;
    for(int j = 1; j < n - 1; j++) {
        ll tmp = 0;
        if(s[j] == 'R') {
            tmp += g_rui[j] * (b_rui[n] - b_rui[j]);
            tmp += b_rui[j] * (g_rui[n] - g_rui[j]);
        }
        if(s[j] == 'G') {
            tmp += r_rui[j] * (b_rui[n] - b_rui[j]);
            tmp += b_rui[j] * (r_rui[n] - r_rui[j]);
        }
        if(s[j] == 'B') {
            tmp += r_rui[j] * (g_rui[n] - g_rui[j]);
            tmp += g_rui[j] * (r_rui[n] - r_rui[j]);
        }
        ll t2 = 0;
        for(int p = 0; p < n; p++) {
            if(j + p < n && j - p >= 0) {
                if(s[j - p] != s[j] && s[j - p] != s[j + p] &&
                   s[j] != s[j + p]) {
                    t2++;
                }
            }
        }
        tmp -= t2;
        ans += tmp;
    }
    cout << ans << endl;
}


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

using P = pair<ll,ll>;
#define v first
#define w second

// v/w 高い順
bool comp1(P a, P b){
    return a.v*b.w > b.v*a.w;
}

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}

int main(void){
    ll N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>v>>w;
        a[i] = {v,w};
    }
    // sort(all(a),comp1);
    vector<P> dp = {{0,0}};

    // ll max_state = 0;
    rep(i,N){
        vector<P> tmp;
        for(auto& s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(auto& s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
        // if((ll)dp.size() > N) dp.resize(N);
        // max_state = max(max_state,(ll)dp.size());
        assert((ll)dp.size() <= N*N+1);
    }
    // cout<<max_state<<endl;
    cout<<dp[0].v<<endl;
    return 0;
}



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

typedef long long ll;
ll N, K, Q;
const ll MAX_N = 100000;
ll P[MAX_N];
int main() {
  cin >> N >> K >> Q;
  for (ll i = 0; i < Q; ++i) {
    ll a;
    cin >> a;
    --a;
    ++P[a];
  }
  for (ll i = 0; i < N; ++i) {
    P[i] += K;
    P[i] -= Q;
    cout << (P[i] > 0 ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 1408
a = gets.chomp.split("").map(&:to_i)

nmod = 0
#test = 0

a.each do |e|
  nmod = (nmod+e) % 9
  #test += e
  #p test
  #p nmod
end

#puts("#{test % 9}")
#puts("#{nmod}")

if nmod == 0
  puts("Yes")
else
  puts("No")
end

Measured memory_bytes: 26388
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  vector<string> a(110);
  cin >> n >> l;
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(int i=0; i<a.size(); i++) cout << a[i];
  cout << endl;
}
  

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

int main() {
  int N;
  cin >> N;
  
  vector <int> moti(N);
  
  for (int i = 0; i < N; i++){
    cin >> moti.at(i);
  }
  
  sort (moti.begin(),moti.end());
  //reverse (moti.begin(),moti.end());
  
  int kasane = 1;
    
  for (int i = 1; i < N; i++){
    int mae = i - 1;
    if( moti.at(i) > moti.at(mae) ) {
      kasane += 1;
    }
    
    
  }   
    cout << kasane <<endl;
  
}

Measured memory_bytes: 256
a=int(input())
b=[int(input()) for i in range(a)]
b.sort()
c=sum(b)
d=0
if c%10!=0:
  print(c)
else:
  for i in range(a):
    if b[i]%10!=0:
      c=c-b[i]
      print(c)
      break
  if sum(b)==c:
    print(0)

Measured memory_bytes: 9116
#include "bits/stdc++.h"

using ll = long long;
using namespace std;

void solve() {
   int p;
   int n;
   cin >> n >> p;

   vector <int> v(n);
   int even = 0;
   int odd = 0;
   for(int i = 0; i < n; i++) {
      cin >> v[i];
      v[i] %= 2;
      even += v[i] == 0;
      odd += v[i] == 1;
   }

   if(odd == 0) {
      if(p == 1) {
         cout << 0 << endl;
      } else {
         cout << (1LL << n) << endl;
      }
   } else {
      cout << (1LL << (n - 1)) << endl;
   }
}


int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   }
 
   return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextInt();
		long[] A = new long[N + 1];
		A[0] = 0;
		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt() + A[i - 1];
		}
		long[] B = new long[M + 1];
		B[0] = 0;
		for (int i = 1; i <= M; i++) {
			B[i] = sc.nextInt() + B[i - 1];
		}

		int result = 0;
		int maxB = M;
		for (int i = 0; i <= N && A[i] <= K; i++) {
			long K2 = K - A[i];
			for (int j = maxB; j >= 0; j--) {
				if (B[j] <= K2) {
					if (result < i + j)
						result = i + j;
					maxB = j;
					break;
				}
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 62836
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int a,b; cin >>a >>b;
  cout <<a*b <<endl;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	string s; cin >> s;


	if(stoi(s.substr(5, 2)) >= 5){
		cout << "TBD" << endl;
	}else{
		cout << "Heisei" << endl;
	}
	
	return 0;
}

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

int main(){
    map<string,int> m;
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 1ll << 60;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for(ll &e : A) cin >> e;
    for(ll &e : B) cin >> e;
    vector<ll> dig;
    for(ll K = 53; K >= 1; K--){
        vector<vector<ll>> dis(60, vector<ll>(60, INF));
        for(ll i = 0; i < 60; i++) dis[i][i] = 0;
        for(ll d : dig) for(ll i = 0; i < 60; i++) dis[i][i % d] = 0;
        for(ll i = 0; i < 60; i++) for(ll k = K - 1; k >= 1; k--) dis[i][i % k] = min<ll>(dis[i][i % k], 1ll << k);
        for(ll k = 0; k < 60; k++) for(ll i = 0; i < 60; i++) for(ll j = 0; j < 60; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        bool suc = 1;
        for(ll i = 0; i < N; i++) suc &= (dis[A[i]][B[i]] != INF);
        if(K == 53 && !suc){
            cout << -1 << endl;
            return 0;
        }
        if(!suc) dig.push_back(K);
    }
    ll ans = 0;
    for(ll d : dig) ans += (1ll << d);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

int main(){
    int s,w;
    cin >> s >> w;
    if(w>=s)
        cout << "unsafe";
    else
        cout << "safe";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
 ll a,b; cin>>a>>b;
  ll x=GCD(a,b);
  set<ll>S;
  for(auto p : prime_factor(x)) {
    while(p.second--) S.insert(p.first);
  }
  cout <<1+S.size()<< endl;
  
}

Measured memory_bytes: 256
fun main(){
    val r = readLine()!!.split(" ")
    val a = r[0].toLong()
    val b = r[1].toDouble()

    //println((b * 100).toBigDecimal())
    val res = (a * (b.toBigDecimal() * 100.toBigDecimal()).toLong()) / 100
    println(res)
}

Measured memory_bytes: 36164
/*
 * ex5_3
 * kamecha
 */
#include<stdio.h>
#define rep(i, n)   for(int i = 0; i < (n); i++)

/*
 * 全部'.'だと1を返す関数
 */
int check_row(const char grid[100][100], int line, int row){
    int flag = 1;
    rep(i, line){
        if(grid[i][row] == '#')  flag = 0;
    }
    if(flag)    return 1;
    else        return 0;
}

int check_line(const char grid[100][100], int line, int row){
    int flag = 1;
    rep(i, row){
        if(grid[line][i] == '#')  flag = 0;
    }
    if(flag)    return 1;
    else        return 0;
}

int main(void){
    int height, width;  scanf("%d %d", &height, &width);
    char grid[100][100];
    int del_row[100];
    int del_line[100];
    int max_row = 0, max_line = 0;
    int flag = 0;
    rep(i, height)  rep(j, width)   scanf(" %c", &grid[i][j]);
    /*
     * 圧縮する行、列を確認する
     */
    rep(i, height){
        if(check_line(grid, i, width))  del_line[max_line++] = i;
    }
    rep(i, width){
        if(check_row(grid, height, i))  del_row[max_row++] = i;
    }
    /*
     * 圧縮されてる所を飛ばして表示
     */
    rep(i, height){
        rep(j, max_line)    if(i == del_line[j])    flag = 1;
        if(flag){
            flag = 0;
            continue;
        }
        rep(j, width){
            rep(k, max_row) if(j == del_row[k]) flag = 1;
            if(flag){
                flag = 0;
                continue;
            }
            printf("%c", grid[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
    public static void main(String[]args){
	Scanner sc = new Scanner(System.in);
	int ans =0;
	
	String S[]=sc.nextLine().split("");
	String T[]=sc.nextLine().split("");
	for(int i=0; i<S.length; i++){
	    if( !S[i].equals(T[i])){
		ans++;
	    }
	}
	System.out.println(ans);
    }
    
}


Measured memory_bytes: 65912
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
            j -= 1
    res = max(res,i+j)
print(res)

Measured memory_bytes: 134480
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();

            out.println(n * n - a);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


struct City
{
    int ken, year, id;
    bool operator<(const City &o) const{
        return  year < o.year;
    }
};


int main() {
    int N,M; cin >> N >> M;

    vector<City> city(M);
    REP(i,M){
        City c;
        cin >> c.ken >> c.year;
        c.id = i;
        city[i] = c;
    }

    sort(ALL(city));

    map<int,int> m;
    vector<ll> ans(M);

    REP(i,M){
        m[city[i].ken]++;

        ans[city[i].id] = city[i].ken*1000000LL + m[city[i].ken];
    }


    REP(i,M){
        cout << setw(12) << setfill('0') << ans[i] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define sp(x) fixed<<setprecision(x)
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define die(x) return cout << x << endl, 0
#define fastio ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
const int MAXN = 100 * 1000 + 10;
int n, k, neg;
int a[MAXN], dp[MAXN];
int main(){
    fastio;
    cin >> n >> k;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
//    cout << "dp0: " << dp[0] << endl << "dp1: " << dp[1] << endl;
    for(int i = 2; i < n; i ++){
    	dp[i] = INT_MAX;
    	for(int j = 1; j <= min(k, i); j ++)
        	dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
//        cout << "dp" << i << ": min( " << dp[i - 1] << " + " << a[i] << " - " << a[i - 1] << ", " << dp[i - 2] << " + " << a[i] << " - " << a[i - 2] << " );\n";
    }
    die(dp[n - 1]);
    return 0;
}


Measured memory_bytes: 4372
using System;
using static System.Console;

namespace dp
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main()
        {
            var n = int.Parse(ReadLine());
            var aList = ReadNumList();

            var countList = new int[4];
            foreach (var a in aList)
            {
                ++countList[a];
            }

            var dp = new double[n + 1][][];
            for (var i = 0; i < dp.Length; ++i)
            {
                dp[i] = new double[n + 1][];
                for (var j = 0; j < dp[i].Length; ++j)
                {
                    dp[i][j] = new double[n + 1];
                    for (var k = 0; k < dp[i][j].Length; ++k)
                    {
                        dp[i][j][k] = -1d;
                    }
                }
            }
            dp[1][0][0] = (double)n;

            WriteLine(Search(dp, n, countList[1], countList[2], countList[3]));
        }
        static double Search(double[][][] dp, int n, int one, int two, int three)
        {
            if (dp[one][two][three] != -1d)
            {
                return dp[one][two][three];
            }
            var result = 0d;
            if (one > 0)
            {
                result += one * Search(dp, n, one - 1, two, three);
            }
            if (two > 0)
            {
                result += two * Search(dp, n, one + 1, two - 1, three);
            }
            if (three > 0)
            {
                result += three * Search(dp, n, one, two + 1, three - 1);
            }
            result += n;
            result /= one + two + three;
            dp[one][two][three] = result;
            return result;
        }
    }
}


Measured memory_bytes: 246728
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m; cin >> n >> m;
    vi num_e(n + 2);
    int sum_w = 0, sum_e = 0;
    rep(j, m){
        rep(i, 1, n + 1){
            char c; cin >> c;
            if(c == 'E') num_e[i]++;
        }
    }
    num_e[n + 1] = m;
    for(auto& e : num_e) sum_w += (m - e);
    sum_e = 0;

    int res = n * m, bd = -1;
    rep(i, n + 1){
        sum_w -= (m - num_e[i]);
        sum_e += num_e[i];

        if(chmin(res, sum_w + sum_e)){
            bd = i;
        }
    }

    cout << bd << " " << bd + 1 << endl;

    return 0;
}

Measured memory_bytes: 3276
class Node:
  def __init__(self, nid, lid, rid):
    self.nid = nid
    self.lid = lid
    self.rid = rid
    self.height = 0
    self.type = "root"
    self.parent = None
    self.depth = 0

  def set_parent(self, parent):
    self.parent = parent
    self.type = "leaf" if (self.lid < 0 and self.rid < 0) else "internal node"
    parent.update_height(self.height + 1)

  def update_height(self, h):
    self.height = max(self.height, h)
    if self.parent: self.parent.update_height(self.height + 1)

  def get_sibling(self):
    if self.parent is None: return - 1
    if self.parent.lid == self.nid: return self.parent.rid
    if self.parent.rid == self.nid: return self.parent.lid

  def get_depth(self):
    if self.depth: return self.depth
    if self.type == "root": return 0
    self.depth = self.parent.get_depth() + 1
    return self.depth

  def get_degree(self):
    deg = 0
    if self.lid >= 0: deg += 1
    if self.rid >= 0: deg += 1
    return deg

  def display(self):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
      self.nid,
      self.parent.nid if self.parent else -1,
      self.get_sibling(),
      self.get_degree(),
      self.get_depth(),
      self.height,
      self.type
      )
    )

nodelist = {}
for i in range(int(input())):
  nid, lid, rid = list(map(int, input().split()))
  nodelist[nid] = Node(nid, lid, rid)

for i in nodelist:
  n = nodelist[i]
  if n.lid >= 0: nodelist[n.lid].set_parent(n)
  if n.rid >= 0: nodelist[n.rid].set_parent(n)

for i in sorted(nodelist): nodelist[i].display()

Measured memory_bytes: 7748
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,m,no,ans;
vector<pair<int,int> > v[55];
bool u[55];
void dfs(int x)
{
	u[x]=true;
	for(int i=0;i<v[x].size();i++)
		if(!u[v[x][i].first]&&v[x][i].second!=no)
			dfs(v[x][i].first);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(make_pair(b,i));
		v[b].push_back(make_pair(a,i));
	}
	for(int i=1;i<=m;i++)
	{
		no=i;
		for(int j=1;j<=n;j++)
			u[j]=false;
		dfs(1);
		for(int j=1;j<=n;j++)
			if(!u[j])
			{
				ans++;
				break;
			}
	}
	cout<<ans;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		for(int i=0; i<M; i++) {
			if(i%2==0)
				pw.printf("%d %d\n", (N+1)/2-i/2, (N+1)/2+1+i/2);
			else
				pw.printf("%d %d\n", i/2+2, N-i/2);
		}
		sc.close();
		pw.close();
	}
}


Measured memory_bytes: 57836
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

main(){
  int l, a, b, c, d;
  scanf("%d%d%d%d%d", &l, &a, &b, &c, &d);
  int e = a / c;
  if(a % c)
    e++;
  int f = b / d;
  if(b % d)
    f++;
  printf("%d\n", l - max(e, f));
  return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	int ans = 0;
	rep(i,n){
		int x;
		cin >> x;
		ans += min(2*x,2*(k-x));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
  long n;
  cin >> n;
  long num = 1;
  vector<long> nums;
  while(true){
    if(num == n+1) break;
    if(num%3 != 0 && num%5 != 0){
      nums.emplace_back(num);
  	}
    num++;
  }
  long sum = 0;
  for(auto &nu:nums){
    sum+=nu;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 11592
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int a, b, c, d;
    	cin >> a >> b >> c >> d;
    	while (a > 0 && c > 0) {
    		c -= b;
    		if (c > 0)
    			a -= d;
    	}
    	if (a > 0)
    		cout << "Yes";
    	else
    		cout << "No";
    }

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]==s[1] or s[1]==s[2] or s[2]==s[3] or s[3]==s[4])
    {
        cout<<"Bad\n";
    }
    else
    {
        cout<<"Good\n";
    }
    exit(0);
}





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

int main() {
string  N ;
    cin >> N ;
  
  if (N.at(1)==N.at(2)&&N.at(2)==N.at(3)){
    cout <<  "Yes" << endl;  
  }
  else if (N.at(0)==N.at(1)&&N.at(1)==N.at(2)){
      cout <<  "Yes" << endl;  
  }
  
  else {		
        cout << "No" << endl;  
  }
}

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

using namespace std;

#define VECTOR_LIMIT (100000+5)

int x[VECTOR_LIMIT] = { 0 };

int main() {
	int n,i,t;
	cin >> n;

	vector<int> x;
	for (i = 0; i < n; i++) {
		cin >> t;
		x.push_back(t);
	}

	sort(x.begin(), x.end(), greater<int>());

	long long res = 0;
	long long s[2] = {0,0};
	int cnt = 0;

	for (i = 0; i<n - 1; i++) {
		if (x[i] == x[i + 1] && cnt == 1) {
			s[cnt] = x[i];
			cnt++;
			break;
		}
		if (x[i] == x[i + 1] && cnt == 0) {
			s[cnt] = x[i];
			i++;
			cnt++;
		}
	}

	res = s[0] * s[1];
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
ll sizes[100001];
ll arr[100001];
ll root(ll i){
    while(i!=arr[i]) i=arr[i];
    return(i);
}
void Union(ll i,ll j){
    ll root_i=root(i),root_j=root(j);
    if(root_i==root_j) return;
    if(sizes[root_i]>sizes[root_j]) swap(root_i,root_j);
    sizes[root_j]+=sizes[root_i];
    arr[root_i]=arr[root_j];
    return;
}
bool prime[10000];
void era(){
    memset(prime,true,sizeof prime);
    for(ll p=2;p*p<=10000;p++){
        if(prime[p]){
            for(ll q=p*p;q<=10000;q+=p){
                prime[q]=false;
            }
        }
    }

    return;
}
ll fac[200001],finv[200001];
ll power(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=(ans*a)%MAX;
        b/=2;
        a=(a*a)%MAX;
    }
    return(ans%MAX);
}
ll inverse(ll a){
    return((power(a,MAX-2))%MAX);
}
ll ncr(ll n, ll r){
    ll p1=finv[n-r];
    ll p2=finv[r];

    return((((fac[n]*p1)%MAX)*p2)%MAX);


}
int main(){
    IO

    ll H,W,D;
    cin>>H>>W>>D;
    ll x[H*W+1],y[H*W+1];
    ll z;
    for(ll i=1;i<=H;i++){
        for(ll j=1;j<=W;j++){
            cin>>z;
            y[z]=i;
            x[z]=j;
        }
    }
    ll Q;
    cin>>Q;
    ll cum[H*W+1];
    ll N=H*W;
    memset(cum,0,sizeof cum);
    for(ll i=D+1;i<=N;i++){
        cum[i]=cum[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
    }

    while(Q--){
        ll L,R;
        cin>>L>>R;
        cout<<cum[R]-cum[L]<<"\n";
    }
    return(0);
}

Measured memory_bytes: 3200
#include<stdio.h>
short h, w, i, j;
char m[100][101];
char row[100], col[100];
int main(void){
  scanf("%hd%hd", &h, &w);
  register char f;
  for(i=0; i<h; i++){
    scanf("%s", m[i]);
    for(j=0; j<w; j++){
      if(m[i][j]=='#'){
        row[i]=1;
        col[j]=1;
      }
    }
  }
  for(i=0; i<h; i++){
    for(j=0; j<w; j++){
      if(row[i]==1 && col[j]==1){
        putchar(m[i][j]);
      }
    }
    if(row[i]==1){
      putchar(10);
    }
  }
}


Measured memory_bytes: 128
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, a, b = na()
s = ns()

cnt = 0
cntb = 0
for i in range(n):
    if s[i] == 'a' and cnt < a + b:
        cnt += 1
        print("Yes")
    elif s[i] == 'b' and cnt < a + b and cntb < b:
        cnt += 1
        cntb += 1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4016
import java.util.*;
 class Main
{
  public static void main(String args[])
   {
     Scanner sc=new Scanner(System.in); 
       int n=sc.nextInt();
     HashMap<String,Integer> hm=new HashMap<String,Integer>();
     hm.put("AC",0);
     hm.put("WA",0);
     hm.put("TLE",0);
     hm.put("RE",0);
     while(n-->0)
     {
       String s=sc.next();
      
          hm.put(s,1+hm.get(s));
     }
   System.out.println("AC"+" x "+hm.get("AC"));
   System.out.println("WA"+" x "+hm.get("WA"));
System.out.println("TLE"+" x "+hm.get("TLE"));
 System.out.println("RE"+" x "+hm.get("RE"));
   }
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int main()
{
    ll n;
    string s;
    cin >> n >> s;
    char tmp;
    ll res = 1;
    tmp = s[0];
    for (int i = 1; i < n; ++i) {
        if (tmp != s[i]) {
            tmp = s[i];
            ++res;
        }
    }
    cout << res << endl;
    return 0;
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    ll N,K;
    cin>>N>>K;
    ll ans = 0;
    for(ll i = K+1; i <= N; i++){
        ll t = ((N-K)/i);
        ll s = t*(i-K);
        s+=min(N+1,(t+1)*i)-(K+t*i);
      	if(K==0) s--;
        ans+=s;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define MAX_N 200001 //size of array

long fac[MAX_N], inv[MAX_N], finv[MAX_N];

void com_init()
{
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; 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;
  }
}

long combination(int a, int b)
{
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  long c = M;
  for (int i=0; i<N-K-1; i++) {
    c *= M-1;
    c %= MOD;
  }
  com_init();
  long ans = 0;
  for (int i=K; i>=0; i--) {
    ans += (c*combination(N-1, i)) % MOD;
    ans %= MOD;
    c *= M-1;
    c %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

typedef double R;

inline void add(ll &x, ll y) {
	x += y;
}

ll dp[310][310][32];

ll calc(int C, int mx, const vi& L, const vi& p) {
	memset(dp, 0, sizeof(dp));
	int n = p.size();
	dp[0][mx * (n + 1)][0] = 1;

	rep(i, C * (n + 1)) {
		rep(j, 310) {
			rep(k, 1 << n) {
				if (dp[i][j][k] == 0) continue;
				if (i + 1 > j) continue;

				int c = (i + 1) % (n + 1);
				add(dp[i+1][j][k], dp[i][j][k]);

				if (--c >= 0 && !((k >> c) & 1)) {
					add(dp[i+1][min(C * (n + 1), max(j, i + L[p[c]] * (n + 1)))][k | (1 << c)], dp[i][j][k]);
				}
			}
		}
	}
	ll res = dp[C * (n + 1)][C * (n + 1)][(1<<n)-1];
	return res;
}

int main() {
	int N, C; cin >> N >> C;
	vi L(N); rep(i, N) cin >> L[i];

	int pos = max_element(ALL(L)) - L.begin();
	swap(L[N-1], L[pos]);
	int ml = L.back();
	L.pop_back();

	vi p(N - 1);
	iota(ALL(p), 0);

	ll ans = 0;

	do {
		ans += calc(C, ml, L, p);
	} while (next_permutation(ALL(p)));

	ll all = 1;
	rep(i, N-1) all = all * (i+1);
	rep(i, N-1) all = all * C;

	printf("%.12Lf\n", (long double)ans / all);

	return 0;
}

Measured memory_bytes: 24448
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;

    n = n%10;
    if(n==3){
        cout << "bon" << endl;
    }
    else if(n==0||n==1||n==6||n==8){
        cout << "pon" << endl;
    }
    else{
        cout << "hon" << endl;
    } 
    
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/5/2018
 
 16:05-16:15 analysis
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
int N;
string S;
const char sh='S',wo='W';
const char A[2]={sh,wo};
map<char,int> key={{sh,0},{wo,1}};
char f(char me, char nei, char ans) {
  if(me==sh&&ans=='o') return nei;
  if(me==wo&&ans=='x') return nei;
  return A[key[nei]^1];
}

void solve() {
  REP(mask,4) {
    string X=string(N,'#');
    X[0]=(mask&1)?sh:wo;
    X[1]=((mask>>1)&1)?sh:wo;
    bool ok=true;
    REP(i,N) {
//      if(X[i]=='#') dump2(i,X[i]);
      assert(X[i]!='#');
      int l=(N+i-1)%N,r=(i+1)%N;
      assert(X[l]!='#'||X[r]!='#');
      if(X[l]!='#'&&X[r]!='#') {
        ok&=f(X[i],X[l],S[i])==X[r]&&f(X[i],X[r],S[i])==X[l];
      } else if(X[l]=='#') X[l]=f(X[i],X[r],S[i]);
      else X[r]=f(X[i],X[l],S[i]);
    }
    if(ok) {
      // assertion
      REP(i,N) {
        int l=(N+i-1)%N,r=(i+1)%N;
        assert(f(X[i],X[l],S[i])==X[r]&&f(X[i],X[r],S[i])==X[l]);
      }
      
      cout<<X<<endl;
      return;
    }
  }
  cout<<-1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>S;
  solve();
  return 0;
}


Measured memory_bytes: 576
#include <iostream>
using namespace std;
const int MAXN=1e5+7;
int n,h[MAXN],f[MAXN];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	h[0]=0x3f3f3f3f;
	for(int i=2;i<=n;i++)
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

    int cnt[3] = {};
    string s; cin >> s;
    REP(i,s.size()) cnt[s[i] - 'a']++;

    sort(cnt, cnt + 3);
    if (abs(cnt[0] - cnt[2]) <= 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
package main
 
import (
	"fmt"
)

func main() {
  var d, hw, tmp int
  fmt.Scan(&d, &hw)
  for i := 0; i < hw; i++ {
    fmt.Scan(&tmp)
    d -= tmp
    if d < 0 { 
      fmt.Println(-1)
      return
    }
  }
  fmt.Println(d)
}


Measured memory_bytes: 2308
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    ll K; cin >> K;
    map<int, ll> m;
    repp(i,0,N) {
        int a, b; cin >> a >> b;
        m[a] += b;
    }
    for (auto x: m) {
        K -= x.second;
        if (K <= 0) {
            cout << x.first << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 4224