akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	vector<int> ans;
	for (int i = 0; i < n + 1; ++i) {
		for (int j = min(n, i + m); j >= i + 1; --j) {
			if (s[j] == '0') {
				ans.push_back(j - i);
				i = j - 1;
				break;
			}
		}
	}
	int sum = 0;
	for (int c : ans) sum += c;
	if (sum != n) {
		cout << -1 << endl;
	}
	else {
		reverse(ans.begin(), ans.end());
		rep(i, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 3944
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll n, q;
vll cnt;
vvll g;

void dfs(ll u, ll p = -1) {
    for (ll &v : g[u]) {
        if (v == p) {
            continue;
        }
        cnt[v] += cnt[u];
        dfs(v, u);
    }
}

int main() {
    fast_io; cout_precision;
    cin >> n >> q;
    g.resize(n + 1);
    for (ll i = 0, a, b; i < n - 1; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cnt.assign(n + 1, 0);
    for (ll i = 0, p, x; i < q; i++) {
        cin >> p >> x;
        cnt[p] += x;
    }
    dfs(1);
    for (ll i = 1; i <= n; i++) {
        cout << cnt[i] << ' ';
    }
    cout << endl;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> H(N);
  for(int i=0;i<N;i++) cin >> H[i];
  
  vector<bool> V(N,true);
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    if(H[a]>=H[b]) V[b] = false;
    if(H[a]<=H[b]) V[a] = false;
  }
  
  int ans=0;
  for(int i=0;i<N;i++){
    if(V[i]==true) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0; i < 4; ++i){
    if(S[i] == '+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 200
char s[maxn];
int main(){
	scanf("%s",s);
	for(int i=0;s[i];i++){
		if(s[i]=='L'&&i%2==0){puts("No");return 0;}
		else if(s[i]=='R'&&i%2==1){puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;

int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for(int i = 1; i < n; i++) if(a[i] == a[i - 1]) return cout << "NO\n", 0;
    cout << "YES";

    return 0;
}




Measured memory_bytes: 4368
#include <iostream>
using namespace std;
int main() {
    int k;
    cin >> k;
    if (k % 7 == 0) {
        k /= 7;
    }
    k *= 9;
    int x = 10;
    int y = 10;
    int c = 1;
    if (k % 2 == 0 || k % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }
    while (true) {
        int a = x / k;
        x = (x % k) * 10;
        y = (y % k) * 10;
        int b = y / k;
        y = (y % k) * 10;
        if (x == y) {
            break;
        }
        c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

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

    int N; cin >> N;
    vel A(N);
    rep(i,N) cin >> A[i];

    
    bool next = true;
    while(next){
        sort(all(A));
        next = false;
        rep1(i,N) {
            if(A[i] == INF) continue;
            ll temp  = A[i];
            if(A[i] % A[0] == 0) A[i] = INF;
            else A[i] %= A[0];
            if(A[i] != temp) next = true;
        }
    }
    cout << A[0] << endl;
    return 0;
}

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

using namespace std;

const int maxn = 1e3+100, mod = 1e9+7;

int h, w, mat[maxn][maxn], dp[maxn][maxn];

int solve(int i, int j){

    if(dp[i][j]!=-1)return dp[i][j];

    if(i==h and j==w)return 1;

    dp[i][j]=0;

    if(mat[i+1][j]==1){
        dp[i][j]=((solve(i+1, j))%mod + dp[i][j])%mod;
    }
    if(mat[i][j+1]==1){
        dp[i][j]=((solve(i, j+1))%mod + dp[i][j])%mod;
    }
    return dp[i][j];
}

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

    cin >> h >> w;

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
        char a;
        cin >> a;
        if(a=='.')mat[i][j]=1;
        }
    }

    memset(dp, -1, sizeof dp);

    cout << solve(1,1);

    return 0;
}


Measured memory_bytes: 9344
// -_-
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define mod 1000000007
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<long long , long long> pll;
 
int main() 
{

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n;
	cin >> n;
	ll a[n+2], b[n+1], sum = 0, s = 0;
	fori(i, 1, n+1)
	{cin >> a[i]; sum += a[i];}
	fori(i, 1, n) cin >> b[i];

	fori(i, 1, n)
	{
		if(a[i] < b[i])
			s += a[i];
		else {s += b[i]; continue;}
		b[i] -= a[i];
		if(a[i+1] < b[i])
			{
				s += a[i+1];
				a[i+1] = 0;
			}
			else
			{
				s += b[i];
				a[i+1] -= b[i];
			}
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 55;
const ll LINF = 1e18 + 5;
int n, m; 
vector <int> G[N];
ll edge[N];
int fa[N][25], dep[N], idx[N][N]; 
void dfs(int u)
{	
	for(int i=1;i<=20;i++) 
		fa[u][i] = fa[fa[u][i-1]][i-1];
	for(auto v : G[u])
	{
		if(v!=fa[u][0])
		{
			dep[v] = dep[u] + 1;
			fa[v][0] = u; 
			dfs(v);
 		}
	}
}
int LCA(int x,int y) 
{
	if(dep[x]>dep[y]) swap(x,y);
	for(int i=20;i>=0;i--)
		if(dep[fa[y][i]]>=dep[x]) y = fa[y][i]; 
	if(x==y) return x;
	for(int i=20;i>=0;i--)
		if(fa[x][i]!=fa[y][i]) x = fa[x][i], y = fa[y][i]; 
	return fa[x][0];
}
ll calcu(int x, int y)
{
	ll mask = 0;
	int lca = LCA(x, y);
	while(x!=lca)
	{
		mask |= 1ll<<idx[x][fa[x][0]];
		x = fa[x][0];
	}
	while(y!=lca)
	{
		mask |= 1ll<<idx[y][fa[y][0]];
		y = fa[y][0];
	}
	return mask;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<n; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(v); G[v].pb(u);
 		idx[u][v] = idx[v][u] = i;
 	}
 	dep[1] = 1;
 	dfs(1);
 	cin >> m;
 	for(int i=0; i<m; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		edge[i] = calcu(u, v);
 	}
 	ll ans = (1ll<<(n-1));
 	for(int i=1; i<(1<<m); i++)
 	{
 		int parity = 0;
 		ll mask = 0;
 		for(int j=0; j<m; j++)
 		{
 			if((i>>j)&1)
 			{
 				parity++;
 				mask |= edge[j];
 			}
 		}
 		//debug(n-__builtin_popcount(mask)-1);
 		if(parity&1) ans -= (1ll<<(n-__builtin_popcountll(mask)-1));
 		else ans += (1ll<<(n-__builtin_popcountll(mask)-1));
 	}
 	cout << ans;
	return 0;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(){
    int n;
    cin >> n;
    map <string, int> mp;

    FOR(i, n){
    	string s;
    	cin >> s;

    	sort(ALL(s));
    	mp[s]++;
    }

    ll ans = 0;
    for(auto p:mp){
    	ans += (ll) p.second*(p.second - 1)/2;
    }

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


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define N 505 
using namespace std;
inline int read(){
    int ans=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
int h,w,a[N][N],pos[N];
bool vis[N][N],is[N][N];
struct Node{int a,b,c,d;};
vector<Node>q;
int main(){
    h=read(),w=read();
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j)a[i][j]=read();
        for(int j=1;j<w;++j)if(a[i][j]&1)a[i][j+1]++,q.push_back((Node){i,j,i,j+1});
    }
    for(int i=1;i<h;++i)if(a[i][w]&1)a[i+1][w]++,q.push_back((Node){i,w,i+1,w});
    cout<<q.size()<<'\n';
    for(int i=0;i<q.size();++i)cout<<q[i].a<<' '<<q[i].b<<' '<<q[i].c<<' '<<q[i].d<<'\n';
    return 0;
}

Measured memory_bytes: 5232
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long MOD = 998244353;
		int N = sc.nextInt();
		int S = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		long[][][] dp = new long[3][N+1][S+1];
		dp[0][0][0] = 1;
		for(int i=0; i<N; i++) {
			dp[0][i+1][0] = (dp[0][i+1][0] + dp[0][i][0])%MOD;
			dp[1][i+1][0] = (dp[1][i+1][0] + dp[0][i][0])%MOD;
			if(A[i]<=S) {
				dp[1][i+1][A[i]] = (dp[1][i+1][A[i]] + dp[0][i][0])%MOD;
				dp[2][i+1][A[i]] = (dp[2][i+1][A[i]] + dp[0][i][0])%MOD;
			}
			for(int j=0; j<=S; j++) {
				dp[1][i+1][j] = (dp[1][i+1][j] + dp[1][i][j])%MOD;
				dp[2][i+1][j] = (dp[2][i+1][j] + dp[2][i][j])%MOD;
				dp[2][i+1][j] = (dp[2][i+1][j] + dp[1][i][j])%MOD;
			}
			for(int j=0; j+A[i]<=S; j++) {
				dp[1][i+1][j+A[i]] = (dp[1][i+1][j+A[i]] + dp[1][i][j])%MOD;
				dp[2][i+1][j+A[i]] = (dp[2][i+1][j+A[i]] + dp[1][i][j])%MOD;
			}
		}
		
		System.out.println(dp[2][N][S]);
		
		sc.close();
	}
	
}


Measured memory_bytes: 328644
n = int(input())
mx=50

n2_lis=[1]
for i in range(1,mx):
    n2_lis.append(n2_lis[i-1]*(-2))

sum_p=[0]
sum_m=[0]
sp=0
sm=0
for num in n2_lis:
    if num > 0:
        sp+=num
    else:
        sm+=num
    sum_p.append(sp)
    sum_m.append(sm)

rg=[]
for i in range(mx):
    rg1=n2_lis[i] + sum_p[i]
    rg2=n2_lis[i] + sum_m[i]
    rg.append([min(rg1,rg2),max(rg1,rg2)])

ans=[]
for i in reversed(range(0,mx)):
    if rg[i][0] <= n and n <= rg[i][1]:
        ans.append(1)
        n-=n2_lis[i]
    else:
        ans.append(0)
ans = ''.join([str(n) for n in ans])
print(int(ans))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> Vec;
void rotatex(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[2];a[2]=a[3];a[3]=tmp;
  tmp=a[4];a[4]=a[5];a[5]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatey(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[5];a[5]=a[4];a[4]=tmp;
  tmp=a[3];a[3]=a[2];a[2]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatez(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[4];a[4]=a[7];a[7]=a[3];a[3]=tmp;
  tmp=a[1];a[1]=a[5];a[5]=a[6];a[6]=a[2];a[2]=tmp;
}

int main(){
  string s[8];
  while(cin>>s[0]){
    int i,j,k,ans=0;
    for(i=1;i<8;i++) cin>>s[i];
    sort(s,s+8);
    set<string> ss;
    set<Vec> sv;
    Vec v;
    for(i=0;i<8;i++) ss.insert(s[i]),v.push_back(ss.size()-1);
    do{
      if(sv.find(v)!=sv.end()) continue;
      ans++;
      for(i=0;i<4;i++){
	rotatez(v);
	for(j=0;j<4;j++){
	  rotatey(v);
	  for(k=0;k<4;k++){
	    rotatex(v);
	    sv.insert(v);
	  }
	}
      }
    }while(next_permutation(v.begin(),v.end()));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 7556
import java.util.Scanner;
public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int count = scan.nextInt();
    double sum = 0;
    for (int i=0; i<count&&scan.hasNextInt(); i++) {
      sum += (1/(double)scan.nextInt());
    }
    System.out.println(1/sum);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int n,k,q,a,del,sc[100010];
int main () {
	scanf("%d%d%d",&n,&k,&q);
	del=q-k;
	for (int i=1;i<=q;i++) {
		scanf("%d",&a);
		sc[a]++;
	}
	for (int i=1;i<=n;i++) {
		if (sc[i]<=del) {printf("No\n");}
		else {printf("Yes\n");}
	}
	return 0;
}

Measured memory_bytes: 1024
H,W = map(int, input().split())
S = [input() for _ in range(H)]
        
from collections import deque

ans = 0
inf = 10**12
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        q = deque()
        q.append((i, j, 0))
        used = [[inf]*W for _ in range(H)]
        used[i][j] = 0
        while q:
            temp = q.popleft()
            k = temp[0]
            l = temp[1]
            d = temp[2]
            if k > 0 and S[k-1][l] == "." and used[k-1][l] > d+1:
                used[k-1][l] = d+1
                q.append((k-1, l, d+1))
            if k < H-1 and S[k+1][l] == "." and used[k+1][l] > d+1:
                used[k+1][l] = d+1
                q.append((k+1, l, d+1))
            if l > 0 and S[k][l-1] == "." and used[k][l-1] > d+1:
                used[k][l-1] = d+1
                q.append((k, l-1, d+1))
            if l < W-1 and S[k][l+1] == "." and used[k][l+1] > d+1:
                used[k][l+1] = d+1
                q.append((k, l+1, d+1))

        for s in range(H):
            for t in range(W):
                if used[s][t] < inf:
                    ans = max(ans, used[s][t])

print(ans)            


Measured memory_bytes: 64492
#include<iostream>
#include<string>
using namespace std;
int W[10];int K[10];	 
    int fir=0;
    int sec=0;
    int thi=0;
    int fir2=0;
    int sec2=0;
    int thi2=0;
int main(){
	for(int i=0;i<10;i++){
	cin>>W[i];}
	for(int i=0;i<10;i++){
	cin>>K[i];}

    for(int i=0;i<10;i++){
    if(W[i]>fir){
    thi=sec;
    sec=fir;
    fir=W[i];}else
    if(W[i]>sec){
    thi=sec;
    sec=W[i];}else
    if(W[i]>thi){
    thi=W[i];}}
    for(int i=0;i<10;i++){
    if(K[i]>fir2){
    thi2=sec2;
    sec2=fir2;
    fir2=K[i];}else
    if(K[i]>sec2){
    thi2=sec2;
    sec2=K[i];}else
    if(K[i]>thi2){
    thi2=K[i];}}
	cout<<fir+sec+thi<<" "<<fir2+sec2+thi2<<endl;

		return 0;
	}


Measured memory_bytes: 1164
<?php
fscanf(STDIN, "%d %d", $N, $M);

$lmax =1;
$rmin =$N;
for($i=0;$i<=$M;$i++){
  fscanf(STDIN, "%d %d", $l, $r);
  if($l>$lmax){
    $lmax = $l;
  }
  if($r<$rmin){
    $rmin = $r;
  }
}
if($rmin-$lmax+1>0){
echo ($rmin-$lmax+1)."\n";
}else{
  echo "0"."\n";
}
?>

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

int main()
{
    // 入力
    string s;
    cin >> s;

    int counter = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == '1')
            ++counter;
    }

    // 出力
    cout << counter << endl;
}


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

using namespace std;

namespace {

#define VERA(i, a, b)for(auto i=(ll)(a);i<(ll)(b);++i)
#define ANDY(i, a, b)for(auto i=(ll)(a);i>(ll)(b);--i)

typedef long long ll;
typedef double dd;

struct UF {
  vector<ll> e;

  UF(int n) : e(n, -1) {}

  bool same_set(int a, int b) { return find(a) == find(b); }

  int size(int x) { return -e[find(x)]; }

  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }

  void join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b];
    e[b] = a;
  }
};


template <class T> inline ll Size(const T& x) { return x.size(); }

bool Solve(ll test_num) {
  (void) test_num;
  ll n, m;
  if (not(cin >> n >> m)) return false;
  UF dsu(n);
  vector<ll> wei(n);
  for (auto& w : wei) cin >> w;
  VERA(e, 0, m) {
    ll a, b;
    cin >> a >> b;
    dsu.join(a, b);
  }
  if (m == n - 1) {
    cout << "0\n";
    return true;
  }
  vector<vector<ll>> comps(n);
  vector<ll> all;
  ll res = 0, have = 0, non_zero = 0;
  VERA(v, 0, n) comps[dsu.find(v)].push_back(v);
  bool non_leaf = false;
  for (auto& comp : comps) {
    if (comp.empty()) continue;
    static vector<ll> now;
    now.clear();
    for (auto v : comp)
      now.push_back(wei[v]);
    sort(now.begin(), now.end());
    have += Size(now);
    if (Size(now) > 1)
      non_leaf = true;
    res += now.front();
    ++non_zero;
    VERA(i, 1, Size(now)) all.push_back(now[i]);
  }
  if (have < 2 * (n - 1 - m)) {
    cout << "Impossible\n";
    return true;
  }
  sort(all.begin(), all.end());
  VERA(i, 0, 2 * (n - 1 - m) - non_zero) res += all[i];
  cout << res << endl;
  return true;
}

void Init() {
}

}

int main() {
#ifdef AZN
  const auto start_time = chrono::system_clock::now();
  freopen("../input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(1223);
  Init();
  ll test = 1;
  while (true)
    if (not Solve(test++))
      break;
#ifdef AZN
  cerr << "Took: " << ((chrono::system_clock::now() - start_time).count() /
                       static_cast<double>(chrono::system_clock::period::den)) << " s" << endl;
#endif
  return 0;
}


Measured memory_bytes: 7412
w,h=map(int,input().split())
s=sorted([[int(input()),0]for i in range(w)]+[[int(input()),1]for i in range(h)])
a,b,c=w+1,h+1,0
for i,j in s:
    if j:
        c+=i*a
        b-=1
    else:
        c+=i*b
        a-=1
print(c)

Measured memory_bytes: 32224
using System;
using System.Linq;
using System.Collections.Generic;
class A{
    static string change(string str){
        int t=int.Parse(str);
        t*=t;
        string y=t.ToString();
        int strs=t.ToString().Length;
        for(int i=0;i<8-strs;i++){
            y="0"+y;
        }
        //Console.WriteLine(y);
        return y.Substring(2,4);
    }
    static void Main(){
        int x=int.Parse(Console.ReadLine());
        for(int i=1;i<=x;i++){
            Console.WriteLine("Case "+i+":");
            string str=Console.ReadLine();
            for(int j=0;j<10;j++){
                str=change(str);
                Console.WriteLine(int.Parse(str));
                str=""+int.Parse(str)+"";
            }
        }
    }
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    map<ll, ll> mp, mp2;
    ll ret = 0;
    vector<ll> v(n);
    for(i = 0; i < n; i++) {
        ll x;
        cin >> v[i];
        x = v[i];
        mp2[x]++;
        x %= m;
        mp[x]++;
    }
    for(i = 0; i < m; i++) {
        if(i == 0 || 2 * i == m) {
            ret += mp[i] / 2;
            mp[i] -= mp[i] / 2 * 2;
        } else {
            ll p = min(mp[i], mp[(m - i) % m]);
            ret += min(mp[i], mp[(m - i) % m]);
            mp[i] -= p;
            mp[(m - i) % m] -= p;
        }
    }
    for(i = 0; i < n; i++) {
        if(mp[v[i] % m] >= 2 && mp2[v[i]] >= 2) {
            ret += min(mp2[v[i]], mp[v[i] % m]) / 2;
            mp[v[i] % m] -= min(mp2[v[i]], mp[v[i] % m]) / 2 * 2;
            mp2[v[i]] = 0;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 13568
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn];
int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

const int maxl = 31;
int cnts[31];

void solve() {
  memset(cnts, 0, sizeof(cnts));
  int whole = 0;
  for (int i = 0; i < n; ++i) {
    whole ^= a[i];
    int got = (a[i] ^ (a[i] - 1));
    cnts[__builtin_popcount(got)] += 1;
  }
  int res = 0;
  while (whole) {
    int high = 31 - __builtin_clz(whole);
    ++high;
    if (!cnts[high]) {
      printf("-1\n");
      return;
    }
    ++res;
    whole ^= (1 << high) - 1;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

using namespace std;
using ll = long long;
const ll INF = (int)(1e17+0.5);

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

    vector<int> weight(N);
    vector<int> value(N);
    for(int i=0; i<N; i++)cin >> weight.at(i) >> value.at(i);

    int V = 1000 * N;
    vector<vector<ll>> dp(N+1, vector<ll>(V + 1, INF));
    dp.at(0).at(0) = 0;

    // 方針: dp[i][sum_v]: 価値がsum_v以上となるように選んだ時の重さの総和の最小値
    // 漸化式
    // dp[i+1][sum_v] min= dp[i][sum_v - v[i]] + w[i] 
    //                min= dp[i][sum_v]  

    for(int i=0; i<N; i++){
        for(int sum_v=0; sum_v<=V; sum_v++){
            // 追加しない
            dp.at(i+1).at(sum_v) = min(dp.at(i+1).at(sum_v), dp.at(i).at(sum_v));

            // 追加する
            if(sum_v - value.at(i) >= 0)
                dp.at(i+1).at(sum_v) = min(dp.at(i+1).at(sum_v), dp.at(i).at(sum_v - value.at(i)) + weight.at(i));
        }
    }

    // for(auto row : dp){
    //     for(ll e : row)cout << ((e == INF) ? "x" : to_string(e)) << " ";
    //     cout << endl;
    // }

    int maxv = 0;
    for(int v=0; v<=V; v++){
        if(dp.at(N).at(v) <= W){
            maxv = v;
        }
    }

    cout << maxv << endl;
}

Measured memory_bytes: 83260
import math
n,m=map(int,input().split())
A=[]
if n%2==1:
    for i in range(m):
        A.append([i+1,n-i])
else:
    d=n//2-1
    h=math.ceil(d/2)
    for i in range(min(h,m)):
        A.append([i+1,n-i])
    if h<m:
        for j in range(m-h):
            A.append([i+j+2,n-i-j-2])
for a in A:
    print(*a)

Measured memory_bytes: 22540
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var L []int
var N, A, B, C int

func main() {
	s := wordScanner(100)
	scanInts(s, &N, &A, &B, &C)
	L = scanIntSlice(s, N)

	fmt.Println(dfs(N-1, 0, 0, 0))
}

func dfs(i, a, b, c int) int {
	if i < 0 {
		if min([]int{a, b, c}) == 0 {
			return 9999
		}
		return abs(A-a) + abs(B-b) + abs(C-c) - 30
	}
	r1 := dfs(i-1, a, b, c)
	r2 := dfs(i-1, a+L[i], b, c) + 10
	r3 := dfs(i-1, a, b+L[i], c) + 10
	r4 := dfs(i-1, a, b, c+L[i]) + 10
	return min([]int{r1, r2, r3, r4})
}

func min(l []int) int {
	r := l[0]
	for _, n := range l {
		if n < r {
			r = n
		}
	}
	return r
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}


Measured memory_bytes: 640
//I hate signal 11!!
#include<bits/stdc++.h>
#define MAX_N 215
#define MOD 998244353LL
#define LL long long
#define ccw(x,y,z,p,q,r) (((x)-(z))*(q)+((y)-(x))*(r)+((z)-(y))*(p))
using namespace std;
struct node{
	LL x,y;
}arr[MAX_N],b[MAX_N];
LL n,m,I,ans,t[MAX_N][MAX_N],cost[MAX_N],temp,z;
// I need angle sort stl...
//inline LL ccw(node x,node y,node z){return (x.x-z.x)*y.y+(y.x-x.x)*z.y+(z.x-y.x)*x.y;}
bool angle_sort(node x,node y){
	z=ccw(x.x,arr[I].x,y.x,x.y,arr[I].y,y.y);
	if(z<0)	return true;
	if(z>0)	return false;
}
void make_b(){
	LL i;
	m=0;
	for(i=1;i<=n;i++){
		if(arr[I].y>arr[i].y || (arr[I].y==arr[i].y && arr[I].x>=arr[i].x))	continue;
		b[++m]=arr[i];
	}
	sort(b+1,b+m+1,angle_sort);
}
int main(){
	LL i=1,prev,curr,next,cnt,scnt;
	cost[0]=1;
	while(i<=203){cost[i]=(cost[i-1]*2)%MOD;i++;}
	scanf("%lld",&n);
	for(i=1;i<=n;i++)	scanf("%lld %lld",&arr[i].x,&arr[i].y);
	//t[curr][next] : dp table, start i, curr and next node!!
	for(I=1;I<=n;I++){
		make_b();
		//first point : I(arr[I])...
		for(curr=1;curr<=m;curr++){
			for(next=curr+1;next<=m;next++){
				t[curr][next]=0;
				if(ccw(arr[I].x,b[curr].x,b[next].x,arr[I].y,b[curr].y,b[next].y)==0)	continue;
				cnt=scnt=0;
				for(i=curr+1;i<next;i++){
					if(ccw(b[curr].x,b[next].x,b[i].x,b[curr].y,b[next].y,b[i].y)>=0){
						cnt++;
						if(ccw(arr[I].x,b[i].x,b[curr].x,arr[I].y,b[i].y,b[curr].y)==0)	scnt++;
					}
				}
				for(i=curr-1;i>0;i--){
					if(ccw(arr[I].x,b[curr].x,b[i].x,arr[I].y,b[curr].y,b[i].y)!=0)	break;
					if(ccw(b[curr].x,b[next].x,b[i].x,b[curr].y,b[next].y,b[i].y)>=0){cnt++;scnt++;}
				}
				for(i=next+1;i<=m;i++){
					if(ccw(arr[I].x,b[next].x,b[i].x,arr[I].y,b[next].y,b[i].y)!=0)	break;
					if(ccw(b[curr].x,b[next].x,b[i].x,b[curr].y,b[next].y,b[i].y)>=0)	cnt++;
				}
				for(prev=curr-1;prev>0;prev--){
					if(ccw(b[prev].x,b[curr].x,b[next].x,b[prev].y,b[curr].y,b[next].y)>0)	t[curr][next]=(t[curr][next]+t[prev][curr])%MOD;
				}
				t[curr][next]=((t[curr][next]*cost[cnt-scnt])%MOD+cost[cnt])%MOD;
				ans=(t[curr][next]+ans)%MOD;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
	int yyyy,mm,dd;
	scanf("%d/%d/%d",&yyyy,&mm,&dd);
	ll ans=yyyy*365+mm*30+dd;
	if(ans<=2019*365+4*30+30){
		cout<<"Heisei"<<endl;
	} else{
		cout<<"TBD"<<endl;
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n,m;
ll f[111][111];
vector<ll> crt;

ll calc_score(vector<ll> vs){
  if(vs.size()<2)return 0;
  ll res=0;
  rep(i,vs.size()){
    ll mins=INF;
    rep(j,vs.size()){
      if(i==j)continue;
      minch(mins,f[vs[i]][vs[j]]);
    }
    res+=mins;
  }
  return res;
}

ll dfs(ll v){
  //dbg(v);
  ll res=calc_score(crt);
  repl(i,v+1,n){
    bool ok=true;
    for(ll u : crt){
      if(i!=u&&f[i][u]==0){
        ok=false;
      }
    }
    if(ok){
      crt.push_back(i);
      maxch(res,dfs(i));
      crt.pop_back();
    }
  }
  return res;
}

int main(){
	cin.sync_with_stdio(false);
  memset(f,0,sizeof(f));
  cin>>n>>m;
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    f[a][b]=f[b][a]=c;
  }
  ll res=0;
  rep(i,n){
    crt.push_back(i);
    maxch(res,dfs(i));
    crt.pop_back();
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge{ll s,t,d;};
typedef vector<vector<Edge>> Graph;

vi topologicalSort(vvi &G) {
  ll V=G.size();
  vi in(V);
  for(vi &v:G) for(ll to:v) in[to]++;
  queue<ll> q;
  REP(i,V) if(in[i]==0) q.push(i);
  vi ret;
  while(q.size()) {
    ll from=q.front();
    q.pop();
    ret.PB(from);
    for(ll to:G[from]) {
      in[to]--;
      if(in[to]==0) q.push(to);
    }
  }
  return ret;
}

int main() {
  ll V,E; cin>>V>>E;
  vvi G(V);
  REP(i,E) {
    ll s,t; cin>>s>>t;
    G[s].PB(t);
  }
  vi ans=topologicalSort(G);
  for(ll i:ans) cout<<i<<endl;
}

Measured memory_bytes: 3884
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

using namespace std;

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

int main() {
    int N, L;
    cin >> N >> L;
    int ans = N * L + N * (N - 1) / 2;
    if (L <= 0 && 0 <= L + N - 1) {
    } else if (L > 0) {
        ans -= L;
    } else {
        ans -= L + N - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <regex>
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;

    s += s;
    cout << (regex_search(s, regex(t)) ? "Yes" : "No") << endl;
}

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

A=[0]*N
B=[0]*N

for i in range(0,N):
  tmp=list(map(int,input().split()))
  A[i]=tmp[0]
  B[i]=tmp[1]
c=zip(A,B)
c=sorted(c)
total=0
idx=0
totalcan=0
while totalcan<M:
  total+=c[idx][0]*c[idx][1]
  totalcan+=c[idx][1]
  idx+=1

while totalcan>M:
  total-=c[idx-1][0]
  totalcan-=1
print(str(total))

Measured memory_bytes: 18588
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

 int main(){

	 int N,point2,point3,tmp;
	 ll ans = -1;
	 scanf("%d",&N);

	 ll* table = new ll[N+1];
	 table[0] = 0;

	 for(int i = 1; i <= N; i++){
		 scanf("%lld",&table[i]);
		 table[i] += table[i-1];
	 }

	 ll left,right,m,inner_left,inner_right,inner_m,sum;
	 bool FLG;

	 left = 1;
	 right = table[N]/3;
	 m = (left+right)/2;

	 while(left <= right){
		 FLG = false;

		 for(int start = 1; start <= N; start++){

			 inner_left = 1;
			 inner_right = N-1;
			 inner_m = (inner_left+inner_right)/2;

			 point2 = -1;

			 while(inner_left <= inner_right){

				 if(start+inner_m > N){
					 tmp = start+inner_m-N;
				 }else{
					 tmp = start+inner_m;
				 }

				 if(tmp > start){
					 sum = table[tmp-1] - table[start-1];
				 }else{
					 sum = (table[N]-table[start-1]) + (table[tmp-1] - table[0]);
				 }

				 if(sum >= m){
					point2 = tmp;
					inner_right = inner_m-1;
				 }else{
					 inner_left = inner_m+1;
				 }
				 inner_m = (inner_left+inner_right)/2;
			 }

			 inner_left = 1;
			 if(point2 > start){
				 inner_right = N+start-point2-1;
			 }else{
				 inner_right = start-point2-1;
			 }
			 inner_m = (inner_left+inner_right)/2;
			 point3 = -1;

			 while(inner_left <= inner_right){

				 if(point2+inner_m > N){
					 tmp = point2+inner_m-N;
				 }else{
					 tmp = point2+inner_m;
				 }

				 if(tmp > point2){
					 sum = table[tmp-1] - table[point2-1];
				 }else{
					 sum = (table[N]-table[point2-1]) + (table[tmp-1] - table[0]);
				 }

				 if(sum >= m){
					 if(start > tmp){
						 sum = table[start-1] - table[tmp-1];
					 }else{
						 sum = (table[N]-table[tmp-1]) + (table[start-1] - table[0]);
					 }
					 if(sum >= m){
						 point3 = tmp;
						 inner_right = inner_m-1;
					 }else{
						 inner_right = inner_m-1;
					 }
				 }else{
					 inner_left = inner_m+1;
				 }
				 inner_m = (inner_left+inner_right)/2;
			 }

			 if(point3 == -1){
				 continue;
			 }else{
				 FLG = true;
				 break;
			 }
		 }

		 if(FLG){
			 ans = m;
			 left = m+1;
		 }else{
			 right = m-1;
		 }
		 m = (left+right)/2;
	 }

	 printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
long long a[N],b[N],c[N],d[N],e[N],f[N],m,n;
int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i]>>b[i],c[i]=m-a[i],d[i]=b[i],b[i]+=b[i-1];
    for(int i=n; i>=0; i--)
        d[i]+=d[i+1];
    for(int i=1; i<=n; i++)
        e[i]=max(e[i-1],b[i]-2*a[i]),f[i]=max(f[i-1],b[i]-a[i]);
    long long ans=0;
    for(int i=1; i<=n+1; i++)
        ans=max(ans,max(e[i-1]+d[i]-c[i],f[i-1]+d[i]-2*c[i]));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  ll N,X,ans=0;
  cin>>N>>X;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  
  if(A[0]>X){
    ans+=A[0]+A[1]-X;
    A[1]=0;
  }
  
  if(A[0]<=X){
    if(A[0]+A[1]>X){
      ans+=A[0]+A[1]-X;
      A[1]=X-A[0];
    }
  }
  
  for(int i=2; i<N; ++i){
    if(A[i-1]+A[i]>X){
      ans+=A[i-1]+A[i]-X;
      A[i]=X-A[i-1];
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	a = abs(a);
	b = abs(b);
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
vel dx{ 1,1,0,0,-1,-1 };
vel dy{ 0,1,1,-1,-1,0 };
signed main() {
	vel ans;
	while (true) {
		int t, n; cin >> t >> n;
		if (t == 0 and n == 0) { break; }
		V<veb> syou(150, veb(150, false));
		int x, y;
		rep(i, n) { cin >> x >> y; x += 60; y += 60; syou[x][y] = true; }
		vvel dist(150, vel(150, -1));
		int sx, sy; cin >> sx >> sy;
		sx += 60; sy += 60;
		dist[sx][sy] = 0;
		queue<pin> q; q.push(mkp(sx, sy));
		int count = 0;
		count++;
		while(!q.empty()) {
			pin poi = q.front(); q.pop();
			rep(i, 6) {
				int x = poi.first + dx[i];
				int y = poi.second + dy[i];
				if (0 <= x and x < 150 and 0 <= y and y < 150) {
					if (dist[x][y] == -1 and !syou[x][y]) {
						q.push(mkp(x, y));
						dist[x][y] = dist[poi.first][poi.second] + 1;
						if (dist[x][y] <= t) { count++; }
					}
				}
			}
		}
		ans.push_back(count);
	}
	for (auto x : ans) { cout << x << endl; }
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
const int HMAX=100,WMAX=100;
const int m[4][2]={{-1,0},{0,-1},{0,1},{1,0}};

bool p[HMAX][WMAX];
char a[HMAX][WMAX];
int h,w;

void dfs(int x,int y,char l)
{
	if(x<0||x>=h)return;
	if(y<0||y>=w)return;
	if(a[x][y]!=l)return;
	if(p[x][y])return;
	p[x][y]=true;
	for(int i=0;i<4;i++)dfs(x+m[i][0],y+m[i][1],a[x][y]);
}

int main()
{
	while(scanf("%d%d",&h,&w)==2)
	{
		if(h==0&&w==0)break;
		int c=0;
		memset(p,0,sizeof p);
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %c",&a[i][j]);
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(!p[i][j])dfs(i,j,a[i][j]),++c;
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 1680
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    
    let (a, b, c) = {
        let mut input = String::new();
        stdin.read_line(&mut input).unwrap();
        let mut input = input.trim().split_whitespace();
        (
            input.next().unwrap().parse::<u32>().unwrap(),
            input.next().unwrap().parse::<u32>().unwrap(),
            input.next().unwrap().parse::<u32>().unwrap(),
        )
    };

    let d = a - b;
    
    println!("{}", c.saturating_sub(d) );
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    if (prev_permutation(a.begin(), a.end()))
        print_line(a);

    next_permutation(a.begin(), a.end());
    print_line(a);

    if (next_permutation(a.begin(), a.end()))
        print_line(a);


}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	if (n % 2 == 0) {
		ll ans = 0;
		ll tmp = 5;
		while (tmp <= n) {
			ans += n / tmp / 2;
			tmp *= 5;
		}
		printf("%lld\n", ans);
	}
	else {
		printf("%d\n", 0);
	}
	return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let upper = buf.trim().parse::<i32>().unwrap();

    let mut pow2 = 1;
    if upper == 1{
        println!("1");
    } else {
        while pow2 <= upper {
            pow2 *= 2;
        }
        println!("{}", pow2 / 2);
    }
}


Measured memory_bytes: 4352
#int(input())
#int(x) for x in input().split()
#map(int,input().split())
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
co=0
s=set([1])
i=0
path=[1]
j=0
while True:
	co+=1
	path.append(a[i])
	if a[i] in s:
		j=path.index(a[i])
		break
	else:
		s.add(a[i])
	i=a[i]-1
#print(path)
if k<=j:
	print(path[k])
else:
	k-=j
	path=path[j+1:]
	k-=1
	k=k%(len(path))
	print(path[k])







		
		




Measured memory_bytes: 125072
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    if(count(S.begin(), S.end(), '-') != 1) {
        cout << "No" << endl;
        return 0;
    }
    if(S[A] != '-') {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin >> n >> k;
    vector<int> b(n);
    rep(i,k){
        int d;cin >> d;
        rep(i,d){
            int a;cin >> a;
            a--;
            b[a]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(b[i]==0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

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

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
}

int main() {
	int n;
	cin >> n;
	VI v(n);
	REP(i, n) { cin >> v[i]; }

	int count = 0;
	REPC(x, v) {
		int t = x;
		while (t%2==0) {
			t /= 2;
			++count;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
//import java.math.BigInteger;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        int D = sc.nextInt();
        int N = sc.nextInt();
        //int[] m = new int[N];
        int ans = 1;
        
        //ans = N * (int)Math.pow(100,D);
        for(int i=0; i<D; i++){
            ans = ans * 100;
        }
        
        if(N==100){
            ans = ans * (N+1);
        }else{
            ans = ans * N;
        }
        
        System.out.println(ans);
    }
}


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

int main() {
	int a,b,c;cin>>a>>b>>c;
	int n,m;
	n=a;
	m=b;
	if(n>m){
		n=b;
		m=a;
	}
	int ans;
	if(m>c){
		ans=n+c+10*m;
	}else{
		ans=n+m+10*c;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,M;
signed main(){
	cin>>N>>M;
	if(N&1){
		rep(i,M)cout<<i+1<<" "<<N-i<<endl;
	}else {
		int l=1,r=N;bool flag=false;
		rep(i,M){
			if(r-l<=N/2&&!flag){r--;flag=true;}
			cout<<l++<<" "<<r--<<endl;
		}
	}
}


Measured memory_bytes: 3640
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector <int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto check = [&] (int x) {
    long long s = 0;
    for (int z : a) {
      s += (z + x - 1) / x - 1;
    }
    return s <= k;
  };
  int l = 0, r = *max_element(a.begin(), a.end()) + 1;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (check(m)) r = m;
    else l = m;
  }
  cout << r << endl;
}


Measured memory_bytes: 4012