akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int A, B, K;
  cin >> A >> B >> K;

  int min_min = A;
  int min_max = A + K;
  int max_min = B - K + 1;
  int max_max = B;

  if (min_max > max_min)
  {
    for (int i = A; i <= B; i++)
    {
      cout << i << endl;
    }
    return 0;
  }

  for (int i = min_min; i < min_max; i++)
  {
    cout << i << endl;
  }
  for (int i = max_min; i <= max_max; i++)
  {
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    long long l, r;
    std::cin >> l >> r;

    r = std::min(l + 2019, r);
    long long ans = 2020;
    for (long long t = l; t <= r; t++) {
        for (long long s = t + 1; s <= r; s++) {
            ans = std::min(ans, t * s % 2019);
        }
    }

    std::cout << ans << std::endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  string res;
  if(A + B > C + D)
    res = "Left";
  else if(A + B < C + D)
    res = "Right";
  else {
    res = "Balanced";
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    static boolean arr[];

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++)arr[i]=s.nextInt();
        long min = Long.MAX_VALUE;
        for(int i=-100;i<=100;i++){
            long sum=0;
            for(int j=0;j<n;j++){
                sum+=Math.pow(Math.abs(arr[j]-i),2);
            }
            min = Math.min(min,sum);
        }
        System.out.println(min);

    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

bool ans(ll n){
    ll a[n];rep(i,0,n-1)cin>>a[i];
    bool dp[n][n+1];memset(dp,false,sizeof(dp));
    rep(i,0,n-1)dp[i][i]=true;
    for(ll c=2;c<=n;c+=2){
        rep(i,0,n-1){
            ll j=i+c;//[i,j)
            if(j>n)continue;
            if(dp[i+1][j-1]&&abs(a[i]-a[j-1])<=1)dp[i][j]=true;
            for(ll k=i+2;k<=j-2;k+=2){
                if(dp[i][k]&&dp[k][j])dp[i][j]=true;
            }
        }
    }
    /*rep(i,0,n-1){
        rep(j,0,n){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;*/
    ll dp2[n][n];memset(dp2,0,sizeof(dp2));
    rep(i,0,n-1){
        ll ma=0;
        rep(j,i+1,n){
            if(dp[i][j])ma=j-i;
            dp2[i][j-1]=ma;
        }
    }
    /*rep(i,0,n-1){
        rep(j,0,n-1){
            cout<<dp2[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;*/
    ll cou[n][n];
    memset(cou,0,sizeof(cou));
    rep(i,0,n-2){
        rep(j,i,n-1){
            if(i-1>=0)cou[i+1][j]=max(cou[i][j],cou[i][i-1]+dp2[i][j]);
            else cou[i+1][j]=max(cou[i][j],dp2[i][j]);
        }
    }
    /*rep(i,0,n-1){
        rep(j,0,n-1){
            cout<<cou[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;*/
    
    cout<<cou[n-1][n-1]<<endl;
    return 0;
}

int main(){fastio
    while(1){
        ll n;cin>>n;
        if(n==0)return 0;
        ans(n);
    }
    return 0;
}



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

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    int a, b, c;
    cin >> a >> b >> c;
    if (b * c >= a) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  string s;
  cin >> n >> s;

  int i = 0;
  int ans = 0;
  while (i < n) {
    while(s[i] == s[i+1]) {
      i++;
    }
    ans++;
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

using namespace std;


typedef long long lolo;
int N, *A;
lolo sum= 0, *sumA, allsum= 0, ans= 0, mini;

int main(){
	
	cin>> N;

	A= new int[N];
	sumA= new lolo[N];

	for(int i= 0; i< N; i++){
		cin>> A[i];
		allsum+= A[i];
		sumA[i]= allsum;
	}
	lolo div= allsum/ 3, fp1= 0, fp1num, fp2, fp2num, fp3, shiftsum= 0, com;
	for(int c= 0; c< N; c++){
		if(c!= 0) shiftsum= sumA[c- 1];
		com= 0;
		for(int i= c; i< N+ c; i++){
			if(i< N) com= sumA[i]- shiftsum;
			else com+= A[i- N];
			if(com<= div){
				fp1= com;
				fp1num= i;
			}
			else if(com- fp1>= div){
				fp2= com- fp1;
				fp2num= i;
				fp3= allsum- (fp1+ fp2);
				break;
			}
		}
		mini= min(fp1, fp3);
		ans= max(ans, mini);
	}
	
	cout<< ans<< endl;

	delete[] A;
	delete[] sumA;
}

Measured memory_bytes: 2324
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int N;
	cin>>N;
	vint X;
	for(int i=0;i<N;i++){
		int x;
		cin>>x;
		X.pb(x);
	}

	int ans=INF;
	for(int i=0;i<150;i++){

		int cost=0;
		for(int x:X)
			cost+=(i-x)*(i-x);

		ans=min(ans, cost);
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	int n;
	cin >> n;
	int a = n / 4, b = n / 7;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			if (4 * i + 7 * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

divisor = []

for i in range(int(N ** 0.5)+1, 0, -1):
    if N % i == 0:
        divisor.append(i)
        break

B = N // divisor[0]
# print(B, divisor)
if len(str(divisor[0])) > len(str(B)):
    print(len(str(divisor[0])))
else:
    print(len(str(B)))

Measured memory_bytes: 3064
fun main() = abc167e()

@OptIn(ExperimentalStdlibApi::class)
fun abc167e() {
    val (n, m, k) = readLine()!!.split(' ').map { it.toInt() }

    val biCoef = BiCoef(n)
    var answer = 0L

    for (x in 0..k) {
        answer += ((m * modPow(m - 1L, n - x - 1L)) % MOD * biCoef.nCr(n - 1, x)) % MOD
        answer %= MOD
    }

    println(answer)
}

private const val MOD = 998244353

private fun modPow(n: Long, p: Long): Long {
    var x = n
    var y = p
    var result = 1L
    x %= MOD
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % MOD
        y = y shr 1
        x = (x * x) % MOD
    }
    return result
}


@Suppress("unused")
private class BiCoef(max: Int) {
    private val fact = LongArray(max + 1)
    private val fInv = LongArray(max + 1)
    private val inv = LongArray(max + 1)

    init {
        fact[0] = 1
        fact[1] = 1
        fInv[0] = 1
        fInv[1] = 1
        inv[1] = 1
        for (i in 2..max) {
            fact[i] = fact[i - 1] * i % MOD
            inv[i] = MOD - inv[(MOD % i).toInt()] * (MOD / i) % MOD
            fInv[i] = fInv[i - 1] * inv[i] % MOD
        }
    }

    fun fact(n: Int): Long = if (n < 0) 0 else fact[n]
    fun inv(n: Int): Long = if (n < 0) 0 else inv[n]
    fun fInv(n: Int): Long = if (n < 0) 0 else fInv[n]
    fun comb(n: Int, k: Int): Long = nCr(n, k)
    fun nCr(n: Int, k: Int): Long = if (n < k || n < 0 || k < 0) 0 else fact[n] * (fInv[k] * fInv[n - k] % MOD) % MOD
    fun perm(n: Int, k: Int): Long = nPr(n, k)
    fun nPr(n: Int, k: Int): Long = if (n < k || n < 0 || k < 0) 0 else fact[n] * fInv[n - k] % MOD % MOD
}


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


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

    int c = 0;
    vector<int> s;
    for(int i=0; i<keys.length(); i++) {
        if(keys[i] == '0'){
            s.push_back(0);
            c++;
        }
        else if(keys[i] == '1'){
            s.push_back(1);
            c++;
        }
        else if(s.size() > 0){
            s.pop_back();
            c--;
        }
    }

    for(int i=0; i<c; i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

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

	


int main(){
    cout << fixed << setprecision(12);
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ll ans;
    ans=w*h/2;
    cout<<ans<<" ";
    if(x==w/2&&y==h/2){
        cout<<1<<endl;
    }else{cout<<0<<endl;}
}

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

char dir[4][4]{ "ABC","DEF","GHI" };
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	rep(t, 1000) {
		string s; cin >> s;
		int x = (s[0] - 'A') / 3, y = (s[0] - 'A') % 3;
		bool flag = true;
		for (int i = 1; i < s.size(); i++) {
			bool ok = false;
			rep(j, 4) {
				int nx = x + dx[j], ny = y + dy[j];
				if (0 <= nx&&nx < 3 && 0 <= ny&&ny < 3 && dir[nx][ny] == s[i]) {
					ok = true;
					x = nx, y = ny;
					break;
				}
			}
			if (!ok) {
				flag = false;
				break;
			}
		}
		if (flag)cout << s << endl;
	}
}

Measured memory_bytes: 3200
xh=[]
n,d,a=map(int,input().split())
for _ in range(n):
	x,h=map(int,input().split())
	xh.append([x,h])
xh.sort()
ans=0
cnt=[0]*n
j=0
limit=[]
for i in range(n):
	while xh[j][0]-xh[i][0]<=2*d:
		j+=1
		if j==n:
			break
	j-=1
	limit.append(j)
num=[0]*(n+1)
cnt=0
for i in range(n):
	xh[i][1]-=(ans-cnt)*a
	damage_cnt=max(0,(xh[i][1]-1)//a+1)
	ans+=damage_cnt
	num[limit[i]]+=damage_cnt
	cnt+=num[i]
print(ans)


Measured memory_bytes: 52836
#include <iostream>
#include <vector>
#include <algorithm>

 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> l;
 
  for (int i = 0; i< 2*n;i++) {
    int t;
    cin >> t;
    l.push_back(t);
  }
 
  sort(l.begin(), l.end());
 
  int sum = 0;
  for (int i = 0; i< n; i++) {
    sum += l[2*i];
  }
 
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::cmp;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut k: u64,
        r#as: [u64; n],
        bs: [u64; m],
    }

    let mut i = 0;
    let mut j = 0;

    while i < n && r#as[i] <= k {
        k -= r#as[i];
        i += 1;
    }
    while j < m && bs[j] <= k {
        k -= bs[j];
        j += 1;
    }

    let mut max = i + j;

    while i > 0 {
        k += r#as[i - 1];
        i -= 1;
        while j < m && bs[j] <= k {
            k -= bs[j];
            j += 1;
        }
        max = cmp::max(max, i + j);
    }

    println!("{}", max);
}


Measured memory_bytes: 9328
def main():
  n, *a = map(int,open(0).read().split())
  d, s = [0]*n, 0
  for i, x in enumerate(a):
    if i+x<n:
      d[i+x]+=1
    if i-x>=0:
      s+=d[i-x]
  print(s)
main()

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

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int dist[31][31];
int cap[31][31];
bool visit[31][31][31]; // city, speed, pre
const int INF = 1e7;

struct node {
	int s, p, c;
	double t;
	node(int _s, int _p, int _c, double _t) {
		s = _s;
		p = _p;
		c = _c;
		t = _t;
	}
};
bool operator<(const node& l, const node& r) {
	return l.t > r.t;
}

int main() {
	int n, m;
	while(cin >> n >> m, n) {
		rep(i,31) rep(j,31) dist[i][j] = cap[i][j] = INF;
		memset(visit, 0, sizeof(visit));
		int s, g;
		cin >> s >> g;
		rep(i, m) {
			int x, y, d, c;
			cin >> x >> y >> d >> c;
			dist[x][y] = dist[y][x] = d;
			cap[x][y] = cap[y][x] = c;
		}
		priority_queue<node> que;
		for(int i=1; i<=n; i++) {
			if( dist[s][i] < INF && 1 <= cap[s][i] ) {
				que.push( node(1, i, s, 1.*dist[s][i]) );
			}
		}
		bool found = false;
		while(!que.empty()) {
			node nd = que.top();
			que.pop();
			if( nd.p==g && nd.s==1 ) {
				cout << setprecision(10) << nd.t << endl;
				found = true;
				break;
			}
			if( visit[nd.p][nd.s][nd.c] ) continue;
			visit[nd.p][nd.s][nd.c] = true;
			for(int nxt=1; nxt<=n; nxt++) {
				if( nd.c == nxt ) continue;
				for(int sp=max(1,nd.s-1); sp<=min(30,nd.s+1); sp++) {
					if( !visit[nxt][sp][nd.p] && dist[nd.p][nxt] < INF && sp <= cap[nd.p][nxt] ) {
					double nt = nd.t + 1.*dist[nd.p][nxt]/sp;
						que.push(node(sp, nxt, nd.p, nt));
					}
				}
			}
		}
		if(!found) {
			cout << "unreachable" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 15108
from sys import stdin
from functools import lru_cache

@lru_cache(maxsize=None)
def lcs_record(x:chr, Y:str):
    return [0] + [1 if x == v else 0 for v in list(Y)]

def len_of_LCS(X:str ,Y:str):
    len_Y = len(Y)
    p_record = [0]*(len_Y+1)
    for x in list(X):
        c_record = lcs_record(x, Y).copy()
        for i in range(1, len_Y+1):
            if c_record[i] == 1:
                c_record[i] = p_record[i-1] + 1
            else:
                c_record[i] = p_record[i] if p_record[i] > c_record[i-1] else c_record[i-1]
        p_record = c_record
    return c_record[len_Y]

n = int(stdin.readline())
lines = list()
for i in range(n*2):
    lines.append(input().rstrip('\n'))
for i in range(n):
    X = lines[i*2]
    Y = lines[i*2+1]
    print(len_of_LCS(X, Y))


Measured memory_bytes: 10220
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), x, y;
		int r[][] = new int[2 * n][2];
		int b[][] = new int[2 * n][2];
		for (int i = 0; i < n; ++i) {
			x = sc.nextInt();
			y = sc.nextInt();
			r[x][0] = y + 1;
			r[y][1] = x + 1;
		}
		for (int i = 0; i < n; ++i) {
			x = sc.nextInt();
			y = sc.nextInt();
			b[x][0] = y + 1;
			b[y][1] = x + 1;
		}

		sc.close();
		int ans = 0, t = 0;
		for (int k = 0; k < 2; ++k) {
			t = 0;
			for (int i = 1; i < 2 * n; ++i) {
				if (b[i][k] != 0) {
					int max = 0, maxnum = -1;
					for (int j = 0; j < i; ++j) {
						if (r[j][k] != 0) {
							int tmp = b[i][k] - r[j][k];
							if(tmp > 0) {
								if(r[j][k] > max) {
									max = r[j][k];
									maxnum = j;
								}
							}
						}
					}
					if(maxnum >= 0) {
						r[maxnum][k] = 0;
						++t;
					}
				}
			}
			ans = Math.max(ans,  t);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <stdio.h>
//#include <windows.h>

int masu[100][100],mx,ice[100][100],n,m;

/**
void print()
{
	system("cls");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",masu[i][j]);
		}
		puts("");
	}
}
/**/

void func(int x,int y,int now)
{
//	printf("%d",now);
//	print();
	
	if(masu[x+1][y]==1){
		masu[x][y]=0;
		func(x+1,y,now+1);
		masu[x][y]=1;
	}
	if(masu[x-1][y]==1){
		masu[x][y]=0;
		func(x-1,y,now+1);
		masu[x][y]=1;
	}
	if(masu[x][y+1]==1){
		masu[x][y]=0;
		func(x,y+1,now+1);
		masu[x][y]=1;
	}
	if(masu[x][y-1]==1){
		masu[x][y]=0;
		func(x,y-1,now+1);
		masu[x][y]=1;
	}
	else {
		if(mx<now){
			mx=now;
		}
	}
}

void func2()
{
	int i,j;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			masu[i][j]=ice[i][j];
		}
	}
}

int main(void)
{
	int i,j;
	
	while(scanf("%d%d",&m,&n),n,m){
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				scanf("%d",&ice[i][j]);
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				func2();
				if(masu[i][j]==1){
					func(i,j,1);
				}
			}
		}
		for(i=0;i<100;i++){
			for(j=0;j<100;j++){
				ice[i][j]=0;
				masu[i][j]=0;
			}
		}
		printf("%d\n",mx);
		n=0;
		m=0;
		mx=0;
	}
	
	return 0;
}

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

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

typedef pair<ll,ll> pli;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)

ll s[100002], t[100002], ans[100000];
vector<pli> x;
int a,b,q;


int main(){
  cin >> a>> b>> q;
  FOR(i,1,a+1) cin >> s[i];
  FOR(i,1,b+1) cin >> t[i];
  s[0] = t[0]= -10e15;
  s[a+1] = t[b+1] = 10e15;
  REP(i,q){
    ll l;
    cin >> l;
    x.push_back(pli(l,i));
  }
  sort(x.begin(),x.end());
  int si,ti;
  si = ti = 0;
  REP(i,q){
    ll xi = x[i].first;
    while(s[si]<=xi){
      si++;
      if(si==a+1) break;
    }
    while(t[ti]<=xi){
      ti++;
      if(ti==b+1) break;
    }
    ll a = min(xi-min(s[si-1],t[ti-1]), max(s[si],t[ti])-xi);
    a = min(a, 2*s[si]-xi-t[ti-1]);
    a = min(a, 2*t[ti]-xi-s[si-1]);
    a = min(a, xi+t[ti]-2*s[si-1]);
    a = min(a, xi+s[si]-2*t[ti-1]);
    ans[x[i].second] = a;
  }
  REP(i,q) cout << ans[i] <<endl;
}


Measured memory_bytes: 5360
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  vector<int> K(Q), F(Q);
  vector<string> C(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> K[i];
    if (K[i] == 2) cin >> F[i] >> C[i];
  }
  
  deque<string> q;
  q.push_back(S);
  int f = 1;
  for (int i = 0; i < Q; ++i) {
    if (K[i] == 1) {
      if (f == 1) f = 2;
      else f = 1;
    } else {
      if (f == F[i]) q.push_front(C[i]);
      else q.push_back(C[i]);
    }
  }
  
  if (f == 1) {
    for (int i = 0; i < q.size(); ++i) cout << q[i];
  } else {
    for (int i = q.size() - 1; i >= 0; --i) {
      if (q[i].size() != 1) reverse(q[i].begin(), q[i].end());
      cout << q[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 14848
using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    int[] Ans;
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = new int[n];
        for (int i = 1; i < n; i++)
        {
            a[i] = sc.NextInt() - 1;
        }

        Ans = new int[n];
        for (int i = 1; i < n; i++)
        {
            Ans[a[i]]++;
        }

        Console.WriteLine(string.Join("\n", Ans));
    }


    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 44212
#include <bits/stdc++.h>
#define int long long
 
using namespace std;
 
int n;
 
main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    long double x = (long double) n / 3;
    cout << fixed << setprecision(9) << (long double) x * x * x;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			int w = in.nextInt();
			int d = in.nextInt();
			if((w|d)==0){
				break;
			}
			int[] h1 = new int[w];
			int sum=0;
			for(int i = 0; i < w; i++){
				h1[i] = in.nextInt();
				sum+=h1[i];
			}
			for(int j = 0;j < d; j++){
				int buf = in.nextInt();
				for(int i = 0; i < w; i++){
					if(h1[i] == buf){
						buf = h1[i] = 0;
					}
				}				
				sum+=buf;
			}
			System.out.println(sum);
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
require "set"
N,M=gets.split.map{|i| i.to_i}

A=(1..N).map{|i| Set.new }

for i in 1..M
    s,c=gets.split.map{|i| i.to_i}
    A[s-1].add(c)
end

str=""

v=A[0].to_a
if v.length>=2 
    puts "-1"
    exit
end
if v.length ==1 and v[0]!=0
   str << v[0].to_s
elsif v.length==0
    if N==1
        puts 0
        exit

    end
    str<<1.to_s
else
    if N==1
        puts 0
        exit
    end
    puts -1
    exit
end



for i in A.slice(1..N)
    v=i.to_a
    if v.length>=2
        puts -1
        exit
    end
    if v.length==0
        str << "0"
    else
        str << (v[0].to_s)
    end
end
puts str



Measured memory_bytes: 2044
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    if (X[i + 1] - X[i]) * A > B:
        ans += B
    else:
        ans += (X[i + 1] - X[i]) * A

print(ans)

Measured memory_bytes: 14224
#include <stdio.h>

int main(void){

    static int n,d,x ;
    scanf ("%d%d%d",&n,&d,&x) ;
    
    for (int i=0; i<n; i++){
        
        int a[i] ;
        scanf ("%d",&a[i]) ;
        
        x += ((d-1)/a[i])+1 ;
        
    }

    printf ("%d\n",x) ;
    
    return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    char s; cin >> s;
    string res = "vowel";
    if(s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o') res = "vowel";
    else res = "consonant";
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
#define MASK 0x0003FFFF
//#define Hsize ((1<<18)-1)
#define Hsize 100009
#define MAXN 210001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    int next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    if (x<0) x=-x;
    return (x%100007);
    return (x&MASK);
}

//add the current sumZ to the hash table
void addToHash(ll sumZ)
{
    int index, HsumZ, beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=hashIndex[HsumZ]; index>0; index=hashBucket[index].next)
        if (hashBucket[index].number == sumZ) // there is already that number in the hashbucket
        {
            hashBucket[index].times+=1;
            return;
        } 
    top++;
    hashIndex[HsumZ]=top;
    hashBucket[top].number = sumZ;
    hashBucket[top].times = 1;
    hashBucket[top].next = beginP;
}

void init()
{
    memset(hashBucket,-1,sizeof(hashBucket));
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 5504
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a, b;
	cin >> a >> b;
	if (a + b > 9)cout << "error" << endl;
	else cout << a + b << endl;
}



Measured memory_bytes: 384
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long X  = keyboard.nextLong();
		long Y  = keyboard.nextLong();
		
		long ANS = 0;
		
		while(X<=Y) {
			X *=2;
			ANS++;
		}
		
		System.out.println(ANS);
		keyboard.close();	
	}
}

Measured memory_bytes: 35548
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

vector<int> a;
vector<vector<long long> > memo;

long long solve(int i, int j)
{
    if(j < i)
        return 0;
    if(memo[i][j] != -1)
        return memo[i][j];

    long long x = a[i] - solve(i+1, j);
    long long y = a[j] - solve(i, j-1);
    return memo[i][j] = max(x, y);
}

int main()
{
    int n;
    cin >> n;
    a.resize(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    memo.assign(n, vector<long long>(n, -1));
    cout << solve(0, n-1) << endl;

    return 0;
}


Measured memory_bytes: 70912
#include <iostream>

using namespace std;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;

    if (a.back() == b.front() && b.back() == c.front()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# 入力 : a b c
a, b, c = map(int, input().split())

# キャンディーを同じ個数に分けられるなら Yes を、そうでなければ No を出力せよ。
list = [a, b, c]
list.sort()
if list[0] + list[1] == list[2] :
    print("Yes")
else :
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

// Solution

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

    if(k < s.size()) {
        for(int i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "...";
    } else {
        cout << s;
    }
    return 0;
}


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

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

int main() {
	int x,y;
	cin >> x >> y;
	if(x < y)
		swap(x,y);
	cout << gcd(x,y) << endl;
	
	return 0;
}

Measured memory_bytes: 3108
//e4-e5-f4
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define sl set<ll>
#define usl unordered_set<ll>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vpl vector<pll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define P 1000000007
#define Q 1000000006
#define inf 1e18
#define N 50
#define M 105
//using namespace boost::multiprecision; 
//using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);

void solve(){
    
    string s;
    cin>>s;
    ll d;
    cin>>d;
    ll n = lt(s);
    vl dp1(d,0), dp0(d,0);
    dp0[0]=1;
    f(i,0,n){
        vl dp3(d,0), dp2(d,0);
        f(j,0,d){
            ll curr = s[i]-'0';
            f(dig,0,10){ // for already small
                (dp3[(j+dig)%d] += dp1[j]) %= P;
                //cout<<i<<" "<<j<<" "<<dp3[(j+dig)%d]<<endl;
            }
            f(dig,0,curr+1){ //not yet small
                if(dig < curr) (dp3[(j+dig)%d] += dp0[j]) %= P; //this is small
                else (dp2[(j+dig)%d] += dp0[j]) %= P;
            }
        }
        dp1 = dp3;
        dp0 = dp2;
    }
    //cout<<n<<endl;
    cout<<(dp1[0] + dp0[0] - 1 + P)%P;
}

signed main() {
    teevra_gati
    
    solve();

    return 0;
}

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

int h,w;
char nimotu[52][52];
int nimotu_data[27][52][52];
struct {
	int xmin,xmax;
	int ymin,ymax;
} nimotu_range[26];

int solve(void) {
	int i;
	int x,y;
	int kousinn_atta;
	if(scanf("%d%d",&h,&w)!=2)return 0;
	for(i=1;i<=h;i++) {
		if(scanf("%s",nimotu[i]+1)!=1)return 0;
	}
	memset(nimotu_data,0,sizeof(nimotu_data));
	for(i=0;i<26;i++) {
		nimotu_range[i].xmin=w+2;
		nimotu_range[i].xmax=-1;
		nimotu_range[i].ymin=h+2;
		nimotu_range[i].ymax=-1;
	}
	for(y=1;y<=h;y++) {
		for(x=1;x<=w;x++) {
			if(nimotu[y][x]!='.') {
				/* ASCII code wo katei */
				int m=nimotu[y][x]-'A';
				nimotu_data[m][y][x]++;
				if(nimotu_range[m].xmin>x)nimotu_range[m].xmin=x;
				if(nimotu_range[m].xmax<x)nimotu_range[m].xmax=x;
				if(nimotu_range[m].ymin>y)nimotu_range[m].ymin=y;
				if(nimotu_range[m].ymax<y)nimotu_range[m].ymax=y;
			}
		}
	}
	for(i=0;i<26;i++) {
		for(y=1;y<=h;y++) {
			for(x=1;x<=w;x++)nimotu_data[i][y][x]+=nimotu_data[i][y][x-1];
		}
		for(x=1;x<=w;x++) {
			for(y=1;y<=h;y++)nimotu_data[i][y][x]+=nimotu_data[i][y-1][x];
		}
	}
	do {
		kousinn_atta=0;
		for(i=0;i<26;i++) {
			if(nimotu_range[i].xmin<=nimotu_range[i].xmax) {
				int xs=nimotu_range[i].xmin-1;
				int xt=nimotu_range[i].xmax;
				int ys=nimotu_range[i].ymin-1;
				int yt=nimotu_range[i].ymax;
				int n=nimotu_data[i][yt][xt]-nimotu_data[i][yt][xs]
					-nimotu_data[i][ys][xt]+nimotu_data[i][ys][xs];
				int v=nimotu_data[26][yt][xt]-nimotu_data[26][yt][xs]
					-nimotu_data[26][ys][xt]+nimotu_data[26][ys][xs];
				if(n+v==(xt-xs)*(yt-ys)) {
					kousinn_atta=1;
					/* kono nimotu wo hazusu */
					nimotu_range[i].xmin=w+2;
					nimotu_range[i].xmax=-1;
					/* ruisekiwa wo kaizyo */
					for(x=1;x<=w;x++) {
						for(y=h;y>=1;y--) {
							nimotu_data[i][y][x]-=nimotu_data[i][y-1][x];
							nimotu_data[26][y][x]-=nimotu_data[26][y-1][x];
						}
					}
					for(y=1;y<=h;y++) {
						for(x=w;x>=1;x--) {
							nimotu_data[i][y][x]-=nimotu_data[i][y][x-1];
							nimotu_data[26][y][x]-=nimotu_data[26][y][x-1];
						}
					}
					/* nurinaosu */
					for(y=1;y<=h;y++) {
						for(x=1;x<=w;x++) {
							nimotu_data[i][y][x]+=nimotu_data[i][y][x-1];
							nimotu_data[26][y][x]+=nimotu_data[26][y][x-1];
							if(nimotu[y][x]-'A'==i) {
								nimotu_data[i][y][x]--;
								nimotu_data[26][y][x]++;
							}
						}
					}
					for(x=1;x<=w;x++) {
						for(y=1;y<=h;y++) {
							nimotu_data[i][y][x]+=nimotu_data[i][y-1][x];
							nimotu_data[26][y][x]+=nimotu_data[26][y-1][x];
						}
					}
				}
			}
		}
	} while(kousinn_atta);
	for(i=0;i<26;i++) {
		if(nimotu_range[i].xmin<=nimotu_range[i].xmax) {
			/* nimotu ga nokotteru */
			puts("SUSPICIOUS");
			return 1;
		}
	}
	puts("SAFE");
	return 1;
}

int main(void) {
	int n,i;
	if(scanf("%d",&n)!=1)return 1;
	for(i=0;i<n;i++) {
		if(!solve())return 1;
	}
	return 0;
}

Measured memory_bytes: 876
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
template <class T>
using lim = numeric_limits<T>;
 
bool can[10];
int cost[10] = {0,2,5,5,4,5,6,3,7,6};

string mymax(string a, string b){
	if (a.length() == b.length()) {
		if (a < b) return b;
		else return a;
	}
	else if (a.length() < b.length()) return b;
	else return a;
}
	
int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	memset(can, 0, sizeof can);
	
	int n, m;
	cin >> n >> m;
	
	string dp[n+1];
	for (int i = 0; i <= n; i++) dp[i]="0";
	dp[0] = "";
	for (int i = 0; i < m; i++){
		int a; cin >> a;
		can[a] = true;
	}
	
	// adding all available matches and getting the max
	// dp[i] is maximum val at i
	for (int i = 0; i < n; i++){
		for (int j = 1; j < 10; j++){
			if (!can[j] || dp[i]=="0" || i + cost[j] > n) continue;
			dp[i+cost[j]] = mymax(dp[i+cost[j]], dp[i]+(char)(j+'0'));
		}
	}
	
	cout << dp[n] << endl;
}


Measured memory_bytes: 44800
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

queue=deque([])
seen=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            queue.append([i,j,0])
            seen[i][j]=1

dx=[1,0,-1,0];dy=[0,1,0,-1]
while queue:
    x,y,t=queue.pop()
    for i,j in zip(dx,dy):
        if 0<=x+i<h and 0<=y+j<w and seen[x+i][y+j]==0:
            queue.appendleft([x+i,y+j,t+1])
            seen[x+i][y+j]=1
print(t)


Measured memory_bytes: 221772
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n;
  cin>>n;
  vil v(n);
  //map<ll,ll> m;
  ll ans=0;
  ll mod=1e9+7;
   for(int i=0;i<n;i++) cin>>v[i];
   ll dp[n+1];
   dp[0]=v[0];
   for(int i=1;i<n;i++) dp[i]=dp[i-1]+v[i];
   for(int i=0;i<n;i++){
         ll p=v[i];
         ll r=(dp[n-1]-dp[i])%mod;
         p=(p*r)%mod;
         p%=mod;
         ans+=p;
         ans%=mod;
   }
   cout<<ans;
}



  

Measured memory_bytes: 6372
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)

def search(values,hp,vp,item):
	if not (0<=hp<len(values)): return
	if not (0<=vp<len(values[hp])): return
	if item!=values[hp][vp]: return
	values[hp][vp]=True
	search(values,hp-1,vp,item)
	search(values,hp+1,vp,item)
	search(values,hp,vp-1,item)
	search(values,hp,vp+1,item)

def solve(values):
	count,valid_items=0,set(['@','#','*'])
	for i in range(len(values)):
		for j in range(len(values[i])):
			if values[i][j] in valid_items:
				search(values,i,j,values[i][j])
				count+=1
	return count

def main():
	line,values=input().strip(),list()
	while line!='0 0':
		H,W = list(map(int,line.split(' ')))
		value = list()
		for _ in range(H):
			value.append(list(x for x in input().strip()))
		values.append(value)
		line = input().strip()
	for value in values:
		print(solve(value))

if __name__=='__main__':
	main()

Measured memory_bytes: 15928
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
    z->parent=y;
    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;


  
 


}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);


}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for (i=0;i<n;i++){
    scanf("%s",com);
    if (com[0]=='f'){
      scanf("%d",&x);
    } else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



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

int main() {
  int n;
  cin>>n;
  int ball[n];
  for(int i=0; i<n; i++) cin>>ball[i];

  const int MAX = 200001;
  int64_t count[MAX];
  for(int i=0; i<MAX; i++) count[i]=0;
  for(int i=0; i<n; i++) count[ball[i]]++;

  int64_t sum = 0;
  for(int i=0; i<MAX; i++) sum+=count[i]*(count[i]-1)/2;

  for(int i=0; i<n; i++) {
    if(count[ball[i]]<2) cout<<sum<<endl;
    else cout<<sum-(count[ball[i]]-1)<<endl;
  }

  return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;



int main(){
    ll H,W;
    cin>>H>>W;
    if(H==1||W==1){
        cout<<1<<endl;
        return 0;
    }
    if(H%2==0){
        cout<<H/2*W<<endl;
    }else if(W%2==0){
        cout<<W/2*H<<endl;
    }else{
        ll a = (H+1)/2;
        ll b = (W+1)/2;
        ll res = a*b+(a-1)*(b-1);
        cout<<res<<endl;
    }

}

Measured memory_bytes: 256
import java.io.*;
public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = 
		new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int b,f,r,v;
		int[][] base = new int[12][10];
		String[] lines;
		for(int i=0;i<N;i++)
		{
			lines = br.readLine().split(" ");
			b = Integer.parseInt(lines[0]);
			f = Integer.parseInt(lines[1]);
			r = Integer.parseInt(lines[2]);
			v = Integer.parseInt(lines[3]);
			if(base[((b-1)*3)+(f-1)][r-1]>=0)
			{
				base[((b-1)*3)+(f-1)][r-1] += v;
			}
			else
			{
				base[((b-1)*3)+(f-1)][r-1] = v;
			}
		}
		for(int i=0;i<12;i++)
		{
			for(int j=0;j<10;j++)
			{
				System.out.print(" "+base[i][j]);
			}

			if((i+1)!=12&&(i+1)%3==0)
			{
				System.out.println();
				System.out.print("####################");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 19348
#include<cstdio>
#define P pair<int,int>
#define int long long
const int N=1e5+5,p=1e9+7;
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
    x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
int a[N];
signed main()
{
    int n=read(),l=2,r=2;
    for(int i=n;i;--i)a[i]=read();
    for(int i=1;i<=n&&l<=r;++i)
    {
        // printf("!%lld %lld\n",l,r);
        // if(r<a[i]||l/a[i]==r/a[i])return puts("-1"),0;
        l=((l-1)/a[i]+1)*a[i];
        r=r/a[i]*a[i]+a[i]-1;
    }
    l>r?puts("-1"):printf("%lld %lld\n",l,r);
    return 0;
}

Measured memory_bytes: 896
//##MohK
//1/04/2020 .... 3,12.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256