akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
bom = []
for i in range(H):
    bom.append(list(input()))

for h in range(H):
    for w in range(W):
        if bom[h][w] == "#":
            continue

        cnt = 0
        for x in range(-1, 2):
            for y in range(-1, 2):
                if 0 <= h+x < H and 0 <= w+y < W:
                    if bom[h+x][w+y] == "#":
                        cnt += 1
        bom[h][w] = str(cnt)
for i in bom:
    print("".join(i))


Measured memory_bytes: 3188
MOD = 10**9+7
n = int(input())
S = [1]*n
D = [1]*(n+1)
for i in range(n):
  D[i+1] = D[i]*2 % MOD
for i in range(n-1):
  S[i+1] = (S[i]*2 + D[i+1]) % MOD
T = S[::-1]
C = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
  ans += C[i]*((D[n-(i+1)]+T[i])*D[i]) % MOD
  ans %= MOD
ans = ans*D[n-1]%MOD
print(ans)

Measured memory_bytes: 44716
#include<iostream>
using namespace std;
int main()
{
	long long r,d,x2000,a[15];
	cin>>r>>d>>x2000;
	a[0]=x2000;
	for(int i=1;i<=10;i++)
	{
		a[i]=a[i-1]*r-d;
	}
	for(int i=1;i<=10;i++)
	{
		cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long X = sc.nextLong();

    sc.close();

    int i = 0;
    long count = 0;

    while (count < X) {
      i++;
      count += i;
    }

    System.out.println(i);
    
  }

}

Measured memory_bytes: 21972
import collections

def solve():
    N = int(input())
    A = []
    B = []
    for i in range(N):
        (a, b) = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)

    pq = sorted([(a,b) for a, b in zip(A, B)], key=lambda x: sum(x))
    pq = collections.deque(pq)
    # print(pq)

    score = [0, 0]
    idx = 0
    while pq:
        x = pq.pop()
        score[idx] += x[idx]
        idx = (idx + 1) % 2
    # print(score)

    return score[0] - score[1]


def main():
    ans = solve()
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 24044
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int k=0;
    int s=0;
    int s1;
    int s2;
    int k1;
    int k2;
    int ans=0;

    if(a>b){
      k=a;
      s=b;
    }else{
      k=b;
      s=a;
    }
    for(int i=s;i<k;i++){
      s1=a-i;
      s2=i-a;
      k1=b-i;
      k2=i-b;
      if(s1==k1){
        System.out.println(i);
        ans=1;
      }else if(s1==k2){
        System.out.println(i);
        ans=1;
      }else if(s2==k1){
        System.out.println(i);
        ans=1;
      }else if(s2==k2){
        System.out.println(i);
        ans=1;
      }
    }
    if(ans!=1){
      System.out.println("IMPOSSIBLE");
    }

  }
}


Measured memory_bytes: 22228
use proconio::{input, fastout, marker::Usize1};

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        arr: [(Usize1, usize); m],
    }

    let mut mm: Vec<Vec<usize>> = vec![vec![]; n];
    for &(p, y) in &arr {
        mm[p].push(y);
    }

    for v in mm.iter_mut() {
        v.sort();
    }

    for &(p, y) in &arr {
        println!("{:06}{:06}", p+1, mm[p].binary_search(&y).unwrap()+1)
    }
}


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

using namespace std;

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

  int n;
  cin >> n;

  vector<vector<int>> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      int xx, yy;
      cin >> xx >> yy;
      x[i].push_back(--xx);
      y[i].push_back(yy);
    }
  }

  int ans = 0;
  for (int i = 1; i < (1 << n); ++i) {
    bool ok = true;
    for (int j = 0; j < n; ++j) {
      if (!(i & (1 << j))) continue;
      for (int k = 0; k < x[j].size(); ++k) {
        // cerr << bitset<3>(i) << ": " << x[j][k] << "-" << ((i >> x[j][k]) &
        // 1)
        //      << "-" << y[j][k] << ", ";
        if (((i >> x[j][k]) & 1) != y[j][k]) {
          ok = false;
          break;
        }
      }
      // cerr << '\n';
    }
    // cerr << '\n';
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL n; cin >> n;
		cout << ((n + 1) / 2) << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
k, s = gets.split(' ').map(&:to_i)
ans = 0

# k**3だと2500**3の時に計算時間が間に合わなくなるため、2500**2までに抑える
for x in 0..k do
  for y in 0..k do
    # この時点でzは一意に定まっている
    # あとは、念のためｚが制約を満たしているかを確認して、条件を満たしていれば加算する
    z = s - x - y
    ans += 1 if z >= 0 && z <= k
  end
end

p ans

Measured memory_bytes: 14212
#include<stdio.h>
#include <string.h>
int main()
{
	int a,b,c,k,i;
	scanf("%d%d%d",&a,&b,&k);
	if(k<(b-a+1)/2 || k==(b-a+1)/2){
		c=a;
		for(i=0;i<k;i++)
		{
			printf("%d\n",c);
			c++;
		}
		c=b-k+1;
		for(i=0;i<k;i++)
		{
			printf("%d\n",c);
			c++;
		}
	}
	else{
		c=a;
		for(i=0;i<b-a+1;i++)
		{
			printf("%d\n",c);
			c++;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a1,a2,a3,a4,n;
int doit(int x){
		if (x&1)return min(a1*4,min(a2*2,a3));
		return 0;
	}
signed main(){
	ios::sync_with_stdio(false);
	cin>>a1>>a2>>a3>>a4>>n;
	cout<<min(a1*8,min(a2*4,min(a3*2,a4)))*(n/2)+doit(n%2)<<endl;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 110, M = 1010, INF = 0x3f3f3f3f;

int n, m;
int f[N][N];
struct Edge
{
	int a, b, c;
}e[M];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			if (i != j) f[i][j] = INF;
			else f[i][j] = 0;

	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		cin >> a >> b >> c;
		e[i] = {a, b, c};
		f[a][b] = f[b][a] = min(f[a][b], c);
	}
	
	for (int k = 1; k <= n; k ++ )
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
				
				
	int res = 0;
	for (int i = 0; i < m; i ++ )
	{
		int a = e[i].a, b = e[i].b, c = e[i].c;
		if (f[a][b] != c) res ++ ;
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<memory.h>
#include<set>
#include<map>
#include<cmath>
#include<time.h>
#include<bitset>
#include<iomanip>
#include<time.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N = 1e6 + 5, M = 1e9 + 7;
const double PI = acos(-1);
int n,k, a[N],idx;
int main() {
	
	scanf("%d%d", &n,&k);
	for (int i = 0;i < n;i++) {
		scanf("%d", &a[i]);
		if (a[i] == 1)idx = i;
	}
	int ans = 0;
	for (int i = 0;i < n - 1;i=i+k-1) {
		ans++;
	}
	cout << ans << endl;
	
}


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

int main()
{
       int  a,b,x,y,z;
       cin>>a>>b;
       x=a+b;
      y=a-b;
       z=a*b;

a=max(x,y);
b=max(a,z);
cout<<b<<endl;

       //else cout<<a*b<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];
int dp[100005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++){
	dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(lambda x: (x[0],int(x[1])),input().split()))

def BubbleSort(A,N):
    C = [[0,0] for _ in range(N)]
    for i in range(N):
        C[i][0] = A[i][0]
        C[i][1] = A[i][1]
    for i in range(N):
        for j in range(i+1,N)[::-1]:
            if C[j][1] < C[j-1][1]:
                C[j-1],C[j] = C[j],C[j-1]
    return C

def SelectionSort(A,N):
    C = [[0,0] for _ in range(N)]
    for i in range(N):
        C[i][0] = A[i][0]
        C[i][1] = A[i][1]
    for i in range(N):
        minj = i
        for j in range(i,N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i],C[minj] = C[minj],C[i]
    return C

B = BubbleSort(A,N)
S = SelectionSort(A,N)

print(*list(map(lambda x:''.join(map(str,x)),B)))
print('Stable')
print(*list(map(lambda x:''.join(map(str,x)),S)))
print('Stable' if B==S else 'Not stable')


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
ll dp[1010][1<<12];
const ll inf = 1e18;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
  Fill(dp,inf);
  int n,m;
  cin >> n >> m;
  vl a(m),open(m,0);
  rep(i,m){
    int b;
    cin >> a[i] >> b;
    rep(j,b){
      int c;
      cin >> c;
      open[i]|=(1<<(c-1));
    }
  }
  dp[0][0] = 0;
  rep(i,m){
    rep(j,(1<<n)){
      mins(dp[i+1][j],dp[i][j]);
      mins(dp[i][j|open[i]],dp[i][j]+a[i]); 
    }
  }
  ll ans;
  if(dp[m][(1<<n)-1] == inf) ans = -1;
  else ans = dp[m][(1<<n)-1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 35964
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	int a[]=new int[30];
	for(int i=0;i<28;i++)
	    {
		int n=scan.nextInt()-1;
		a[n]++;
	    }
	for(int i=0;i<30;i++)
	    {
		if(a[i]==0)System.out.println((i+1));
	    }
    }
}

Measured memory_bytes: 17200
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

static int64_t kRem = 1000000007;

// sqrt(n) までの素数を求める。1000014129 (31623 * 31623) まで対応
void create_primes(int n, bitset<31624>& primes) {
	primes.flip();

	int u_b = sqrt(n + 1);
	assert(u_b < 31624);

	{
		for (int j = 4; j <= u_b; j += 2) {
			primes.reset(j);
		}
	}
	for (int i = 3; i <= u_b; i += 2) {
		if (!primes.test(i)) continue;

		for (int j = i * 2; j <= u_b; j += i) {
			primes.reset(j);
		}
	}
}

struct FactorInfo {
	int v;
	int c;
};

// n の素因数分解を行う。 
vector<FactorInfo> make_factors(int n)
{
	bitset<31624> primes;
	create_primes(n, primes);

	int v     = n;
	int limit = sqrt(n + 1);

	vector<FactorInfo> ans;
	FOR_LE(i, 2, limit) {
		if (!primes.test(i)) continue;

		int count = 0;
		while (v % i == 0) {
			v /= i;
			count++;
		}

		if (count != 0) {
			ans.push_back({ i, count });
		}
	}


	if (v != 1) {
		ans.push_back({ v , 1 });
	}

	return ans;
}


int64_t pow_rem(int64_t val, int64_t mul, int64_t rem)
{
	if (mul == 1) return val;

	int64_t ret = pow_rem(val, mul / 2, rem);
	ret *= ret;
	ret %= rem;

	if (mul & 1) {
		ret *= val;
		ret %= rem;
	}

	return ret;
}

int64_t pow_remdiv(int64_t val, int64_t rem)
{
	return pow_rem(val, rem - 2, rem);
}

uint64_t nCr(uint64_t n, uint64_t r) {
	if (n == 0) return 0;
	if (r > n) return 0;

	uint64_t ret = 1;
	for (uint64_t i = 0; i < r; i++) {
		ret = ret * (n - i);
		ret %= kRem;
		ret = ret * pow_remdiv(i + 1, kRem);
		ret %= kRem;
	}
	return ret;
}

int main()
{
	int n, m; cin >> n >> m;

	vector<FactorInfo> factors = make_factors(m);

	int64_t ans = 1;
	for (auto& factor : factors) {
		ans *= nCr(n + factor.c - 1, factor.c);
		ans %= kRem;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 105

int main(){

	int n,G[MAX][MAX],i,j,u,k,vertex;

	scanf("%d",&n);
	for(i = 1; i <= n;i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	for(i = 1; i <= n;i++){
		scanf("%d%d",&u,&k);
		for(j = 0; j < k; j++){
			scanf("%d",&vertex);
			G[i][vertex] = 1;
		}
	}
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			printf("%d",G[i][j]);
			if(j != n)
				printf(" ");

		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        int n,i,j,temp;
        long sum;
        int[] a;
        sum = 0;
        str = scan.nextLine();
        n = Integer.valueOf(str);
        a = new int[n];
        str = scan.nextLine();
        String[] num = str.split(" ", 0);
        for(i=0;i<n;i++){
            a[i] = Integer.valueOf(num[i]);
            sum += a[i];
        }
        for(i=0;i<n;i++){
            for(j=n-1;j>i;j--){
                if(a[j]<a[j-1]){
                    temp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = temp;
                }
            }
        }
        System.out.println(a[0]+" "+a[n-1]+" "+sum);
        scan.close();
    }
}


Measured memory_bytes: 31500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n, m;
    cin>>n>>m;
    pair<bool , ll> * a = new pair<bool , ll>[n];
    a[0].first = true;
    a[0].second = 1;
    for(int i=1;i<n;i++)
    {
        a[i].first = false;
        a[i].second = 1;
    }
    for(int i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        if( a[x].first  )
        {
            a[y].first = true;

        }
        a[x].second --;
        a[y].second ++;
        if( a[x].first && a[x].second <=0)
            a[x].first = false;
    }
    ll ans =0;
    for(int i=0;i<n;i++)
    {
        if( a[i].first == true && a[i].second >0)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define PB push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int D;
vl c, ans;
vvl s;

void init() {
    cin >> D;
    ans.assign(D, 0);
    c.resize(26);
    s.assign(D, vl(26));
    rep(t, 26) cin >> c[t];
    rep(d, D) rep(t, 26) {
        cin >> s[d][t];
    }
}

ll evaluate(vl typeOfDays, int numDays = D) {
    ll score = 0;
    vl lasts(26, 0);
    rep(d, numDays) {
        score += s[d][typeOfDays[d]];
        lasts[typeOfDays[d]] = d + 1;
        rep(t, 26) {
            score -= c[t] * (d - lasts[t] + 1);
        }
    }
    return score;
}

void solve() {
    rep(d,D) {
        ll mx = -1;
        vl cand = ans;
        rep(t,26) {
            cand[d] = t;
            ll sc = evaluate(cand,d+1);
            if (sc > mx) {
                mx = sc;
                ans = cand;
            }
        }
    }
    cerr << evaluate(ans) << endl;
}

void output() {
    rep(d,D) cout << ans[d]+1 << endl;
}

int main() {
    init();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  int H,W,N;
  cin >> H >> W;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i < N; i++)
    cin >> A[i];
  vector<vector<int> >C(H, vector<int>(W));
  int col = 0;
  for(int i=0; i < H; i++){
    if(i%2==0){
      for(int j=0; j < W; j++){
	C[i][j] = col+1;
	A[col]--;
	if(A[col] == 0)
	  col++;
      }
    }else{
      for(int j=W-1; j >= 0; j--){
	C[i][j] = col+1;
	A[col]--;
	if(A[col] == 0)
	  col++;
      }
    }
  }
  for(int i=0; i < H; i++){
    for(int j=0; j < W-1; j++){
      cout << C[i][j] << " ";
    }
    cout << C[i][W-1] << endl;
  }

  return 0;
}


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

using namespace std;


typedef long long ll;
int main() {
  ll c[4], u[4], n, ans = 0, k[4] = {4, 2, 1};
  for (int i = 0; i < 4; ++i) {
    cin >> c[i];
  }
  cin >> n;
  for (int i = 0; i < 4; ++i) {
    u[i] = c[i] * k[i] * 2;
  }
  u[3] = c[3];
  while (n) {
    ll mn = 8*1e8+1;
    int mni = -1;
    for (int i = 0; i < 4; ++i) {
      if (u[i] < mn) {
        mn = u[i];
        mni = i;
      }
    }
    u[mni] = 8*1e8+1;
    if (mni==3) {
      ans += (n-(n%2))*c[mni]/2;
      n %= 2;
    } else {
      ans += n*c[mni]*k[mni];
      n = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}

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


int main () {
  int A, B;
  cin >> A >> B;
  if (A % 2 == 0 || B % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

int main()
{
  int n;
  int64_t k;
  std::cin >> n >> k;
  std::map<int, int64_t> ab;
  for (int i = 0; i < n; ++i)
  {
    int a, b;
    std::cin >> a >> b;
    ab[a] += b;
  }
  int64_t count = 0;
  int ans = 0;
  for (const auto& itr : ab)
  {
    if (k <= count + itr.second)
    {
      ans = itr.first;
      break;
    }
    count += itr.second;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N)cin >> A[i];
    sort(ALL(A),greater<>());
    ll ans = 0;
    REP(i,N){
        if(i % 2 == 0){
            ans += A[i];
        }else{
            ans -= A[i];
        }
    }
    cout << ans << "\n";
}

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

int main(){
	int a, b, c, d;
	int d_ab, d_bc, d_ac;
	cin >> a >> b >> c >> d;
	d_ab = fabs(a - b);
	d_bc = fabs(b - c);
	d_ac = fabs(a - c);
	if(d_ab <= d && d_bc <= d || d_ac <= d){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0){
            System.out.print(" "+ i);
            continue;
            }
            int x = i;
            while(x > 0){
                if(x%10 ==3){
                System.out.print(" "+ i);
                break;
                }
                x /= 10;
            }
        }
System.out.println();
    }
}


Measured memory_bytes: 28660
import java.util.*;
class Main{
    public static void mktable(short[] dice, short[][] table){
        table[0][0] = dice[1];
        table[0][1] = dice[2];
        table[0][2] = dice[4];
        table[0][3] = dice[3];

        table[1][0] = dice[0];
        table[1][1] = dice[3];
        table[1][2] = dice[5];
        table[1][3] = dice[2];

        table[2][0] = dice[0];
        table[2][1] = dice[1];
        table[2][2] = dice[5];
        table[2][3] = dice[4];

        table[3][0] = dice[0];
        table[3][1] = dice[4];
        table[3][2] = dice[5];
        table[3][3] = dice[1];

        table[4][0] = dice[0];
        table[4][1] = dice[2];
        table[4][2] = dice[5];
        table[4][3] = dice[3];

        table[5][0] = dice[1];
        table[5][1] = dice[3];
        table[5][2] = dice[4];
        table[5][3] = dice[2];
    }
    public static boolean check(short[] dice, short[] dice2, short[][] table){
        int top, k; 
        for(top = 0; top < 6; top++){
            if(dice2[0] == dice[top]){
                for(k = 0; k < 4; k++){
                    if(dice2[1] == table[top][k]){
                        if(dice2[2] == table[top][(k+1)%4]){
                            if(dice2[4] == table[top][(k+2)%4]){
                                if(dice2[3] == table[top][(k+3)%4]){
                                    if(dice2[5] == dice[5-top]){
                                        System.out.println("No");
                                        System.exit(0);
                                   }
                                }
                            }   
                        }
                    }
                }
            }
        }
        return false;
    }


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

        short[][] dice_t = new short[100][6];
        short[][][] table = new short[100][6][4];

        short n = scanner.nextShort();
        for(short i = 0; i < n; i++){
            for(short j = 0; j < 6; j++)dice_t[i][j] = scanner.nextShort();
            mktable(dice_t[i], table[i]);
            for(short j = 0; j < i; j++){
                if(check(dice_t[j], dice_t[i], table[j])){
                    System.out.println("No");
                    System.exit(0);
                }
            }
        }
        System.out.println("Yes");
    }
}



Measured memory_bytes: 28864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  int a,b,h,m;
  cin >> a >> b >> h >> m;

  long double x = 1,ans,sh,sm,pi=acos(-1.0);
  sh = (x*h+x*m/60.0) / 12.0 * 2.0 * pi;
  sm = x*m/60.0 * 2.0 * pi;

  sh += pi/4.0;
  sm += pi/4.0;
  sh = 2.0*pi - sh;
  sm = 2.0*pi - sm;
  long double xh,yh,xm,ym;
  xh = x*a*cos(sh);
  yh = x*a*sin(sh);
  xm = x*b*cos(sm);
  ym = x*b*sin(sm);

  ans = sqrt((xh-xm)*(xh-xm)+(yh-ym)*(yh-ym));
  out(11) << ans << endl;

}



Measured memory_bytes: 4168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
using Int = long long;

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += A[i];
    }
    vector<pair<int, int>> B;
    for (int i = 0; i < N; i++) {
        B.emplace_back(abs(sum - N*A[i]), i);
    }
    cout << min_element(B.begin(), B.end())->second << endl;
    return 0;
}

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

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl

typedef long long ll;

void solve1()
{
    int n;cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    bool f = true;
    rep(i, n) {
        if(a[i]%2 == 0) {
            if(!(a[i]%3 == 0 || a[i]%5 == 0)) {
                f = false;
            }
        }
    }    

    string ans = f?"APPROVED":"DENIED";

    cout << ans << endl;
}

int main()
{
    solve1();
}

Measured memory_bytes: 3640
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

#define int ll


const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, a[N], ans, pref[N], cur;
map <int, int> t, m;
void upd(int pos) {
    for (; pos <= 1e18; pos = (pos | (pos + 1))) t[pos]++;
}
int get(int pos) {
    int res = 0;
    for (; pos >= 0; pos = ((pos & (pos + 1)) - 1)) res += t[pos];
    return res;
}
main() {
    file("threesum");
    //ios;
    cin >> n >> k;
    fo(i, 1, n, 1) cin >> a[i], pref[i] = (!i ? 0 : pref[i - 1]) + a[i], m[pref[i] - k * i], m[pref[i - 1] - k * i + k],
    m[pref[i]];
    for (auto &it : m) it.S = ++cur;
    fo(i, 1, n, 1) {
        upd(m[pref[i - 1] - k * i + k]);
        ans += get(m[pref[i] - k * i]);
    }
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 43904
#include<bits/stdc++.h>
using namespace std;
 
#define ll          int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        200005
#define mod         998244353  
 
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;
    cin>>n;
    x=(n/500)*1000;
    n=n%500;
    x+=(n/5)*5;
    cout<<x;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r = sc.nextInt();
		if(n < 10){
			r += (10 - n) * 100;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 21844
def main():
	linie = input()
	vector = [int(x) for x in linie.split()]	
	n = vector[0]
	y = vector[1]
	ok = 0
	nr1 = -1
	nr2 = -1
	nr3 = -1
	nr = n + 1
	for i in range(0, n + 1):
		for j in range(n + 1 - i):
				if i * 1000 + j * 5000 + (n - i - j) * 10000 == y:
					nr1 = i
					nr2 = j
					nr3 = (n - i - j)
	print(nr3, nr2, nr1)
 
 
if __name__ == "__main__":
	main()

Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
const int INF=1<<23;

int main() {
    ll n,a,b;
    while(true){
        cin>>n>>a>>b;
        if(n+a+b==0)break;
        vector<ll> v(n);
        rep(i,n){
            cin>>v[i];
        }
        sort(v.rbegin(),v.rend());
        ll gap=0;ll ans=0;
        for(ll i=a;i<=b;i++){
            ll g=v[i-1]-v[i];
            if(gap<=g){
                gap=g;
                ans=i;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}



Measured memory_bytes: 3008
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
nums = get_nums_l()

right = sum(nums)
left = 0
ans = 99999999999999999

for n in nums:
    left += n
    right -= n
    ans = min(ans, abs(left-right))

print(ans)

Measured memory_bytes: 38384
/*
https://atcoder.jp/contests/dp/tasks/dp_l
*/
import java.io.*;
import java.util.*;

public class Main {

    private static long solve(int n, long[] arr) {
        long[][] dp = new long[n][n];

        for (int i = n - 1; i >= 0; i--) {
            for (int j = i; j < n; j++) {
                if (i == j) {
                    dp[i][j] = arr[i];
                } else {
                    dp[i][j] = Math.max(arr[j] - dp[i][j - 1], arr[i] - dp[i + 1][j]);
                }
            }
        }
        // System.out.println(Arrays.deepToString(dp));
        return dp[0][n - 1];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextLong();
        }
        System.out.println(solve(n, arr));
        sc.close();
    }
}

Measured memory_bytes: 131184
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


#define MOD 1000000007


struct solve
{
	solve(){}
	ll operator()(int k, vll&a) {
		int n=a.size();
		vll ap, an;

		for(auto m:a)
		{
			if(m>=0) ap.push_back(m);
			else an.push_back(-m);
		}

		if(n==k)
		{
			ll ans=1;
			for(auto m:ap) ans=(ans*m)%MOD;
			for(auto m:an) ans=(ans*m)%MOD;
			if(an.size()&1)
			{
				return (MOD-ans)%MOD;
			}
			return ans;
		}

		if(ap.size()==0)
		{
			ll ans=1;
			if(k&1)
			{
				sort(an.begin(), an.end());
				for(int i=0;i<k;i++) ans=(ans*an[i])%MOD;
				return MOD-ans;
			}
			else
			{
				sort(an.rbegin(), an.rend());
				for(int i=0;i<k;i++) ans=(ans*an[i])%MOD;
				return ans;
			}
		}

		sort(ap.begin(), ap.end());
		sort(an.begin(), an.end());
		int api=(int)ap.size()-1, ani=(int)an.size()-1;
		ll ans=1;
		for(;k>=2;)
		{
			if(api<1 || ani<1) break;
			if(ap[api]*ap[api-1]>an[ani]*an[ani-1])
			{
				ans=(ans*ap[api])%MOD;
				api-=1;
				k--;
			}
			else
			{
				ans=(((an[ani]*an[ani-1])%MOD)*ans)%MOD;
				ani-=2;
				k-=2;
			}
		}
		for(;k>=2 && ani>=1;)
		{
			ans=(((an[ani]*an[ani-1])%MOD)*ans)%MOD;
			ani-=2;
			k-=2;
		}
		for(;k>=1 && api>=0;)
		{
			ans=(ans*ap[api])%MOD;
			api-=1;
			k--;
		}

		return ans;
	}
};

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

	for(;;)
	{
		int n, k;
		cin >> n >> k;
		if(cin.fail()) break;
		vll a(n);
		for(auto&m:a) cin >> m;
		cout << solve()(k, a) << "\n";
	}
	return 0;
}


Measured memory_bytes: 6900
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
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; }
typedef complex<double> P;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

long long int MOD = 1000000007;
int N;
int hoge[10]={2,3,4,5,6,8,9,10,12,14};
int main(){
	cin>>N;
	int M=N;
	vi a;
	if(N%2==1){
		a.pb(30);
		N--;
	}
	N=N/2;
	int cnt=0,keta=0;
	while(N){
		a.pb(keta*30+hoge[cnt]);
		a.pb((keta+1)*30-hoge[cnt]);
		cnt++;
		if(cnt==10){
			cnt=0;
			keta++;
		}
		N--;
	}
	if(M==3){
		cout<<2<<" "<<5<<" "<<63<<endl;
	}else{
		for(int i=0;i<a.size();i++)cout<<a[i]<<" ";
		cout<<endl;
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int W, H, N;
	cin >> W >> H >> N;

	Graph G(H, vector<int>(W));

	rep(i, N) {
		int x, y, a;
		cin >> x >> y >> a;
		
		if (a == 1)
			rep(j, H)
			rep(k, x)
			G[j][k]++;

		else if (a == 2)
			rep(j, H)
			for (int k = x; k < W; k++)
				G[j][k]++;

		else if (a == 3)
			rep(j, y)
			rep(k, W)
			G[j][k]++;

		else if (a == 4)
			for (int j = y; j < H; j++)
				rep(k, W)
				G[j][k]++;
	}

	int ans = 0;

	rep(i, H)
		rep(j, W)
			if (G[i][j] == 0)
				ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

for i in range(len(S)-len(T), -1, -1):
    tmp_str = S[i:i+len(T)]
    ans = ""
    for j in range(len(T)):
        if tmp_str[j] != T[j] and tmp_str[j] != "?":
            break
        ans += T[j]
        if j == len(T)-1:
            ans = S[:i] + ans + S[len(T)+i:]
            print(ans.replace("?", "a"))
            exit()
            
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll a, b, n;

void solve(){
    cin >> a >> b >> n;
    ll _max = 0, val, x;
    if(b > n)
        x = n;
    else if(b == n)
        x = n - 1;
    else
        x = b - 1;
    double t1 = (a * x) / b, t2 = x / b;
    val = floor(t1) - (a * floor(t2));
    // trace(x, val);
    _max = max(_max, val);
    cout << _max;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
  int H, W;
  
  while(1) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    else {
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          cout << "#";
        }
        cout << endl;
      }
      cout << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define pb push_back
#define li long int

using namespace std;

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

int main()
{
    FAST();
    int i,n;cin>>n;
    int h[n];
    int dp[n];
    dp[0]=0;
    for(i=0;i<n;i++)	cin>>h[i];
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
    	int a=dp[i-2]+abs(h[i]-h[i-2]);
		int b=dp[i-1]+abs(h[i]-h[i-1]);
		dp[i]=min(a,b);	
	}	
	cout<<dp[n-1];
    
}

Measured memory_bytes: 4436
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  vector<ll> dp(87);
  dp[0] = 2;
  dp[1] = 1;
  for (int i = 2; i <= 86; i++){
    dp[i] = dp[i - 1] + dp[i - 2];
  }
  int n;
  cin >> n;
  cout << (ll)dp[n] << endl;
}



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

int main() {
  int K;
  cin >> K;
  int L;
  int X = 10;
  int Y = 10;
  int c = 1;
  int d = 1;
  
  if(K % 7 == 0){
    L = 9 * K / 7;
    while(1){
      if(X % L == 1){
        cout << c << endl;
        break;
      }
      else if(c <= 9000000){
        X = (X % L) * 10;
        c++;
      }
      else{
        cout << -1 << endl;
        break;
      }
    }
  }
  else{
    L = 9 * K;
       while(1){
      if(X % L == 1){
        cout << d << endl;
        break;
      }
      else if(d <= 9000000){
        X = (X % L) * 10;
        d++;
      }
      else{
        cout << -1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3596
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))
for m in M:
    DP = [[False for _ in range(m + 1)] for _ in range(N + 1)]
    DP[0][0] = True
    for i in range(N):
        for j in range(m + 1):
            DP[i + 1][j] |= DP[i][j]
            if j - A[i] >= 0:
                DP[i + 1][j] |= DP[i][j - A[i]]
    if DP[N][m]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 6304
import java.util.*;
import static java.lang.System.*;

public class Main {

	
	class P {
		int x, y, count;
		P(int x, int y, int count) {
			this.x = x;
			this.y = y;
			this.count = count;
		}
	}
	
	Scanner sc = new Scanner(in);
	
	void run() {
		int w, h;
		while (true) {
			w = sc.nextInt(); h = sc.nextInt();
			if (w == 0) break;
			boolean[][] mapr = new boolean[h][w-1];
			boolean[][] mapc = new boolean[h-1][w];
			for (int i = 0; i < 2*h-1; i++) {
				if (i % 2 == 0) {
					for (int j = 0; j < w-1; j++) {
						mapr[i/2][j] = sc.nextInt() == 0;
					}
				} else {
					for (int j = 0; j < w; j++) {
						mapc[i/2][j] = sc.nextInt() == 0;
					}
				}
			}
			
			int[][] check = new int[h][w];
			Queue<P> q = new LinkedList<P>();
			q.add(new P(0,0,1));
			check[0][0] = 1;
			while(!q.isEmpty()) {
				P p = q.poll();
				if (p.x-1 >= 0 && mapr[p.y][p.x-1] && check[p.y][p.x-1] == 0) {
					check[p.y][p.x-1] = p.count+1;
					q.add(new P(p.x-1,p.y,p.count+1));
				}
				if (p.x+1 < w && mapr[p.y][p.x] && check[p.y][p.x+1] == 0) {
					check[p.y][p.x+1] = p.count+1;
					q.add(new P(p.x+1,p.y,p.count+1));
				}
				if (p.y-1 >= 0 && mapc[p.y-1][p.x] && check[p.y-1][p.x] == 0) {
					check[p.y-1][p.x] = p.count+1;
					q.add(new P(p.x,p.y-1,p.count+1));
				}
				if (p.y+1 < h && mapc[p.y][p.x] && check[p.y+1][p.x] == 0) {
					check[p.y+1][p.x] = p.count+1;
					q.add(new P(p.x,p.y+1,p.count+1));
				}
			}
			
			out.println(check[h-1][w-1]);
			
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(20, vector<int>(20, -1));
  vector<vector<int>> y(20, vector<int>(20, -1));
  REP(i, n){
    int d;
    cin >> d;
    a[i] = d;
    REP(j, d){
      cin >> x[i][j];
      cin >> y[i][j];
      x[i][j]--;
    }
  }
  int ans = 0;
  REP(s, 1<<n){
    int tmp = 0;
  bool flag = true;
    REP(i, n){
      if (s>>i & 1){
        int num = a[i];
        REP(j, num){
          if ((s>>x[i][j]  & 1) and y[i][j] == 0) {flag = false;}
          if (!(s>>x[i][j]  & 1) and y[i][j] == 1) {flag = false;}
        }
      }
    }
    REP(i, n){
      if (s>>i & 1) tmp++;
    };
    if (flag){ans = max(tmp, ans);}
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//  RegistrationContest
//
//  Created by Kadyrbek Narmamatov on 5/10/20.
//  Copyright © 2020 Kadyrbek Narmamatov. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    std::string s, t;
    bool flag = true;
    std::cin >> s >> t;
    if (s.length() + 1 == t.length()) {
        for (int i = 0 ; i < s.length() ; ++i) {
            if (s[i] != t[i]) {
                flag = false;
                break;
            }
        }
    } else {
        flag = false;
    }
    if (flag) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
      final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());

      System.out.println(n % 1000 == 0 ? 0 : 1000 - (n % 1000));
    }
  }
}


Measured memory_bytes: 32464
num_towns, cost_walk, cost_warp = map(int, input().split())
positions = list(map(int, input().split()))

total_cost = 0
for p1, p2 in zip(positions[:-1], positions[1:]):
    c_walk = (p2 - p1) * cost_walk
    if c_walk < cost_warp:
        total_cost += c_walk
    else:
        total_cost += cost_warp

print(total_cost)


Measured memory_bytes: 19972
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[100000];
int main() {
  cin>>n;
  for(int i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  int ans=0;
  int i=0,j,sum;
 while(i<n)
  {
  	j=i+1;
  sum=1;
 	while(a[i]==a[j])
 	{
 	sum++;
 	j++;
 	}
 	if(sum%2)
 	ans++;
 	i=j;
 }
 cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640