akhauriyash/Code-Regression huggingface dataset:
while(True):
    tmp = list(map(int,input().split()))
    n,m = tmp[0],tmp[1]
    ans = 0
    if n == 0:
        quit()
    hs, ws = [0], [0]
    #hとwについて累積和を取る
    for i in range(n):
        hs.append(hs[-1]+int(input()))
    for i in range(m):
        ws.append(ws[-1]+int(input()))
    #hとwの差分を記録
    h_dif, w_dif = [0] * (hs[-1]+1), [0] * (ws[-1]+1)
    for i in range(n):
        for j in range(i+1,n+1):
            h_dif[hs[j]-hs[i]] += 1
    for i in range(m):
        for j in range(i+1,m+1):
            w_dif[ws[j]-ws[i]] += 1
    for i in range(1,min(len(h_dif),len(w_dif))):
        ans += h_dif[i] * w_dif[i]
    print(ans)



Measured memory_bytes: 18972
let N,A,B = stdin.ReadLine().Split() |> Array.map int |> fun x -> x.[0], x.[1], x.[2]
let S = stdin.ReadLine().ToCharArray() |> Array.indexed
let foreignStudent = S |> Array.filter( fun (_,c) -> c = 'b') |> Array.length

let mutable bCounter = 0
let mutable winCount = 0

let ans = S |> Array.map(fun (index,c) ->
        match c with
        | 'a' -> 
            if (winCount) < (A+B) then 
                winCount<- winCount+1
                "Yes" 
            else 
                "No"
        | 'b' -> 
            bCounter<- bCounter+1
            if (winCount) < (A+B) && bCounter <= B then 
                winCount<-winCount+1
                "Yes" else "No"
        | _ -> "No"
    )
ans |> Array.iter (fun x -> printfn "%s" x)

Measured memory_bytes: 46160
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	int main() {
		// #ifndef ONLINE_JUDGE
		// 	// for getting input from input.txt
		// 	freopen("input.txt", "r", stdin);
		// 	// for writing output to output.txt
		// 	freopen("output.txt", "w", stdout);
		// #endif
		int k,l;
	 	string s;
	 	cin>>s;
	 	for (int i = 0; i < s.size(); ++i)
	 	{
	 		if(s.at(i) == 'A'){
	 			k = i;
	 			break;
	 		}
	 	}

	 	for (int i = k+1; i < s.size(); ++i)
	 	{
	 		if(s.at(i) == 'Z' ){
	 			l = i;
	 		
	 		}
	 	}
	 	// cout<<l<<" "<<k;
	 	cout<<(l-k)+1<<"\n";
		return 0;
		}	

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int H = 1001;
const int W = 1001;
vector<string> g(H);
long long dp[H][W];
int h, w;
long long calc(int r, int c) {
	if (r == h - 1 && c == w - 1)
		return 1;
	if (r >= h || c >= w)
		return 0;
	if (g[r][c] == '#')
		return 0;
	auto &ret = dp[r][c];
	if (ret != -1)
		return ret;
	ret = calc(r + 1, c) % MOD;
	ret = (ret + calc(r, c + 1)) % MOD;
	return ret;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
		cin >> g[i];
	memset(dp, -1, sizeof(dp));
	cout << calc(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 9216
import kotlin.math.sqrt

fun main(){
    val N = readLine()!!.toLong()

    if(N == 1L){
        println(0)
        return
    }

    var x = N
    val pSet = mutableSetOf<Long>()
    for(i in 2..sqrt(N.toDouble()).toInt()){
        while(x % i == 0L){
            pSet.add(i.toLong())
            x /= i
        }
    }
    if(x != 1L) {
        pSet.add(x)
    }

    if(pSet.isEmpty()){
        println(1)
        return
    }

    var ans = 0
    x = N
    pSet.forEach { p ->
        var pp = p
        while (x % pp == 0L){
            ans++
            x /= pp
            pp *= p
        }
    }
    println(ans)
}

Measured memory_bytes: 34584
n,m = map(int,input().split())
count = 0
list2 = [0] * m
for i in range(n):
  list = input().split()
 
  for j in range(len(list)-1):
    for k in range(m+1):
      if int(list[j+1]) == k:
        list2[k-1] += 1
        break;
for l in range(m):
  if list2[l] == n:
    count += 1
if n == 1:
  count = list[0]
print(count)

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


def solve(N: int, P: "List[int]"):

    result = 1
    min_num = P[0]
    for i in range(N):
        if P[i] < min_num:
            result += 1
            min_num = P[i]
        else:
            pass
    print(result)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n = s.size();
  vector<vector<ll>> x(4, vector<ll>(n, 0));
  rep(j, n) {
    if (j) {
      rep(i, 4) {
        x[i][j] += x[i][j - 1];
      }
    }

    if (s[j] == 'A') x[0][j]++;
    else if (s[j] == 'B') x[1][j]++;
    else if (s[j] == 'C') x[2][j]++;
    else if (s[j] == '?') x[3][j]++;
  }

  ll q = x[3][n - 1];
  vector<ll> com(4, 0);
  rep(i, 4) {
    if (q - 3 + i >= 0) com[i] = modpow(3, q - 3 + i);
  }

  ll ans = 0;
  rep(i, n) {
    if (s[i] == 'B') {
      ll res = (x[0][i] * (x[2][n - 1] - x[2][i])) % mod;
      res = (res * com[3]) % mod;
      ans = (ans + res) % mod;
      res = (x[0][i] * (x[3][n - 1] - x[3][i])) % mod;
      res = (res * com[2]) % mod;
      ans = (ans + res) % mod;
      res = (x[3][i] * (x[2][n - 1] - x[2][i])) % mod;
      res = (res * com[2]) % mod;
      ans = (ans + res) % mod;
      res = (x[3][i] * (x[3][n - 1] - x[3][i])) % mod;
      res = (res * com[1]) % mod;
      ans = (ans + res) % mod;
    }
    else if (s[i] == '?') {
      ll res = (x[0][i] * (x[2][n - 1] - x[2][i])) % mod;
      res = (res * com[2]) % mod;
      ans = (ans + res) % mod;
      res = (x[0][i] * (x[3][n - 1] - x[3][i])) % mod;
      res = (res * com[1]) % mod;
      ans = (ans + res) % mod;
      res = ((x[3][i] - 1) * (x[2][n - 1] - x[2][i])) % mod;
      res = (res * com[1]) % mod;
      ans = (ans + res) % mod;
      res = ((x[3][i] - 1) * (x[3][n - 1] - x[3][i])) % mod;
      res = (res * com[0]) % mod;
      ans = (ans + res) % mod;
    }
  }
  cout << ans << endl;
  







  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int min = 1000, max = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    min = num > min ? min : num;
    max = num < max ? max : num;
  }
  cout << max - min << endl;
}


Measured memory_bytes: 256
import Control.Monad.State

getInts = map read . words <$> getLine :: IO [Int]
getInt = read <$> getLine :: IO Int

data Coins = Coins {_a::Int,_b::Int,_c::Int}
main = do
    (a:b:c:_) <- replicateM 3 getInt
    money <- getInt
    putStrLn . show $ pay money (Coins a b c)
    return undefined

pay money (Coins a b c)
    | a == 0 && b == 0 = if money `mod` 50 == 0 && money <= c * 50 then 1 else 0
    | a == 0 = foldr1 (+) $ map (\x -> pay x (Coins 0 0 c)) $ makeZipped b 100
    | otherwise = foldr1 (+) $ map (\x -> pay x (Coins 0 b c)) $makeZipped a 500
    where makeZipped num price = takeWhile (\x -> x >= 0) $ map (\(bb, mon) -> mon - bb * price) $ take (num + 1) $ zip ([0..]) (repeat money)


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

int a[300][300], G[300][300];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n)rep(j,n)scanf("%lld", &a[i][j]);
	rep(i,n)rep(j,n)G[i][j] = a[i][j];
	rep(i,n)rep(u,n)rep(t,n){
		G[u][t] = min(G[u][t], G[u][i]+G[i][t]);
	}
	/*rep(i,n){
		rep(j,n)printf("%d ", G[i][j]);
		printf("\n");
	}*/
	int f = 1;
	rep(i,n)rep(j,n)if(a[i][j] != G[i][j])f = 0;
	if(f == 0){
		printf("-1\n");
		return 0;
	}
	int ans = 0;
	rep(u,n)rep(t,n){
		if(u >= t)continue;
		int mn = inf;
		rep(i,n){
			if(u == i || i == t)continue;
			mn = min(mn, G[u][i]+G[i][t]);
		}
		if(G[u][t] < mn)ans += G[u][t];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio {
  int it, len;
  char s[LEN + 5];
  fastio() {
    it = len = 0;
  }
  char get() {
    if(it < len) return s[it++];
    it = 0, len = fread(s, 1, LEN, stdin);
    return len ? s[it++] : EOF;
  }
  bool notend() {
    char c;
    for (c = get();c == ' ' || c == '\n' || c == '\r';c = get());
    if (it) it--;
    return c != EOF;
  }
  void put(char c) {
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush() {
    fwrite(s, 1, it, stdout);
  }
}buff, bufo;
inline int getint() {
  char c; int res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1;
  for (;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll() {
  char c; ll res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char() {
  char c;
  for (c = buff.get(); c == ' ' || c == '\n' || c == '\r'; c = buff.get());
  return c;
}
int h1, m1, h2, m2, k;
int main() {
  h1 = getint(), m1 = getint(), h2 = getint(), m2 = getint(), k = getint();
  putint(h2 * 60 + m2 - h1 * 60 - m1 - k, '\n');
  bufo.flush(); 
  return 0;
}


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

	int n, a, b;

	cin >> n >> a >> b;

	if ((b - a) % 2 == 0) {
		cout << "Alice" << endl;
	} 
else 
        cout << "Borys" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

string chess[8][8];
bool queen[8][8];

void board(int x, int y, bool isEmpty[8][8])
{
    int i = 0;
    while(x+i < 8)
    {
        isEmpty[x][i] = false;
        i++;
    }
    i = 0;
    while(y+i < 8)
    {
        isEmpty[i][y] = false;
        i++;
    }
    i = 0;
    while(x+i < 8 && y-i >= 0)
    {
        isEmpty[x+i][y-i] = false;
        i++;
    }
    i = 0;
    while(x-i >= 0 && y - i >= 0)
    {
        isEmpty[x-i][y-i] = false;
        i++;
    }
    i = 0;
    while(x-i >= 0 && y + i < 8)
    {
        isEmpty[x-i][y+i] = false;
        i++;
    }
    i = 0;
    while(x + i < 8 && y + i < 8)
    {
        isEmpty[x+i][y+i] = false;
        i++;
    }
}

int main(void)
{
    
    rep(i, 8)
    {
        rep(j, 8)
        {
            chess[i][j] = '.';
            queen[i][j] = false;
        }
    }
    int k;
    cin >> k;

    rep(i, k){
        int s, t;
        cin >> s >> t;
        queen[s][t] = true;
    }

    vector<int> a(8);
    rep(i, 8) a.at(i) = i+1;

    do
    {
        bool isEmpty[8][8];
        rep(i, 8)rep(j, 8) isEmpty[i][j] = true;

        vector<int> b = a;
        rep(i, 8) b[i]--;
        bool flag = true;
        rep(i, 8)
        {
            if(!isEmpty[i][b[i]]){
                flag = false;
                break;
            }
            board(i, b[i], isEmpty);
        }
        if(flag){
            bool flag2 = true;
            rep(i, 8)rep(j, 8)
            {
                if(queen[i][j]){
                    if(b[i] != j) flag2 = false;
                    break;
                } 
            }
            if(flag2)
            {
                rep(i, 8){
                    rep(j, 8){
                        cout << ((b[i] == j) ? "Q" : ".");
                    }
                    cout << endl;
                }
                return 0;
            }
        }
        
    } while(next_permutation(a.begin(), a.end()));
    
    
    return 0;
}




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

int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    int a[n];
    rep(i, n) cin >> a[i];

    sort(a, a + n, greater<int>());

    for (int i = 0; i < k; ++i)
    {
        sum += a[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0].to!int;
    auto Q = s[1].to!int;
    auto L = s[2];
    auto R = s[3];
    auto A = readln.split.map!(to!long).array;
    auto queries = Q.iota.map!(_ => readln.split.map!(to!long).array).array;
    A.sort();

    long f(int idx) {
        long a = A[idx];
        foreach (q; queries) {
            auto type = q[0];
            auto x = q[1];
            auto y = q[2];
            auto z = q[3];
            if (type == 1 && a >= x) {
                a = z * (a + y);
            } else if (type == 2 && a <= x) {
                a = (a - y) / z;
            }
        }
        return a;
    }

    int ansL, ansR;

    {
        int hi = N;
        int lo = -1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (f(mid) >= L) {
                hi = mid;
            } else {
                lo = mid;
            }
        }
        ansL = hi;
    }

    {
        int hi = N;
        int lo = -1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (f(mid) <= R) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        ansR = lo;
    }

    if (f(N-1) < L || f(0) > R) {
        writeln(0);
    } else {
        writeln(ansR - ansL+ 1);
    }
}



Measured memory_bytes: 28772
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

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

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int a, b;

    cin >> a >> b;

    if (b*2 < a) cout << a-(b*2);
    else cout << "0";

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
        if (a > b)
        {
                a = b;
                return true;
        }
        return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
        if (a < b)
        {
                a = b;
                return true;
        }
        return false;
}

typedef long long ll; //64bit型
using namespace std;

// const long long INF = 1LL << 60; //無限大の値
int INF = 1000000;

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

        if (moji[0] == moji[1] || moji[1] == moji[2] || moji[2] == moji[3])
        {
                cout << "Bad" << endl;
        }
        else
        {
                cout << "Good" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int md=1e9+7;
int n,x,y,z,dp[41][1<<18],ans=1;
inline void upd(int&a){a+=a>>31&md;}
int main(){
	scanf("%d%d%d%d",&n,&x,&y,&z);
	const int C=1<<(x+y+z-1)|(1<<(y+z-1))|(1<<z-1),ALL=(1<<x+y+z)-1;
	dp[0][0]=1;
	for(int i=1;i<=n;++i){
		ans=ans*10LL%md;
		for(int S=0;S<=ALL;++S)if(int k=dp[i-1][S])if((S&C)!=C)
		for(int w=1;w<=10;++w)upd(dp[i][(S<<w|(1<<(w-1)))&ALL]+=k-md);
	}
	for(int S=0;S<=ALL;++S)
	if((S&C)!=C)upd(ans-=dp[n][S]);
	printf("%d\n",ans);
	return 0;
}

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



int main(int argc, const char * argv[]) {
    int  n,m,l;
    cin>>n>>m>>l;
    
    long long a[n][m];
    long long b[m][l];
    long long c[n][l];
    
    for(int i=0;i!=n;++i){
        for(int j=0;j!=m;++j){
            cin>>a[i][j];
        }
    }
    
    
    for(int i=0;i!=m;++i){
        for(int j=0;j!=l;++j){
            cin>>b[i][j];
        }
    }
    
    for(int i=0;i!=n;++i){
        for(int j=0;j!=l;++j){
            c[i][j]=0;
            for(int k=0;k!=m;++k){
                c[i][j]+=a[i][k]*b[k][j];
            }
            cout<<c[i][j];
            if(j!=l-1){
                cout<<" ";
            }
        }
        cout<<'\n';
    }
    
    return 0;
    
}



Measured memory_bytes: 3284
#include <iostream>
#include <algorithm>
#include <cmath>
#define lli long long int
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int main() 
{
	fio;
	lli n,w;
	cin>>n>>w;
	lli arr[n],brr[n];
	for (int i=0;i<n;i++)
	cin>>arr[i]>>brr[i];
	lli dp[n][w+1];
	for (int i=0;i<n;i++)
	{
	    dp[i][0]=0;
	}
	for (int i=1;i<=w;i++)
	{
	    if (i>=arr[0])
	    dp[0][i]=brr[0];
	    else
	    dp[0][i]=0;
	}
	for (int i=1;i<n;i++)
	{
	    for (int j=1;j<=w;j++)
	    {
	        if (j>=arr[i])
	        {
	            dp[i][j]=max((brr[i]+dp[i-1][j-arr[i]]),dp[i-1][j]);
	        }
	        if (j<arr[i])
	        {dp[i][j]=dp[i-1][j];}
	    }
	}
	cout<<dp[n-1][w];
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
  int n,m,X,Y;
  cin>>n>>m>>X>>Y;
  vin x(n),y(m);
  rep(i,0,n) cin>>x[i];
  rep(i,0,m) cin>>y[i];
  ///////////////
  bool war=0;
  sort(all(x));sort(all(y));
  reverse(all(x));
  if(x[0]>=y[0]) war=1;
  bool ok=false;
  rep(i,x[0]+1,y[0]+1){//i=z
    if(X<i&&i<=Y) ok=true;
  }
  if(!ok) war=1;
  
  //cout<<x[0]<<y[0]<<endl;
  if(war) cout<<"War"<<endl;
  else cout<<"No War"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
 // Your code here!
 int a,b;
 char r;

 while(1){      
 scanf("%d %c %d", &a ,&r, &b);      

 if ( r == '?' )      
 break;

 if ( r == '+' ){      
 printf("%d\n",a+b)
 ;}          
 else if ( r == '-' ){
 printf("%d\n",a-b)
 ;}          
 else if ( r == '*' ){
 printf("%d\n",a*b)
 ;}
 else if ( r == '/' ){
 printf("%d\n",a/b)
 ;}

 }

 return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main() 
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    for (int r = 0; r < H; ++r) {
        for (int c = 0; c < W; ++c) {
            cout << ((r < B && c < A) || (B <= r && A <= c) ? 1 : 0);            
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)
//long long ;
void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int gcd(int x, int y){
    if (y == 0) return x;
    else        return gcd(y, x % y);
}

int main() {
    long long int a,b,m,n,k,ans,ans_2;
    scanf("%lld %lld",&n,&k);
    ans=n%k;
    ans_2=k-ans;
    if(n==0){
        printf("0\n");
    }else if (ans > ans_2) {
        printf("%lld\n",ans_2);
    }else{
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a;
    string b;
    cin>>a>>b;
    ll b_temp = b[0] - '0';
    ll deci = ((b[2] -'0')* 10 + (b[3] - '0'));
    ll ans = (a * b_temp) + (deci * a) / 100;
    cout<<ans<<"\n";
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{
	int a, b, c,ans;
	ans = 3;
	cin >> a >> b >> c;
	if (a == b)ans--;
	if (b == c)ans--;
	else if (a == c)ans--;
	
	cout << ans << endl;
	
}

Measured memory_bytes: 256
from sys import exit, stdin
from operator import mul
from functools import reduce
from collections import Counter
N = int(stdin.readline().rstrip())
S = Counter(''.join(sorted(list(stdin.readline().rstrip()))) for _ in range(N))

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans = 0
for i in S.values():
    if i > 1:
        ans += cmb(i, 2)
print(ans)

Measured memory_bytes: 59100
program main
  implicit none
  
  integer :: n,a(100000),i,j,c=0,f=1
  
  read(*,*)n
  do i = 1, n
    read(*,*)a(i)
  end do
  
  do i = 1, n
    c = c + 1 
    f = a(f)
    if (f == 2) then
      write(*,*)c
      stop
    end if
  end do
  write(*,*)-1
end program main
    

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int x = a * b;
	if(x % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm> 
#include<vector>
#include<map>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   long long int n,m;
   cin>>n>>m;
  if(n<=m)
  {
    cout<<"unsafe";
  }
  else
  {
    cout<<"safe";
  }
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();

		System.out.println(s1.substring(0, 1).toUpperCase() + s2.substring(0, 1).toUpperCase() + s3.substring(0, 1).toUpperCase());
 	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[3][MAXN], dp[3][MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[0][i] >> a[1][i] >> a[2][i];
    FOR(i,0,2) dp[i][0] = 0;
    FOR(i,1,n) {
        FOR(j,0,2) {
            dp[j][i] = 0;
            FOR(k,0,2)
                if (k != j) {
                    dp[j][i] = max(dp[j][i], dp[k][i-1] + a[j][i]);
                }
        }
    }
    int res = 0;
    FOR(i,0,2) res = max(res, dp[i][n]);
    cout << res;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
  int K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  for (int i= 0; i<N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  vector<int> D(N);
  for(int i=0; i<N-1; i++){
    D.at(i) = A.at(i+1) - A.at(i);
  }
  D.at(N-1) = K + A.at(0) - A.at(N-1);
  sort(D.begin(),D.end());
  cout << K - D.at(N-1) << endl;
}
    
    

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

signed main() {
  SS(int,n);
  SV(ll,a,n);
  sort(a.begin(),a.end());
  ll ans=1;
  rep(i,n){
    debug(a[0]);
    if(1000000000000000000/ans<a[i]){
      p(-1);
      return 0;
    }
    ans*=a[i];
    if(ans==0)break;
  }
  p(ans);
  
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
#define N 200010
int k,n,m,p,a[N],c[N];
int Ans,x;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&x),c[x]++;
	for(int i=1;i<=n;i++)if(c[i])a[++m]=c[i];
	sort(a+1,a+m+1);
	for(int i=1;i<=m-k;i++)Ans+=a[i];
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define sz(x) (int)x.size()
#define eb emplace_back
using LL = long long;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << ( A*B == C*D ? A*B : A*B > C*D ? A*B: C*D ) << endl;
    return 0;
}

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

int main(){
    int N[3];
    for(int i=0;i<3;i++){
        cin>>N[i];
    }
    sort(N,N+3);
    int ans;
    if((N[2]-N[0])%2==(N[2]-N[1])%2){
        ans=(N[2]*2-N[1]-N[0])/2;
    }else{
        N[0]++;
        N[2]++;
        ans=(N[2]*2-N[1]-N[0])/2+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b;
	string s;
	cin >>a >>b;
	cout << max(0, a - 2*b) <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
use itertools::Itertools;

fn main() {
    proconio::input! {
        n: usize, m: usize, q: usize,
        nums: [(usize, usize, usize, usize); q],
    }
    let mut ans = 0;
    for ar in (1..=m).combinations_with_replacement(n) {
        let mut total = 0;
        for &(a, b, c, d) in nums.iter() {
            if ar[b - 1] - ar[a - 1] == c {
                total += d;
            }
        }
        ans = std::cmp::max(ans, total);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2132
n=int(input())
a = list(map(int,input().split()))
if n % 2==0:
    for i in range(n//2):
        print(a[n-1-2*i])
    for i in range(n//2):
        print(a[2*i])
else:
    for i in range((n+1)//2):
        print(a[n-1-2*i])
    for i in range(n//2):
        print(a[1+2*i])



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

int main() {
    int n,k;
    ll mini=1LL<<60;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    sort(h.begin(),h.end());
    for (int i=0; i+k-1<n; i++) {
        mini=min(mini,h[i+k-1]-h[i]);
    }
    cout<<mini<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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;
  string s,t;
  cin >> n >> s >> t;
  string ans = s+t;
  rep(i,n){
    ans[2*i] = s[i];
    ans[2*i+1] = t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      p: usize,
      q: usize,
      r: usize,
    }
    let mut ans = p + q;
    ans = min(ans, q+r);
    ans = min(ans, p + r);
    println!("{}", ans);
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    if (s.size() > t.size())
    {
        puts("GREATER");
        return 0;
    }
    else
    {
        if (s.size() < t.size())
        {
            puts("LESS");
            return 0;
        }
        else
        {
            for (int i = 0; i < s.size(); i++)
            {
                if (s.at(i) > t.at(i))
                {
                    puts("GREATER");
                    return 0;
                }
                else
                {
                    if (s.at(i) < t.at(i))
                    {
                        puts("LESS");
                        return 0;
                    }
                }
            }
        }
    }
    puts("EQUAL");
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout << fixed; cout << setprecision(x); cout << y;
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int x; cin >> x;
	if (x == 0) cout << 1;
	else cout << 0;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

//USE AT YOUR OWN RISK
lli tmod(lli x,lli m=mod){return (x%m+m)%m;}

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<tmod(a[i])<<c;
	cout<<"\n";
}

//make sure x is below mod
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}


// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }


int main() 
{ 
    // fact[0]=1;
    // f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    
    fastio;
    int t;
    // cin>>t;
    t=1;
    int temp=t;
	while(t--){
        // cout<<"Case #"<<temp-t<<": ";
        int n;
        cin>>n;
        string s=to_string(n);
        f(i,0,s.size())if(s[i]=='7'){
            cout<<"Yes";
            return 0;
        }
        cout<<"No\n";
    }   
    return 0; 	
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define SORT(obj) sort(obj.begin(),obj.end())
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  t.erase(s.size());
  if(s==t){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3624
import Prelude
import Data.List
import Control.Monad

isin :: Int->Int->Int->Bool
isin x a b = (x<=a) && (b<=x)

isinithrange :: Int-> Int-> Int-> Int-> Int-> Bool
isinithrange x c d n i = isin x ((n-i)*d-(i-1)*c) ((n-i)*c-(i-1)*d)

solverpre :: Int->Int->Int->Int->Bool
solverpre amb n c d = or $ map (isinithrange amb c d n) [1 .. n]

solver a b n c d =solverpre (abs (a-b)) n c d

myshow :: Bool -> String
myshow True = "YES"
myshow False = "NO"

main = do
    [n, a, b, c, d] <- map read . words <$> getLine
    -- 出力
    putStr $ myshow $ solver a b n c d




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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    int a[m], b[m];
    ll huben[m];
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        huben[i]=0;
    }

    UnionFind uf(n);
    huben[m-1]=(ll)n*(n-1)/2;
    repi(i,1,m){
        ll sa = uf.size(a[m-i]), sb = uf.size(b[m-i]);
        if(uf.issame(a[m-i],b[m-i])){
            huben[m-i-1]=huben[m-i];
        }else{
            huben[m-i-1]=huben[m-i]-sa*sb;
            uf.merge(a[m-i],b[m-i]);
        }
    }

    rep(i,m){
        cc(huben[i]);
    }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

char S[10];
ll i, j, k;
int main(){
    scanf("%s", S);
    j = S[0];
    for (i = 1; S[i];++i){
        if(j!=S[i]){
            break;
        }
    }
    if(S[i]){
        printf("Yes");
    }else{
        printf("No");
    }
        return 0;
}

Measured memory_bytes: 256
data class Task (
  val cost: Int,
  val deadline: Int
)

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val tasks = (0 until n).map {
    val (a, b) = readLine()!!.split(" ")
    Task(a.toInt(), b.toInt())
  }
  val sortedTasks = tasks.sortedBy { it.deadline }
  var now = 0L
  sortedTasks.forEach {
    now += it.cost
    if (now > it.deadline) {
      println("No")
      return
    }
  }
  println("Yes")
}

Measured memory_bytes: 119852
#include <iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
#define mod 1000000
int main() {
	int n, m;
	cin >> n >> m;
	ll rui[101];
	int r = 1;
	for (int i = 0; i < 101; i++)rui[i] = r, r = (r * 2) % mod;

	if (m == 2) {
		ll dp[101][101];
		memset(dp, 0, sizeof(dp));
		for (int j = 0; j <= n; j++)dp[0][j] += 1;
		for (int i = 1; i <= n; i++) {
			dp[i][i] += rui[i];
			for (int j = i + 1; j <= n; j++) {
				dp[i][j] += (rui[i - 1]);
			}
		}
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				ll x = dp[i][j];
				if(i<n)dp[i + 1][j] += x;
				if (j < i) {
					for (int k = i + 1; k <= n; k++) {
						dp[k][k] = (dp[k][k] + (x*rui[k - i - 1] * (ll)(i - j + 1)) % mod) % mod;
						if (k == i + 1) {
							for (int l = k + 1; l <= n; l++) {
								dp[k][l] = (dp[k][l] + (x*(i - j))) % mod;
							}
						}
						else {
							for (int l = k + 1; l <= n; l++) {
								dp[k][l] = (dp[k][l] + (x*rui[k - i - 2] * (ll)(i - j + 1))) % mod;
							}
						}
					}
				}
			}
		}
		/*for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}cout << endl;*/
		ll ans = 0;
		for (int j = 0; j <= n; j++) {
			ans += dp[n][j];
		}
		cout << ans % mod << endl; return 0;
	}
	else {
		cout << rui[n] << endl; return 0;
	}
	
}

Measured memory_bytes: 3164
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
struct node{
  int key;
  struct node *prev,*next;
};
typedef struct node Node;
Node *nil;

Node* search(int x){
  Node *cur=nil->next;
  while(cur!=nil&&cur->key!=x)
    cur=cur->next;
  return cur;
}

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->prev=nil;
}

void insert(int x){
  Node *y=(Node *)malloc(sizeof(Node));
  y->key=x;
  y->next=nil->next;
  nil->next->prev=y;
  nil->next=y;
  y->prev=nil;
}

void deletenode(Node *x){
  if(x!=nil){
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  } 
}

int main(){
  int n,x; scanf("%d ",&n);
  init();
  for(int i=0;i<n;++i){
    char s[12]; scanf("\n%s",s);
    if(s[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(s[0]=='d'&&s[6]=='\0'){
      scanf("%d",&x);
      deletenode(search(x));
    }else if(s[0]=='d'&&s[6]=='F'){
      deletenode(nil->next);
    }else{
      deletenode(nil->prev);
    }
  }
  Node *cur=nil->next;
  while(cur!=nil){
    printf("%d",cur->key);
    cur=cur->next;
    if(cur!=nil) printf(" ");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 34468
#include <iostream>
#include <vector>
#include <array>
#include <limits>

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<array<ll, 3>> edge(m);
    for(int i = 0; i < m; ++i){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edge.at(i).at(0) = a;
        edge.at(i).at(1) = b;
        edge.at(i).at(2) = c;
    }

    vector<ll> dist(n, numeric_limits<ll>::min());
    vector<ll> prev(n, -1);
    dist.at(0) = 0;
    for(int i = 0; i < 2 * n - 1; ++i){
        for(int j = 0; j < m; ++j){
            const ll a = edge.at(j).at(0);
            const ll b = edge.at(j).at(1);
            const ll c = edge.at(j).at(2);
            if(dist.at(a) != numeric_limits<ll>::min() &
               dist.at(b) < dist.at(a) + c){
                dist.at(b) = dist.at(a) + c;
                prev.at(b) = a;
            }
        }
    }

    ll cur = n - 1;
    for(int i = 0; i < n; ++i){
        if(prev.at(cur) == -1){ break; }
        cur = prev.at(cur);
    }
    if(cur != 0){
        cout << "inf" << endl;
        return 0;
    }

    cout << dist.at(n - 1) << endl;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

int main() {
	ll N; cin >> N;
	string s1, s2; cin >> s1 >> s2;
	vector<vector<bool> > f(2, vector<bool>(N,false));

	ll ans=1;
	for (int i = 0; i < N; i++) {
		if (!f[0][i] && s1[i] == s2[i]) {
			f[0][i] = true; f[1][i] = true;
			if (i == 0) {
				ans *= 3;
				ans %= MOD;
			}
			else {
				if (s1[i - 1] == s2[i - 1]) {
					ans *= 2;
					ans %= MOD;
				}
			}
			continue;
		}
		if (!f[0][i] && s1[i] == s1[i + 1]) {
			f[0][i]=true; f[0][i+1]=true;
			if (i == 0) {
				ans *= 6;
				ans %= MOD;
			}
			else {
				if (s1[i - 1] == s2[i - 1]) {
					ans *= 2;
					ans %= MOD;
				}
				else {
					ans *= 3;
					ans %= MOD;
				}
			}
		}
	}

	cout << ans%MOD << endl;

}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int a, b;
	cin >> a >> b;
	cout << (b-1 + a-2) / (a-1);

	return 0;
}


Measured memory_bytes: 256