akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;
int main()
{
    IOS
    // READ("test.txt");
    //WRITE("");
    int n ;
    cin >> n ;
    vector< int >a(n+5,0), v;

    for(int i=0 ; i<n ; i++)
    {
        cin >> a[i] ;
        v.pb(a[i]);
    }
    sort_a(v) ;
    int median1 = v[n/2], median2 = v[n/2-1];
    // cout<<median1<<" "<<median2<<endl;
    for(int i=0 ; i< n ; i++)
    {
        (median1 <= a[i])?cout<<median2<<endl:cout<<median1<<endl;
    }
}



Measured memory_bytes: 3956
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
ll a[maxn];
int main() {
	for(int i=1; i<maxn; i++) {
		if(i%3==0 || i%5==0) a[i]=1;
	}
	ll n;
	cin>>n;
	ll ans =0;
	for(int i=1;i<=n;i++){
		if(!a[i]) ans += i;
	}
	cout<<ans<<endl;
}

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

int main() {
    int64_t N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<int64_t> A(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<int64_t>());

    vector<int64_t> sum(N + 1, 0);
    for (int64_t i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + A[i];
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        //i番目のものが選ばれうるか

        //そもそも上位P個は大丈夫
        if (i < P) {
            ans++;
            continue;
        }
        
        //P番目に届かないなら無理
        if (A[i] + M < A[P - 1]) {
            continue;
        }

        //最適な割り振りは「上位P - 1個まで + 自分より下位」に選ぶ
        //余ったやつが問題
        int64_t rem_vote = V - (P - 1) - (N - i);

        if (rem_vote <= 0) {
            //届くかどうか
            ans++;
            continue;
        }

        //rem_voteがM回発生する
        //それを[P - 1, i)までに割り振ることになる
        //j in [P - 1, i)としてA[j]が受け取れる回数はM + A[i] - A[j]
        //これの和なのでnum * (M + A[i]) - sum[P-1 ~ i)_A
        int64_t num = i - (P - 1);

        int64_t capacity = num * (M + A[i]) - sum[i] + sum[P - 1];
        if (capacity >= rem_vote * M) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  char c;
  cin >> c;
  
  if(c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o'){
    cout << "vowel" << endl;
  }
  
  else{
    cout << "consonant" << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a[n+1]={0};
  int dec[n+1]={0};
  a[1]=1;
  int flag=1;
  if(n==1){
    a[1]=0;
    for(int i=1;i<=m;i++){
      int s;
      cin>>s;
      int m;cin>>m;
      a[s]=m;
    }
    if(m<=1){
      cout<<a[1];
      return 0;
    }
    else{
      cout<<"-1";
      return 0;
    }
  }
  for(int i=1;i<=m;i++){
    int s;
    cin>>s;
    int l;
    cin>>l;
    if(s==1 and l==0){
       flag=0;
       continue;
    }
    dec[s]++;
    if(dec[s]>=2){
      if(l!=a[s]){
        flag=0;
        continue;
      }
    }
    a[s]=l;
  }
  if(flag==0){
    cout<<"-1";
    return 0;
  }
  for(int i=1;i<=n;i++)
    cout<<a[i];
  return 0;
}

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

int main(){
    long long n;
    cin >> n;

    long long ans = 0;
    // long long tmp = n;
    if (n % 2 == 1){
        ans = 0;
    }
    else{
        n /= 2;
        while (n > 0){
            n /= 5;
            ans += n;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

ans = Counter(A)
for i in range(1, N+ 1):
    print(ans[i])


Measured memory_bytes: 52736
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n, N) for(ll i=(n);i<(N);i++)
#define RREP(i, n, N) for(ll i=(N-1);i>=(n);i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N, x;
ll a[2010];
ll b[2010][2010];

int main() {
    cin >> N >> x;
    REP(i, 0, N) {
        cin >> a[i];
    }

    ll ans = inf;
    REP(i,0,2010)REP(j,0,2010) b[i][j] = inf;

    REP(i, 0, N) {
        ll t = x * i;
        REP(j, 0, N) {  //jを手に入れる最適な方法
            b[i][j] = min(b[((i-1)+(N*100000)) % N][j], a[(j-i+(N*100000)) % N]);
            t += b[i][j];
        }
        ans = min(ans, t);
        //cout<<"i: "<<i<<", t: "<<t<<endl;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
 
const ll N = 1e2 + 3;
const ll M = 1e5 + 3;
const ll INF = 1e18;
 
ll n, k, w[N], v[N], dp[M], mx, res;
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fill(dp, dp + M, INF);
	
	cin >> n >> k;
	for (ll i = 1; i <= n; ++i) {
		cin >> w[i] >> v[i];
	}
	
	dp[0] = 0;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = M - v[i] - 1; j >= 0; --j) {
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	
	res = 0;
	for (ll i = 1; i < M; ++i) {
		if (dp[i] <= k) res = i;
	}
	cout << res;
	
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        List<Counter> counters = new ArrayList<>();
        Map<String, Integer> index = new HashMap<>();

        for(int i = 0 ; i < n ; i++){
            String key = scanner.next();
            Counter counter = new Counter(key);
            if(index.containsKey(key)){
                counters.get(index.get(key)).increment();
            }else{
                counters.add(counter);
                index.put(key, counters.size() - 1);
            }
        }

        Collections.sort(counters, new Comparator<Counter>() {
            @Override
            public int compare(Counter o1, Counter o2) {
                if(o1.count == o2.count){
                    return o1.key.compareTo(o2.key);
                }
                return o2.count - o1.count;
            }
        });

        int max = counters.get(0).count;

        for(Counter counter : counters){
            if(max <= counter.count){
                System.out.println(counter.key);
            }
        }

    }

    static class Counter {
        public String key;
        public int count;

        public Counter(String key){
            this.key = key;
            this.count = 1;
        }

        public void increment(){
            this.count += 1;
        }

        public int hashCode(){
            return this.key.hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return this.key.equals(((Counter)obj).key);
        }
    }

}

Measured memory_bytes: 107324
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

inline ll f(ll b, ll n) {
	ll ret;
	if (n < b) ret = n;
	else ret = f(b, n/b) + n % b;
	return ret;
}

int main() {
	ll n, s; cin >> n >> s;
	if (s > n) {
		cout << -1 << endl;
		return 0;
	}
	if (s == n) {
		cout << n + 1 << endl;
		return 0;
	}
	for (ll i = 2; i <= sqrt(n); ++i) {
		if (f(i, n) == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (ll i = sqrt(n); i >= 1; --i) {
		ll b = (n - s) / i + 1;
		if (b <= 1) continue;
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import platform
ver = platform.python_version_tuple()
if int(ver[1]) < 5:
    from fractions import gcd
else:
    from math import gcd


def main():
    input = lambda: stdin.readline()[:-1]
    A, B = map(int, input().split())

    lcm = lambda x, y: x * y // gcd(x, y)
    print(lcm(A, B))


main()


Measured memory_bytes: 5460
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)*}
    };
}

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)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let n = s.len();
    let mut ans = vec![0; n];
    let mut l = 0;
    while l < n {
        let mut r = l;
        while s[r] == 'R' {
            r += 1;
        }
        let mid = r;
        while r < n && s[r] == 'L' {
            r += 1;
        }
        for i in l..r {
            if (i + mid) % 2 == 0 {
                ans[mid] += 1;
            } else {
                ans[mid - 1] += 1;
            }
        }
        l = r;
    }
    print!("{}", ans[0]);
    for i in 1..n {
        print!(" {}", ans[i]);
    }
    println!("");
}


Measured memory_bytes: 4604
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            total = 500 * i + 100 * j + 50 * k
            if X == total:
                count+=1

print(count)


Measured memory_bytes: 2940
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=list(map(int,input().split()))
x=sum(B)
y=M-1
r=0
for i in range(N+1):
    x+=A[i]
    while x>K and y>=0:
        x-=B[y]
        y-=1
    if x<=K:
        r=max(r,i+y+1)
print(r)

Measured memory_bytes: 39936
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  
  cout << fixed << setprecision(20);
  cout << double(w) * double(h) /2 << " " << (x+x == w && y+y == h) << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = str(input())
#print(N,S)

stack = []
while len(S) > 0:
    if len(stack) == 0:
        stack.append(S[0])
        S = S[1:]
    elif S[0] == stack[-1]:
        S = S[1:]
    
    elif S[0] != stack[-1]:
        stack.append(S[0])
        S = S[1:]
    #print(S,stack)
print(len(stack))
        


Measured memory_bytes: 9740
#include<iostream>
using namespace std;
int main(){
int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a>=k){
  cout << k << endl;
  }else if(a+b>=k){
  cout << a << endl;
  }else{
  cout << a-(k-a-b) << endl;
  }
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    std::vector<long> a(n);

    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[i]));
    }
    std::sort(a.begin(), a.end());

    printf("%d\n", a[n-1]-a[0]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){

	long long K;
	cin>>K;
	
	cout<<50<<endl;
	
	vector<long long> ans(50,49+K/50);
	
	for(int i=0;i<K%50;i++){
		ans[i] += 50;
	}
	
	for(int i=0;i<50;i++){
		ans[i] -= K%50;
	}
	
	for(int i=0;i<50;i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	
    return 0;
}



Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end
gets
s = gets.chomp
sc = s.count(".")
kc = s.size - sc
ssc = 0
kkc = 0
ans = [sc,kc].min
s.each_char do |c|
  ssc += 1 if(c == ".")
  kkc += 1 if(c == "#")
  ans = [sc-ssc+kkc,ans].min
end
p ans
#puts ()? "Yes" : "No"
#puts ()? "YES" : "NO"
#puts ()? "yes" : "no"

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

auto main() -> int{
    int N;
    vector<string> result;
    map<string, int> mp;
    cin >> N;
    for(int i = 0; i < N; i++){
        string tmp;
        cin >> tmp;
        mp[tmp] += 1;
    }

    int max = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        max = (max < itr->second)? itr->second : max;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(max == itr->second) result.push_back(itr->first);
    }
    sort(result.begin(), result.end(), 
            [](string x, string y){
                return x.compare(y) <= 0;
            }
        );
    for(auto v: result){
        cout << v << endl;
    }
    return 0;
}


Measured memory_bytes: 26992
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    ABC = [list(map(int, input().split())) for _ in range(n)]

    dp = [[0 for _ in range(3)] for _ in range(n)]
    dp[0][0] = ABC[0][0]
    dp[0][1] = ABC[0][1]
    dp[0][2] = ABC[0][2]
    
    for i in range(1, n):
        a = ABC[i][0]
        b = ABC[i][1]
        c = ABC[i][2]

        dp[i][0] = max(dp[i][0], dp[i - 1][1] + a, dp[i - 1][2] + a)
        dp[i][1] = max(dp[i][1], dp[i - 1][0] + b, dp[i - 1][2] + b)
        dp[i][2] = max(dp[i][2], dp[i - 1][0] + c, dp[i - 1][1] + c)

    print(max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 47344
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	string input;
	vector<int> in(11),a;
	vector<int> ans;
	while(cin>>input){
		ans.clear();
		fill(in.begin(),in.end(),0);
		for(int i=0;i<13;i++){
			++in[input[i]-'1'];
		}
		for(int i=0;i<9;i++){
			if(in[i]==4)continue;
			for(int j=0;j<9;j++){//枕
				a=in;
				++a[i];
				if(a[j]<2)continue;
				a[j] -= 2;
				for(int k=0;k<9;k++){
					int num;
					a[k] %= 3;
					num = min(min(a[k],a[k+1]),a[k+2]);
					if(a[k]==num){
						a[k] -= num;
						a[k+1] -= num;
						a[k+2] -= num;
					}
					else break;
				}
				if(count(a.begin(),a.end(),0)==11){
					ans.push_back(i+1);
					break;
				}
			}
		}
		if(ans.empty())ans.push_back(0);
		cout<<ans[0];
		for(int i=1;i<ans.size();i++){
			cout<<' '<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#include<string.h>


int main()
{
    char first[15],second[15],third[15];
    scanf("%s%s%s",first,second,third);
    int len=strlen(first);
    if(first[len-1]==second[0])
    {
        len=strlen(second);
        if(second[len-1]==third[0]){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}


string s;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,m,i,j,k,x,q;
    int t=1;
    cin>>s;
    int len = 15-s.length();
    fr(i,s.length())if(s[i]=='o')len++;
    if(len>=8)cout<<"YES\n";
    else cout<<"NO\n";

    
    return 0;
}


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

using namespace std;

vector<vector<int> > imap(52,vector<int>(52,0));
int w,h;

void dfs(int nowx,int nowy){
  imap[nowx][nowy]=0;
  for(int i=-1;i<2;++i){
    for(int j=-1;j<2;++j){
      if(imap[nowx+i][nowy+j]==1) dfs(nowx+i,nowy+j);
    }
  }
}

int main(){
  while(cin>> w>>h&&(w||h)){
    for(int i=1;i<h+1;++i)
      for(int j=1;j<w+1;++j)
	cin >> imap[i][j];

    int cnt=0;
    for(int i=1;i<h+1;++i)
      for(int j=1;j<w+1;++j)
	if(imap[i][j]==1){
	  cnt++;
	  dfs(i,j);
	}
    cout << cnt <<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3344
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,i,a,b=-1;
  long long s=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    hin(a);
  }
  for(i=0;i<n;i++){
    a=N[hout()];
    if(a==b){
      if(s){
	printf("%lld\n",s*a);
	return 0;
      }
      else s=a;
      b=-1;
    }
    else b=a;
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    vi a(4);
    rep (i, 4) cin >> a[i];

    int mi = inf;
    rep (i, 4) {
        for (int j= i + 1; j < 4; j++) {
            int s = 0, t = 0;
            rep (k, 4) {
                if (k == i or k == j) s += a[k];
                else t += a[k];
            }
            chmin(mi, abs(s - t));
        }
    }
    cout << mi << endl;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long K, long long N, std::vector<long long> A){
    A.PB(K + A[0]);
    LL ans = 0;
    REP(i, N) {
        ans = max(ans, A[i+1] - A[i]);
    }

    cout << (K - ans) << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        int d = x[i] - x[i - 1];
        int cost = min(a * d, b);
        ans += cost;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import itertools
import sys

input = sys.stdin.readline

maxn = 10000000000

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.append(-maxn)
B.append(-maxn)
C.append(-maxn)

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

apos, bpos, cpos = 0, 0, 0

while (apos + 1) * (bpos + 1) * (cpos + 1) < min(2 * 10 ** 6, X * Y * Z):
    if (
        apos < len(A) - 2
        and abs(A[apos] - A[apos + 1]) < abs(B[bpos] - B[bpos + 1])
        and abs(A[apos] - A[apos + 1]) < abs(C[cpos] - C[cpos + 1])
    ):
        apos += 1
    elif bpos < len(B) - 2 and B[bpos] - B[bpos + 1] < C[cpos] - C[cpos + 1]:
        bpos += 1
    else:
        cpos += 1

res = []
for a in list(itertools.product(A[: apos + 1], B[: bpos + 1], C[: cpos + 1])):
    res.append(a[0] + a[1] + a[2])

res.sort(reverse=True)
for k in range(K):
    print(res[k])


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

d = [0]*n
for i in a:
    d[i-1] += 1

s = 0
for i in range(n):
    s += int(d[i]*(d[i]-1)/2)

for i in range(n):
    print(s-(d[a[i]-1]-1))

Measured memory_bytes: 32156
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


main :: IO ()
main = do
    n <- readLn
    sps <- replicateM n $ do
        [s,p] <- words <$> getLine
        return (s,read p) :: IO (String,Int)
    let procs = (sortOn (fst . snd) . sortBy (flip $ comparing (snd . snd)) . zip [1..]) sps 
    mapM_ (print . fst) procs


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>(), cnt = 0, p = 100;
	while(p < n) p *= 1.01, cnt++;
	cout<<cnt<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define VERTEX_MAX 401

typedef long long ll;
typedef pair<int,int> pii;//  t,dst_idx
// int G[VERTEX_MAX][VERTEX_MAX];
struct edge {
    int to;
    int cost;
};
vector<vector<edge>> G(VERTEX_MAX);
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int num_V, num_E; cin >> num_V >> num_E;
    vector<pii> v_O;// dst, issued_time
    REP(i, num_E) {
        int tmp_u, tmp_v, tmp_d; cin >> tmp_u >> tmp_v >> tmp_d;
        edge tmp1, tmp2;
        tmp1.to = tmp_u; tmp1.cost = tmp_d;
        tmp2.to = tmp_v; tmp2.cost = tmp_d;
        G[tmp_u].push_back(tmp2);
        G[tmp_v].push_back(tmp1);
    }
    int T; cin >> T;
    REP(t, T) {
        int num_O; cin >> num_O;
        REP(i, num_O) {
            int tmp_id, tmp_dst; cin >> tmp_id >> tmp_dst;
            v_O.push_back(make_pair(t,tmp_dst));
        }
    }
    //handle steps
    int car_pos = 1;
    sort(v_O.begin(),v_O.end(),[](const pair<int,int>& lhs, const pair<int,int>& rhs){
        if (lhs.first == rhs.first) return lhs.second < rhs.second;
        else return lhs.first < rhs.first;
    });
    // 1の隣からの注文のみ対応する
    int leave = -1;
    int to_dst = 0;
    REP(t, T) {
        auto res = lower_bound(v_O.begin(), v_O.end(), make_pair(t,VERTEX_MAX), [](const pair<int,int>& lhs, const pair<int,int>& rhs){
            if (lhs.first == rhs.first) return lhs.second < rhs.second;
            else return lhs.first < rhs.first;
        });
        if (leave == -1) {
            for (auto itr = v_O.begin(); itr != res ;itr++){
                int target_dst = itr->second;
                for(auto e: G[1]) {// 店舗からダイレクトにつながっているところだけ
                    if (e.to == target_dst) {
                        leave = target_dst;
                        to_dst = e.cost;
                    }
                }
            }
        }
        if (leave == -1 || leave == 0) {
            cout << -1 << endl;
        }
        else {
            if (to_dst == 0) {
                leave = 0;
                cout << -1 << endl;
            }
            else {
                cout << leave << endl;
                to_dst--;
            }
        }
    }
    return 0;
}


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

int main() {
  int n;
  vector<int> X(200, 0);
  rep(i, 200) X[i]=i*(i+1)*(i+2)/6;
  int INF=1e9;
  int MAX_N=1000001;
  vector<int> dp(MAX_N, INF);
  vector<int> dp2(MAX_N, INF);
  dp[0]=0;
  rep(i, 200) {
    for (int j=X[i]; j<MAX_N; j++) {
      dp[j]=min(dp[j], dp[j-X[i]]+1);
    }
  }
  dp2[0]=0;
  rep(i, 200) {
    for (int j=X[i]; j<MAX_N; j++) {
      if (X[i]%2==0) continue;
      dp2[j]=min(dp2[j], dp2[j-X[i]]+1);
    }
  }

  while (1) {
    cin>>n;
    if (n==0) break;
    cout<<dp[n]<<" "<<dp2[n]<<endl;
  }
}



Measured memory_bytes: 10548
/*
    It’s Always Darkest Before the Dawn
                This Time is that Darkness in you Life
                                                            */
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define pb push_back  
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
 
const ll mod=1e9+7,di=998244353,N=3e5+1;
 
bool IsQuery=false; 
ll q=1,a[N];
 
map<int,vector<int>> edge;
map<int,bool> occ;
 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
void solve(){
	
  	ll n,W;
  	cin>>n>>W;
  	
  	ll w[n],v[n];
  
  	for(int i=0;i<n;i++)
      cin>>w[i]>>v[i];
  	
  	ll dp[100001];
  	
  	for(int i=0;i<=1e5;i++)
      dp[i]=INT_MAX;
  	
  	dp[0]=0;
  
  	for(int i=0;i<n;i++){
    	
      for(int j=1e5;j>=0;j--){
        if(j+v[i]<=1e5)
        dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
      }
    }
    
  	for(int i=1e5;i>=0;i--){
    	if(dp[i]<=W){
          cout<<i;
          return;
        }
    }
  	
    return;   
} 
int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    if(IsQuery)
    cin>>q;
 
    for(int i=0;i<q;i++){
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4404
#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 f(int x){
	int b = 1; 
	while(b <= x) b *= 2;
	return b;
}

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

    int n; cin >> n;
    map<int, int> cnt;
    vi a(n); for(auto& e : a) cin >> e, cnt[e]++;
    sort(_all(a));

    int res = 0;
    rrep(i, n){
    	int e = a[i];
    	if(cnt[e] == 0) continue;

    	int b = f(a[i]) - e;
    	if(cnt[b] >= (b == e ? 2:1)){
    		cnt[b]--;
    		cnt[e]--;
    		res++;
    	}
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 19840
#include <iostream>
using namespace std;
int ab[10000],bc[10000],ac[10000],ans=6000,na,nb,nc,L,R;
string a,b,c;
bool ch(char a,char b){
    return (a==b||a=='?'||b=='?');
}
int main(void){
    cin>>a>>b>>c;
    na=a.size();
    nb=b.size();
    nc=c.size();
    for(int i=0;i<na;i++){
        for(int j=0;j<nb;j++){
            if(!ch(a[i],b[j]))ab[i-j+5000]=1;
        }
    }
    for(int i=0;i<na;i++){
        for(int j=0;j<nc;j++){
            if(!ch(a[i],c[j]))ac[i-j+5000]=1;
        }
    }
    for(int i=0;i<nb;i++){
        for(int j=0;j<nc;j++){
            if(!ch(b[i],c[j]))bc[i-j+5000]=1;
        }
    }
    for(int i=-4000;i<=4000;i++){
        for(int j=-4000;j<=4000;j++){
            if(ab[i+5000]==0&&ac[j+5000]==0&&bc[j-i+5000]==0){
                L=min(0,min(i,j));
                R=max(na,max(i+nb,j+nc));
                //cout<<ans<<" "<<R<<L<<endl;
                ans=min(ans,R-L);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
N, Y = map(int, input().split())

f = False
for i in range(N+1):
    if f:
        break
    for j in range(N+1-i):
        k = N-i-j
        if 10000*i+5000*j+1000*k == Y:
            print('{} {} {}'.format(i, j, k))
            f = True
            break
if not f:
    print('-1 -1 -1')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    int a,p;
    cin>>a>>p;
    p+=a*3;
    cout<<p/2<<endl;


}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
int main(void){
int n;
  scanf("%d",&n);
  char s[n][100],x[100];
  int t[n];
  for(int i=0;i<n;i++){
    scanf("%s%d",s[i],&t[i]);
  }
  scanf("%s",&x);
  int sum=0,start=0;
  for(int i=0;i<n;i++){
	if(strcmp(s[i],x)==0){
      start=1;
      continue;
    }
    if(start)
    sum+=t[i];
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(void){
    int r, c, i, j;
    int h[101][101] = {0};
     
    scanf("%d %d", &r, &c );
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &h[i][j]);
        }
    }
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            h[i][c] += h[i][j];
        }
    }
     
    for(j = 0; j < c + 1; j++){
        for(i = 0; i < r; i++){
            h[r][j] += h[i][j];
        }
    }
    for(i = 0; i < r + 1; i++){
        for(j = 0; j < c + 1; j++){
            printf("%d", h[i][j]);
            if(j != c){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 652
#include <stdio.h>
int main(void){
    int h, w, i, j;
    
    while(1){
    
        scanf("%d %d",&h,&w);
        if(h == 0 && w == 0){
           break;
        }
        else{
            for(i = 0; i < h; i++){
                for(j = 0; j < w; j++){
                    printf("#");
                }
            printf("\n");    
            }
        printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2056
N, M = map(int, input().split())

X_array = list(map(int, input().split()))

X_array.sort()
# print(X_array)
diff_array = [(X_array[i + 1] - X_array[i]) for i in range(M - 1)]
# print(diff_array)
diff_array.sort()
if N != 1:
    print(sum(diff_array[:-(N - 1)]))
else:
    print(sum(diff_array))

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

int main() {
	vector<int> a(1000100);
	cin >> a[0];
	if((a[0]-2)*(a[0]-1)*(a[0]-4) == 0){
		cout << 4 << endl;
		return 0;
	}
	for(int i = 0 ; i < 1000000; i++){
		if(a[i]%2 == 0){
			a[i+1] = a[i]/2;
		}else{
			a[i+1] = a[i]*3+1;
		}
		if(a[i+1] == 4){
		cout << i+5 << endl;
		return 0;
		}
	}
}

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

#define int long long

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

signed main() {
    int N, D, X;
    int A[100];
    cin >> N >> D >> X;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        X += (D - 1) / A[i] + 1;
    }
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int A[n],sum=0;
  for(int i=0;i<n;i++){
    cin>>A[i];
    sum+=A[i];
  }
  int r=0;
  for(int i=0;i<n;i++){
    if(A[i]*4*m>=sum)
      r++;
  }
  if(r>=m)
    cout<<"Yes";
  else
    cout<<"No";
}

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

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m) {
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  rep(i,n) {
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 892
// B - Count ABC
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string S; cin>>N>>S;
	int ans = 0;
	for(int i=0; i<N-2; ++i) if(S.substr(i,3)=="ABC") ans++;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
L=[]
M=[]
for i in range(5):
	X=int(input())
	L.append(X)
	M.append(X%10)
tmp=float("inf")
for i in range(5):
	if M[i]!=0:
		tmp=min(tmp,M[i])
cmd=0
ans=0
for i in range(5):
	if M[i]==tmp and cmd==0:
		ans+=L[i]
		cmd+=1
	else:
		if L[i]%10==0:
			ans+=L[i]
		else:
			ans+=((L[i]//10)+1)*10
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int n;
  cin >> n;
  int num = 1;
  while(num<=n){
    num = num*2;
  }
  cout << num/2 << endl;
  return 0;
}

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

bool not_prime[127160];
bool not_prime_judge(int N) {
  if (N == 1) return true;
  for (int i = 2; i * i <= N; i++) {
    if (N % i == 0) return true;
  }
  return false;
}

int main() {
  int Q;
  cin >> Q;
  vector<pair<int, int>> num(Q);
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    num[i] = make_pair(l, r);
  }
  for (int i = 3; i < 127160; i++) {
    if (not_prime[i]) continue;
    if (not_prime_judge(i)) {
      for (int j = i; j < 127160; j += i) not_prime[j] = true;
      not_prime[i] = true;
    } else if (not_prime_judge((i + 1) / 2)) {
      not_prime[i] = true;
    } else
      not_prime[i] = false;
  }

  not_prime[0] = not_prime[1] = not_prime[2] = true;

  vector<int> sum(127160, 0);
  sum[0] = 0;
  for (int i = 0; i < 127160; i++) {
    if (not_prime[i])
      sum[i] = sum[i - 1];
    else
      sum[i] = sum[i - 1] + 1;
  }


  for (int i = 0; i < Q; i++) {
    int l = num[i].first, r = num[i].second;
    if (l == 0)
      cout << sum[r] << endl;
    else
      cout << sum[r] - sum[l - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 2048
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min(a)
min_b = min(b)
ans = min_a + min_b
for _ in range(M):
    i, j, c = map(int, input().split())
    ans = min(ans, a[i - 1] + b[j - 1] - c)
print(ans)

Measured memory_bytes: 18612
import numpy as np

S = list(input())

zero_one = list('01'*(len(S)//2))
if len(S)%2 == 1:
    zero_one.append('0')
 
one_zero = list('10'*(len(S)//2))
if len(S)%2 == 1:
    one_zero.append('1')
    
S = np.array(S)
zero_one = np.array(zero_one)
one_zero = np.array(one_zero)

ans = min(np.sum(S==zero_one),np.sum(S==one_zero))

print(ans)

Measured memory_bytes: 15440
import numpy as np
import time
import random

start_time = time.time()

def calc(d, q):
    select_rand = select.copy()
    select_rand[d] = q
    last = [0] * 26
    satisfied_rand = 0
    for i in range(1, D+1):
        t = select_rand[i-1]
        satisfied_rand += s[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            satisfied_rand -= c[j] * (i-last[j])
    return (satisfied_rand, select_rand)

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

c = np.array(c)

last = [0] * 26
select = []
satisfied = 0
for i in range(1, D+1):
    last_d = [c[j]*(i-last[j]) for j in range(26)]
    last_d_sum = sum(last_d)
    #選択肢A 満足度の高いものから選ぶ
    s_d = np.array(s[i-1])
    maxindexA = np.argmax(s_d)
    satis_optA = s_d[maxindexA] - last_d_sum + last_d[maxindexA]
    
    #選択肢B コストが大きいものから選ぶ
    last_d = np.array([c[j]*(i-last[j]) for j in range(26)])
    maxindexB = np.argmax(last_d)
    satis_optB = s_d[maxindexB] -last_d_sum + last_d[maxindexB]

    if satis_optA >= satis_optB:
        #Aを選択
        select.append(maxindexA+1)
        satisfied += satis_optA
        last[maxindexA] = i
    else:
        #Bを選択
        select.append(maxindexB+1)
        satisfied += satis_optB
        last[maxindexB] = i

while time.time() - start_time < 1.75:
    d = random.randint(0, D-1)
    q = random.randint(1, 26)
    result = calc(d, q)
    if satisfied < result[0]:
        select = result[1]

for i in range(D):
    print(select[i])


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

int main(){
  int d,sum;
  while(cin>>d){
    sum=0;
    for(int i=0;i*d<600;i++){
      sum+=d*(i*d)*(i*d);
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <ctype.h>
#define FOR1toN(a) for(int i=1;i<=a;i++)
#define FOR0ton(a) for(int i=0;i<a;i--) 
using namespace std;



int main()
{
	//freopen("in.txt","r",stdin);
	int n;
	cin>>n;
	int cnt[1000000];
	int arr1[1000000];

	memset(cnt,0,sizeof(cnt));
	memset(arr1,0,sizeof(arr1));

    long long sum=0;
	for(int i=1;i<=n;i++)
	{

		int tmp;
		cin>>tmp;
		sum+=tmp;
		arr1[i]=tmp;
		cnt[tmp]++;
	}

	int q;
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		long long a,b;
		cin>>a>>b;
		sum-=(cnt[a]*a);
		sum+=(cnt[a]*b);
		cnt[b]+=cnt[a];
		cnt[a]=0;/*
		for(int i=1;i<=n;i++)
			{
				cout<<arr1[i]<<" ";
			}
			cout<<endl;*/
		cout<<sum<<endl;
	}



   return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	ll P[5];
	ll N; cin >> N;

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

	sort(P,P+5);

	cout << 5+(N-1)/P[0] << endl;

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b;
    scanf("%lld %lld",&a, &b);
    for(long long int i=0;i<a || i<b;i++){
        if(abs(a-i)==abs(b-i)){
            printf("%d\n",i);
            return 0;
        }
   }
   printf("IMPOSSIBLE\n");
    return 0;
}



Measured memory_bytes: 256