akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int my_abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int my_abs_B(long long num,long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

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

int main() {
    int A, B;
    cin >> A >> B;
    vector<int> retu(B);
    int count = 0;
    for (int i = 0; i < B; i++) {
        cin >> retu.at(i);
        count = count + retu.at(i);
    }
    if (A <= count) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}

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

int sua, sbu, sba, n, ans;
string s;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		for (int j = 1; j < s.size(); j++)
			ans += (s[j - 1] == 'A' && s[j] == 'B');
		if (s[0] == 'B' && s.back() == 'A')
			sba++;
		else if (s[0] == 'B')
			sbu++;
		else if (s.back() == 'A')
			sua++;
	}
	if (sua > 0)
		ans += sba + min(sua, sbu);
	else if (sba > 0)
		ans += sba - 1 + (sbu > 0);
	cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

constexpr int mod = 998244353;

std::vector<int> sums;

int calc(int n, const std::vector<std::pair<int, int>>& lrs, std::vector<int>& dp)
{
  for (std::size_t i = 0; i < lrs.size(); ++i) {
    const auto& p = lrs[i];
    if (n - p.second - 1> 0) {
      sums[i] -= dp[n - p.second - 1];
      if (sums[i] < 0) sums[i] += mod;
      sums[i] %= mod;
    }
    if (n - p.first > 0) {
      sums[i] += dp[n - p.first];
      sums[i] %= mod;
    }
  }

  int result = 0;
  for (std::size_t i = 0; i < lrs.size(); ++i) {
    result += sums[i];
    result %= mod;
  }
  dp[n] = result;
  return result;
}

int solve(int n, int k, std::vector<std::pair<int, int>>& lrs)
{
  std::sort(lrs.begin(), lrs.end());

  sums = std::vector<int>(k);

  std::vector<int> dp(n + 1, -1);
  dp[1] = 1;
  for (int i = 2; i < n; ++i) {
    calc(i, lrs, dp);
  }
  return calc(n, lrs, dp);
}

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::vector<std::pair<int, int>> lrs(k);
  for (auto& p : lrs) {
    std::cin >> p.first >> p.second;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, k, lrs) << std::endl;
}


Measured memory_bytes: 3924
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	int n, a, mi = 100;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		int cnt = 0;
		while (a % 2 == 0) {
			a /= 2;
			cnt++;
		}
		mi = min(mi, cnt);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxN=200005,M=1e9+7;
int n,k,resp;
int mod(int x,int M){int ret=x%M;if(ret<0)ret+=M;return ret;}
int fact[mxN],inv[mxN];
int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);

    int t=mod(exp(a,b/2,M),M);
    if(b%2==1)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);
}

int C(int n,int k){
    return mod(fact[n]*mod(inv[k]*inv[n-k],M),M);
}

int32_t main(){
    cin>>n>>k;
    fact[0]=inv[0]=1;
    for(int i=1;i<mxN;i++){
        fact[i]=(fact[i-1]*i)%M;

    }
    inv[mxN-1] = exp(fact[mxN-1],M-2,M);
	for(int i=mxN-2;i>=1;i--){
		inv[i] = (inv[i+1]*(i+1))%M;
	}

    for(int i=0;i<=min(n-1,k);i++){
        resp=mod(resp+mod(C(n,i)*C(n-1,i),M),M);
    }
    cout<<resp;


}

Measured memory_bytes: 3328
n, m, v, p = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
 
lim_A = A[p-1]
res_A = A[p:]
res_n = len(res_A)
 
for i in range(res_n):
    res_A[i] = lim_A - res_A[i]
 
ans = p
cnt = 0
for i in range(res_n):
    if m >= res_A[i] and m * max(v-p-(res_n-i-1), 0) <= cnt + (m-res_A[i])*(i+1):
        ans += 1
    cnt += res_A[i]
 
print(ans)

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


int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int low=0;
  int high=0;
  for(int i=0;i<m;++i){
    int a;
    cin >> a;
    if(a<x) low++;
    else high++;
  }
  int ans=min(low,high);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main()
{
    string s; cin >> s;
    int l = s.size();
    int a_place = 1, z_place = l;
    
    for (int i = 0; i < l; i++){
        if (s[i] == 'A'){
            break;
        }
        a_place++;
    }
    for (int j = l - 1; j >= 0; j--){
        if (s[j] == 'Z'){
            break;
        }
        z_place--;
    }
    cout << z_place - a_place + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
n,l = gets.chomp.split(" ").map(&:to_i)
apple = []
n.times do |i|
  apple.push(l+i)
end
minus = 0
if l<0 && l+n-1<=0
  minus = l+n-1
elsif l<0 && l+n-1>0
  minus = 0
else
  minus = l
end

puts apple.inject(:+) - minus

Measured memory_bytes: 14208
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
#define MAX 1000005
#define forci(p,q) for(int i=p;i<q;i++)
bool prime[MAX];
/*ull sieve()
{
	memset(prime,true,sizeof(prime));
	for(ull p=2;p*p<MAX;p++)
	{
		if(prime[p]==true){
			for(ull i=2*p;i<MAX;i+=p)
			{
				prime[i]=false;
			}
		}
	}
	prime[0]=0;
	prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	double r;
	cin>>r;
	double pie=3.141593;
	double circum=pie*2*r;
	cout<<fixed<<setprecision(7)<<circum;
	
	
	
	
	
	
}












Measured memory_bytes: 3808
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

ll calc(ll a){
    ll mod = 1,res=0;
    if(a==-1) return 0;
    rep(i,40){
        mod*=2;
    }//mod=2^40
    if(a%4==1||a%4==2){
        res++;
    }
    for(;mod>2;mod/=2){
        ll k=a%mod;
        if((k>=mod/2)&&a%2==0){
            res+=mod/2;
        }
    }
    return res;
}

int main(){
    ll a,b;
    cin >> a >> b;
    a--;
    
    ll res = calc(a)^calc(b);
    cout << res << endl;
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a, b, c, d, e, n, m, k;
string s, t, r;
char c1, c2, c3;

ll A[200005];
ll B[200005];
ll C[200005];

ll pref[200005];

int main() {
	int n, m, k;
	cin >>n>>m>>k;
	for (int i=0 ; i<n ; i++) cin >>A[i];
	for (int i=0 ; i<m ; i++) cin >>B[i];
	for (int i=0 ; i<n ; i++) {
		pref[i+1] = pref[i]+A[i];
	}
	int pos = n;
	ll uk = 0;
	int sol = 0;
	for (int i=0 ; i<=m ; i++) {
		while (uk + pref[pos] > k && pos>=0) pos--;
		if (pos < 0) break;
		sol = max(sol, i+pos);
		if (i!=m) uk += B[i];
	}
	cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 8324
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
const int N = 1e5 + 100;
int A[N];
int B[N];
int C[N];
int D[N];
void pA(int *a, int n){
	for(int i =0 ;i<n;i++)printf("%d ", a[i]);
	printf("\n");
}
void inp(){
	int n;scanf("%d",&n);
	for(int i = 0;i<n;i++)scanf("%d",&A[i]);
	B[0] = 0;
	for(int i = 1;i<=n;i++)B[i] = A[i - 1];
	B[n+1] = 0;
	n += 2;
	for(int i = 0;i<n - 1;i++)C[i] = abs(B[i + 1] - B[ i ]);
	D[0] = C[0];
	for(int i = 1;i<n - 1;i++)D[i] = D[i-1] + C[i];
//	pA(C,n);
//	pA(D,n);
//
	int ans,a,b,c;
	for(int i = 1;i<n-1;i++){
		a = (i-2>=0)?D[i - 2]:0;
		b =  D[n-2] - D[ i];
		c = abs(B[i + 1] - B[i-1]);
		//printf("f %d e %d  m %d\n", a,b,c);
		ans = a+b+c;
		printf("%d\n",ans);
	}
}
//C.cc by xsthunder at Sun Mar 25 20:00:09 2018


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

int main()
{
    int* R_t;
    int i, n, d, min, max;
    cin >> n;

    R_t = new int [n];
    if(R_t == NULL) return 0;

    cin	>> R_t[0] >> R_t[1];
    min = R_t[0];
    max = R_t[1] - R_t[0];
    if(R_t[0] > R_t[1]) min = R_t[1];

    for(i = 2; i < n; i++){
        cin >> R_t[i];
        d = R_t[i] - min;
        if(max < d) max = d;
        if(min > R_t[i]) min = R_t[i];
    }

    cout << max << endl;
    delete [] R_t;

    return 0;
}

Measured memory_bytes: 1800
#include<iostream>
    #include<algorithm>
    #include<string>
    using namespace std;
    int main()
    {
    	int a;
    	cin >> a;
    	string s;
    	cin >> s;
    	if (a >= 3200)cout << s << endl;
    	else cout << "red\n";
    	return 0;
    }

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

int main(){
  int N,L;
  int sum = 0;
  int min = 10000;
  int count;
  
  cin >> N >> L;
  
  for(int i=1;i<N+1;i++){
    count = L+i-1;
    sum+=count;
    
    if(abs(min) > abs(count)) min = count;
  }
  
  cout << sum-min <<endl;
  
  
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
k=0
for i in range(N):
	k=k+min(A[i],B[i])
	if A[i]<=B[i]:
		B[i]=B[i]-A[i]
		A[i]=0
	else:
		A[i]=A[i]-B[i]
		B[i]=0
	
	k=k+min(B[i],A[i+1])
	if B[i]<=A[i+1]:
		A[i+1]=A[i+1]-B[i]
		B[i]=0
	else:
		B[i]=B[i]-A[i+1]
		A[i+1]=0

print(k)

Measured memory_bytes: 19004
n=int(input())
a=[int(x) for x in input().split()]
s=all([x%2==0 for x in a])
ans=0
while s:
    s=all([x%2==0 for x in a])
    if s:
        ans+=1
    for i in range(n):
        a[i]=a[i]//2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int gcd(int m,int n){if(m%n==0)return n;else return gcd(n,m%n);}
int num(int a,int b,int c)
{
	if(a==b&&b==c)return 1;
	else if(a==b||b==c||c==a)return 3;
	else return 6;
}
int main()
{
	int k;cin>>k;
	int s=0;
	for(int a=1;a<=k;a++)for(int b=a;b<=k;b++)for(int c=b;c<=k;c++)s+=gcd(a,gcd(b,c))*num(a,b,c);
	cout<<s<<'\n';
	return 0;
}


Measured memory_bytes: 3628
import sys
n= int(input())
A = list(map(int, input().split()))
s=0 
for i in range(n-1):
    if A[i]>A[i+1]:
        d=A[i]-A[i+1]
        s=s+d
        A[i+1]=A[i+1]+d
print(s)

Measured memory_bytes: 32380
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
a=set(a)
mod=10**9+7
dp=[0]*(n+7)
dp[0]=1
for i in range(n+1):
    if i+2 not in a: #2段先が壊れていない
        dp[i+2]+=dp[i]
    if i+1 not in a: #1段先が壊れていない
        dp[i+1]+=dp[i]
    dp[i+2]%=mod
    dp[i+1]%=mod
print(dp[n]%mod)


Measured memory_bytes: 18984
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 1000000
#define MOD 1000000007

int N, Q;
char S[N_MAX + 10];
int num[3][N_MAX + 10];
void solv2(int k)
{
	lli ret = 0;
	int left = -1, right = -1;
	for (int i = 0; i < N; i++) {
		if ('D' == S[i]) {
			left = i;
			break;
		}
	}

	if (-1 == left) {
		printf("0\n");
		return;
	}

	lli sum = 0;
	for (right = left; right < min(N, left + k); right++) {
		if ('C' != S[right]) continue;
		sum += (lli)(num[1][right + 1] - num[1][left + 1]);
	}
	ret += sum;

	for (left = left + 1; left < N; left++, right = min(N, right + 1)) {
		if ('M' == S[left]) {
			sum -= (lli)(num[2][right] - num[2][left + 1]);
		}
		if ('C' == S[right]) {
			sum += (lli)(num[1][right] - num[1][left + 1]);
		}
		if ('D' == S[left]) {
			ret += sum;
		}
	}

	printf("%lld\n", ret);
}

void solv()
{
	scanf("%d%s%d", &N, S, &Q);

	num[0][0] = num[1][0] = num[2][0] = 0;
	for (int i = 1; i <= N; i++) {
		num[0][i] = num[0][i - 1] + ('D' == S[i - 1] ? 1 : 0);
		num[1][i] = num[1][i - 1] + ('M' == S[i - 1] ? 1 : 0);
		num[2][i] = num[2][i - 1] + ('C' == S[i - 1] ? 1 : 0);
	}
	num[1][N + 1] = num[1][N];

	for (int i = 0; i < Q; i++) {
		int k; scanf("%d", &k);
		solv2(k);
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 12928
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

#define nmax 3010

int n;
int a[nmax];
bool fr[nmax][nmax];
ll dp[nmax][nmax];

ll compute(int l, int r)
{
    if (l > r) return 0;
    if (fr[l][r]) return dp[l][r];

    fr[l][r] = true;

    ll l_ans = a[l] - compute(l + 1, r);
    ll r_ans = a[r] - compute(l, r - 1);

    return dp[l][r] = max(l_ans, r_ans);
}

int main()
{
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    printf("%lld", compute(1, n));

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 80000
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10;
int n,m,q,a[N][N],b[N][N],c[N][N];
char s[N][N];
int main() {
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++) {
        scanf("%s",s[i]+1);
        for(int j=1;j<=m;j++) s[i][j]-='0';
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) {
            a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+s[i][j];
            b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+(s[i][j]&s[i][j+1]);
            c[i][j]=c[i-1][j]+c[i][j-1]-c[i-1][j-1]+(s[i][j]&s[i+1][j]);
        }
    while(q--) {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        int A=a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];
        int B=b[x2][y2-1]-b[x1-1][y2-1]-b[x2][y1-1]+b[x1-1][y1-1];
        int C=c[x2-1][y2]-c[x1-1][y2]-c[x2-1][y1-1]+c[x1-1][y1-1];
        printf("%d\n",A-B-C);
    }
    return 0;
}


Measured memory_bytes: 52992
function main(_stdin){
    const stdin = _stdin.split('\n');
    const len = parseInt(stdin.shift(), 10);
    const proRes = stdin.shift().split(' ').map(e => parseInt(e, 10));
    const inoRes = stdin.shift().split(' ').map(e => parseInt(e, 10));

    const data = [];
    const walked = [];
    for(let i=0;i<len+1;i++){
        if(i === 0) data[i] = 0;
        data[i] = [i, -1, -1];
    }

    setData(0, proRes, inoRes, data);
    const rootidx = proRes[0];

    outParse(data, rootidx, walked);
    console.log(walked.join(' '));
}

function setData(proInd, prores, targets, data){
    const nodeId = prores[proInd];
    const d = data[nodeId];
    if(targets.length === 1){
        d[1] = -1;
        d[2] = -1;
        return;
    }
    let splita;
    for(let i=0,l=targets.length;i<l;i++){
        if(targets[i] === nodeId) splita = i;
    }
    const left = targets.slice(0, splita);
    const right = targets.slice(splita+1);

    if(left.length){
        const leftPro = prores.filter(e => left.indexOf(e) > -1);
        d[1] = leftPro[0];
        const index = prores.indexOf(d[1]);
        setData(index, prores, left, data);
    } else {
        d[1] = -1;
    }

    if(right.length){
        const rightPro = prores.filter(e => right.indexOf(e) > -1);
        d[2] = rightPro[0];
        const index = prores.indexOf(d[2]);
        setData(index, prores, right, data);
    } else {
        d[2] = -1;
    }
}

function outParse(inputs, idx, walked) {
    if(idx === -1){
        return;
    }
    outParse(inputs, inputs[idx][1], walked);
    outParse(inputs, inputs[idx][2], walked);

    walked.push(inputs[idx][0]);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

int main(){
	int a,b;
	cin>>a>>b;
	if(a>=b){
		rep(i,a){
			cout<<b;
		}
		
	}else{
		rep(i,b){
			cout<<a;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 3648
N,M=map(int,input().split())
import heapq
A=list(map(int,input().split()))
heapq.heapify(A)
BC=[]
for i in range(M):
  B,C=map(int,input().split())
  BC.append((B,C))
BC.sort(key=lambda x:x[1],reverse=True)
import bisect
A.sort()
now=0
D=[0]*N
for i in range(M):
  B=BC[i][0]
  C=BC[i][1]
  for j in range(now,min(now+B,N)):
    D[j]=C
  now+=B
  if now>N-1:
    break

for i in range(N):
  a=A[i]
  d=D[i]
  if d>a:
    A[i]=d
  else:
    break
print(sum(A))

Measured memory_bytes: 28100
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, m, l;
int far[305][305], far2[305][305];
signed main() {
	cin >> n >> m >> l;
	rep(i, n)rep(j, n) {
		if (i == j)continue;
		far[i][j] = far2[i][j] = inf;
	}
	rep(i, m) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		far[a][b] = c; far[b][a] = c;
	}
	rep(i, n)rep(j, n)rep(k, n)chmin(far[j][k], far[j][i] + far[i][k]);
	rep(i, n)rep(j, n) {
		if (i == j)continue;
		if (far[i][j] <= l)far2[i][j] = 1;
	}
	rep(i, n)rep(j, n)rep(k, n)chmin(far2[j][k], far2[j][i] + far2[i][k]);
	int q; cin >> q;
	while (q--) {
		int s, t; cin >> s >> t; s--; t--;
		cout << (far2[s][t] != inf ? far2[s][t] - 1 : -1) << endl;
	}
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long H,W;
  cin>>H>>W;
  if(H==1||W==1){
    cout<<1<<endl;
  }
  else{
    if(H%2==0){
      cout<<H*W/2<<endl;
    }
    if(H%2==1&&W%2==1){
      cout<<H*W/2+1<<endl;
    }
    if(H%2==1&&W%2==0){
      cout<<H*W/2<<endl;
    }
  }
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef long long ll;
ll dp[55][2600];
int v[55];
int main(void)
{
	int N, A;
	ll sum = 0;
	scanf("%d %d", &N, &A);
	for (int i = 1; i <= N; i++)
		scanf("%d", &v[i]);
	dp[0][0] = 1;
	for (int k = 1; k <= N; k++)
	{
		sum += v[k];
		for (int i = k; i >=1; i--)
			for (int j = sum; j >= v[k]; j--)
				dp[i][j] += dp[i - 1][j - v[k]];
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++)
		ans += dp[i][i * A];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1152
class Heap(list):
    def __init__(self, init_list = []):
        super().__init__(init_list)

    @staticmethod
    def left(i: int) -> int:
        return 2 * i + 1

    @staticmethod
    def right(i: int) -> int:
        return 2 * i + 2

    def max_heapify(self, i: int):
        l = self.left(i)
        r = self.right(i)
        H = len(self)
        # ????????????????????????????????§???????????§????????????????????¶
        if l < H and self[l] > self[i]:
            largest = l
        else:
            largest = i
        if r < H and self[r] > self[largest]:
            largest = r
        if largest != i:  # i ???????????????????????§????????´???
            # A[i] ??¨ A[largest] ?????????
            tmp = self[i]
            self[i] = self[largest]
            self[largest] = tmp
            self.max_heapify(largest)  # ?????°??????????????????

    def build_max_heap(self):
        for i in range(len(self)//2, -1, -1):
            self.max_heapify(i)

n = int(input())
xs = Heap([int(i) for i in input().split()])
xs.build_max_heap()
print(" " + " ".join([str(i) for i in xs] ))

Measured memory_bytes: 65660
#include<stdio.h>


void printNums(int nums[], int length)
{
	for(int i = 0; i < length - 1; i++)
	{
		printf("%d ", nums[i]);
	}
	printf("%d\n", nums[length - 1]);
}

int main(){

	int length;
	scanf("%d", &length);

	int i, nums[length];
	for(i = 0; i<length ; i++)
	{
		scanf("%d", &nums[i]);
	}
	
	printNums(nums, length);

	int v, j;
	for(i=1;i<length;i++)
	{
		v = nums[i];
		j = i-1;
		while(j>=0 && nums[j] > v)
		{
			nums[j+1]=nums[j];
			j--;
		}
		nums[j+1] = v;

		printNums(nums, length);
	}

	return 0;
}

Measured memory_bytes: 1804
from itertools import combinations_with_replacement
def main():
    n, m, q = map(int, input().split())
    query = []
    for _ in range(q):
        a, b, c, d = map(int, input().split())
        query.append([a, b, c, d])
    
    ele = [i for i in range(1, m+1)]
    
    ans = -1
    for comb in combinations_with_replacement(ele, n):
        comb = sorted(comb)
        tmp = 0
        for qu in query:
            if comb[qu[1]-1] - comb[qu[0]-1] == qu[2]:
                tmp += qu[3]
            else:
                continue
        if tmp > ans:
            ans = tmp
    print(ans)
    
main()

Measured memory_bytes: 68420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct FastFourierTransform {
    vector<Complex> dft(vector<Complex> A, int N, int sgn = 1) {
        if (N == 1) return A;

        vector<Complex> F(N / 2), G(N / 2);
        for (int i = 0; i < N / 2; i++) {
            F[i] = A[2 * i + 0];
            G[i] = A[2 * i + 1];
        }

        F = dft(F, N / 2, sgn);
        G = dft(G, N / 2, sgn);

        Complex zeta(cos(2.0 * M_PI / N), sin(2.0 * M_PI / N) * sgn);
        Complex pow_zeta = 1;

        for (int i = 0; i < N; i++) {
            A[i] = F[i % (N / 2)] + pow_zeta * G[i % (N / 2)];
            pow_zeta *= zeta;
        }
        return A;
    }

    vector<Complex> inv_dft(vector<Complex> A, int N) {
        A = dft(A, N, -1);
        for (int i = 0; i < N; i++) {
            A[i] /= N;
        }
        return A;
    }

    vector<Complex> multiply(vector<Complex> A, vector<Complex> B) {
        int sz = A.size() + B.size() + 1;
        int N = 1;
        while (N < sz) N *= 2;

        A.resize(N), B.resize(N);
        A = dft(A, N);
        B = dft(B, N);

        vector<Complex> F(N);
        for (int i = 0; i < N; i++) {
            F[i] = A[i] * B[i];
        }
        return inv_dft(F, N);
    }

    vector<double> convolve(vector<Complex> A, vector<Complex> B) {
        vector<Complex> mul = multiply(A, B);
        vector<double> ret(sz(mul));
        for (int i = 0; i < sz(mul); i++) {
            ret[i] = mul[i].real();
        }
        return ret;
    }
};

int main() {
    int n;
    ll m;
    cin >> n >> m;
    vector<int> a(100100);
    rep(i, n) {
        int aa;
        cin >> aa;
        a[aa]++;
    }
    vector<Complex> b(100100), c(100100);
    rep(i, 100100) {
        b[i] = Complex(a[i]);
        c[i] = Complex(a[i]);
    }

    FastFourierTransform fft;
    auto vec = fft.convolve(b, c);

    ll cnt = m;
    ll ans = 0;
    for (ll i = sz(vec) - 1; i >= 0; i--) {
        ll now = (ll)(vec[i] + 0.5);
        ans += i * max(0LL, min(cnt, now));
        cnt -= now;
        if (cnt <= 0) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 41772
from __future__ import print_function
# import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,m = map(int, input().split())
p=[i for i in range(m+1)]
y=[i for i in range(m+1)]
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

# eprint(l_pref)


lll = [(1,1) for i in range(m+1)]
for i in range(1,n+1):
    for j in range(len(l_pref[i])):
        lll[l_pref[i][j][1]] = j+1
# eprint(lll)

for i in range(1,m+1):
    # temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(lll[i]))) + str(lll[i]) )


Measured memory_bytes: 93868
integer(16) n
integer(16),allocatable,dimension(:)::a
integer check
integer zero
read*,N
allocate(a(N))
read*,a
check=2
zero=1
do i=1,N
  if(a(i)==0)zero=0
  if(a(i)<0)then
    check=check+1
    a(i)=-a(i)
  end if
end do
print"(I0)",sum(a)-2*minval(a)*zero*merge(0,1,mod(check,2)==0)
end

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
#define pb push_back
#define mp make_pair

const int maxn = 1e5+1;
int gcd(int a, int b)
{
  return b?gcd(b, a%b):a;
}
int a[maxn];
int n, k;
int main()
{
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i)
    scanf("%d", a+i);
  int g = a[0];
  for (int i = 0; i < n; ++i)
    g = gcd(g, a[i]);
  for (int i = 0; i < n; ++i)
    {
      if (a[i] >= k && (k-a[i])%g == 0)
	{
	  puts("POSSIBLE");
	  return 0;
	}
    }
  puts("IMPOSSIBLE");

}


Measured memory_bytes: 640
N = int(input())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]

table = [[0 for i in range(3)] for j in range(N)]

for i in range(1, len(X)):
    table[X[i] - 1][0] = 1
for i in range(1, len(Y)):
    table[Y[i] - 1][1] = 1
for i in range(1, len(Z)):
    table[Z[i] - 1][2] = 1

ans = 0
for i in range(len(table)):
    if (table[i][0] == 0 and table[i][2] == 1) or (table[i][1] == 1 and table[i][2] == 1):
        ans = ans + 1
print(ans)



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using i64 = long long;

std::vector<int> s;
std::vector<std::vector<int>> g;

std::tuple<i64, i64, int> dfs(int v, int p) {
    int cnt = s[v], t = 0;
    i64 rsum = 0, lsum = 0;
    auto maxp = std::make_pair(0ll, 0ll);

    for (int to : g[v]) {
        if (to == p) continue;
        t++;
        auto c = dfs(to, v);
        int chcnt = std::get<2>(c);
        cnt += chcnt;
        std::get<0>(c) += chcnt;
        std::get<1>(c) += chcnt;
        lsum += std::get<0>(c);
        rsum += std::get<1>(c);
        if (maxp.second < std::get<1>(c)) {
            maxp.first = std::get<0>(c);
            maxp.second = std::get<1>(c);
        }
    }

    if (t == 1) return std::make_tuple(lsum, rsum, cnt);
    return std::make_tuple(std::max(rsum % 2, maxp.first + maxp.second - rsum), rsum, cnt);
}

int main() {
    constexpr i64 inf = std::numeric_limits<i64>::max();
    int n;
    {
        std::string in;
        std::cin >> n >> in;
        for (auto c : in) s.push_back(c - '0');
    }
    g.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    i64 ret = inf;
    for (int i = 0; i < n; i++) {
        auto r = dfs(i, -1);
        if (std::get<0>(r) == 0) ret = std::min(ret, std::get<1>(r) / 2);
    }

    std::cout << (ret == inf ? -1 : ret) << std::endl;

    return 0;
}

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

int n;
int f[205];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; j += i) f[j]++;
	}
	int cnt = 0;
	for (int i = 1; i <= n; i += 2) cnt += f[i] == 8;
	cout << cnt;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long int ll;

int main(void){
  int n;
  cin>>n;
  int i;
  for(i=1;i<n;i++){
    if(i*(i+1)/2 >= n) break;
  }
  while(i>0){
    if(n-i>=0) {cout<<i<<endl;n-=i;}
    i--;
  }
  return 0;
}


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

using namespace std;

int scanint() 
{ 
	register char c = getchar_unlocked();
	int x = 0;
	for(; (c<48)||(c>57);c = getchar_unlocked());
	for(; (c>47)&&(c<58);c = getchar_unlocked())
		x = (int)((((x)<<1) + ((x)<<3)) + c - 48);
    return x;
} 

int main() {

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

    constexpr int A_MAX = 1000000;

    vector<int> min_factor(A_MAX);
    // q[n] = i where n = i * p^e, p = min_factor[n], p does not divide i. + 1);
    vector<int> q(A_MAX + 1, 1);
    vector<int> primes;
    for (int i = 2; i <= A_MAX; ++i) {
        min_factor[i] = i;
    }
    for (int i = 2; i <= A_MAX; ++i) {
        if (min_factor[i] == i) {
            primes.push_back(i);
        }
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor[i]) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }

    int N = scanint();
    vector<int> a(A_MAX + 1);
    for (int i = 0; i < N; ++i) {
        ++a[scanint()];
    }

    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        if (a[n] > 1) {
            if (a[n] == N) {
                cout << "not coprime" << endl;
                return 0;
            }
            is_pairwise_coprime = false;
        }
        a[min_factor[n]] += a[n];
        a[q[n]] += a[n];
    }
    if (is_pairwise_coprime) {
        cout << "pairwise coprime" << endl;
    } else {
        cout << "setwise coprime" << endl;
    }

    return 0;
}


Measured memory_bytes: 15508
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
    int a,b,h;cin>>a>>b>>h;
    cout<<((a+b)*h)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N;cin >> N;
    int K;cin >> K;
    string S; cin >> S;

    vector<int> Nums;
    int now = 1;//今見ている数
    int cnt = 0;//並んでいる数
    //0と１の並んでいる数をzipする。
    for(int i=0;i<N;i++){
        if(S[i]==(char)('0'+now))cnt++;//('0'+なにかとは文字コード的な何かするため)
        else
        {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt!=0)Nums.push_back(cnt);//残り物をしっかりとpushする。
    if(Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2*K + 1;//かえれる回数

    int ans = 0;
    int left = 0;
    int right = 0;
    int tmp = 0; //[left,right)半開区間
    for(int i= 0;i < Nums.size();i += 2){//1が並んでいるものをみるので偶数番をみる
        int Nextleft = i;
        int Nextright = min(i+Add,(int)Nums.size());//Nextrightがはみ出ないようにする
        /*イメージ図
        ||:=NextleftとNextright
        \\:=leftとright
        最初
        ||①・②・③・④・⑤・⑥・⑦・⑧・⑨・⑩
        一回目のfor文
        |①・②・③・④・⑤|⑥・⑦・⑧・⑨・⑩
        |\①・②・③・④・⑤|⑥・⑦・⑧・⑨・⑩
        rightをうごかして合計値を出す。
        \①・②|③・④・⑤\⑥・⑦|⑧・⑨・⑩
        右にずらすのでleftはNextleftまでの分を引く
        反対にrightはNextrightまでの分を引く
        */
        while (Nextleft > left)
        {
            tmp -= Nums[left];
            left++;
        }
        while (Nextright > right)
        {
            tmp += Nums[right];
            right++;
        }
        //最大値が出ればそれにansを書き換える
        ans = max(tmp,ans);
    }

    cout << ans << endl;
} 

//chokudaiさんのコードを丸コピしました

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
#define grade(a) cout << a << endl
using namespace std;

int main(){
    int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) break;
        if(m==-1 || f==-1 || m+f<30){
            grade("F");
            continue;
        }
        if(m+f>=80)grade("A");
        else if(m+f>=65)grade("B");
        else if(m+f>=50)grade("C");
        else if(m+f>=30){
            if(r>=50)grade("C");
            else grade("D");
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<math.h>
int main()
{
	int  n,x,a,b,s,t;
	scanf("%d%d%d",&x,&a,&b);
	s=abs(x-a);
	t=abs(x-b);
	if(s>t)
	printf("B");
	else if(s<t)
	printf("A");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  string s;
  cin>>s;
  bool ex=true;
  rep(i,s.size()){
    if(i%2==0 && s[i]=='L') ex=false;
    if(i%2==1 && s[i]=='R') ex=false;
  }
  if(ex)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


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

typedef struct {
	char mark;
	char num;  //ここの数字が０のときはカード終端ということで
	char id;
} trumpcard;

trumpcard a[50], b[50];

int getn()
{
	int n = 0;
	char tmp;
	while ( '0' <= (tmp = getchar()))
		n =n * 10 + tmp - '0' ;

	return n;
}

void getcarddata(int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		a[i].mark = getchar();
		a[i].num = getchar();
		a[i].id = i;
		getchar();
	}
	a[i].num = 0;
}

void swapcard(trumpcard *d, int i, int j)
{
	trumpcard tmp;
	tmp = d[i];
	d[i] = d[j];
	d[j] = tmp;
}

void bubble_sort(trumpcard *d, int n)
{
	int i, j;
	for (i = 0; i < n; i++)
		for (j = n-1; i<j; j--)
			if (d[j].num < d[j-1].num)
				swapcard(d, j, j-1);
}

void selection_sort(trumpcard *d, int n)
{
	int i,j, minj;
	for (i = 0; i <n; i++){
		minj = i;
		for (j = i; j < n; j++)
			if (d[j].num < d[minj].num)
				minj = j;
		swapcard(d, i, minj);
	}
}

int check_stable(trumpcard *d, int n)
{
	int flag = -1;
	for (int i =0; i < n-1; i++)
		if ((d[i].num == d[i+1].num && d[i].id > d[i+1].id))
			flag = 0;
	return flag;
}

void print_card(trumpcard *d, int n)
{
	for (int i=0; i<n; i++)
	{
		if(i != 0)
			printf(" ");
		printf("%c%c", d[i].mark, d[i].num);
	}
	printf("\n");
}



int main(void)
{
	int n = getn();
	getcarddata(n);
	memcpy(b, a, sizeof(trumpcard)*n);

	bubble_sort(a, n);
	selection_sort(b,n);

	print_card(a,n);
	printf("%s\n", (check_stable(a, n))?"Stable":"Not stable");
	print_card(b,n);
	printf("%s\n", (check_stable(b, n))?"Stable":"Not stable");


	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}
ll H, W;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool isRange(ll y, ll x){return(0<=y&&y<H&&0<=x&&x<W);}

int main(){
    // ll H, W;
    cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }

    // mout(S);
    ll maxnum=0;

    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            queue<P> q;
            P p;
            vector<vector<ll>> num(20, vector<ll>(20, -1));
            ll maxtmp=0;
            if(S[i][j]=='.'){
                q.push(P(i,j));
                num[i][j]=0;
                while(q.size()){
                    p = q.front();
                    q.pop();
                    for (ll i = 0; i < 4; i++) {
                        ll ny = p.first + dy[i], nx = p.second + dx[i];
                        if(isRange(ny, nx) && S[ny][nx] == '.' && num[ny][nx] == -1) {
                            num[ny][nx] = num[p.first][p.second] + 1;
                            chmax(maxnum, num[ny][nx]);
                            q.push(P(ny,nx));
                        }
                    }
                }
                chmax(maxnum, maxtmp);
            }
        }
    }
    if(maxnum==0){
        cout << 0 << "\n";
    }else{
        cout << maxnum << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll A, ll B, ll C, ll D) {
  cout << max(A * B, C * D) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll C;
	ll A;
	ll D;
	ll B;
	scanf("%lld", &A);
	scanf("%lld", &B);
	scanf("%lld", &C);
	scanf("%lld", &D);
	solve(A, B, C, D);
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){

	/*????????¨??????????????????????±???????????????°?????????????????????????????¨*/

	/*?????°?????£?¨???¨?????????*/

	int n = 0 ;
	int m = 0 ;
	int l = 0 ;			//??????A,B????????°????????°

	int i = 0 ;
	int j = 0 ;
	int k = 0 ;			//???????????°

	/*n,m,l????????±??????*/
	scanf("%d" ,&n);
	scanf("%d" ,&m);
	scanf("%d" ,&l);

	/*??????A, B???????¬????????????¨????????£?¨?*/
	int A[n][m] ;			//A???n???m????????????
	int B[m][l];			//b???m???l????????????
	long int C[n][l];

	/*??????C????????????*/
	for( i = 0 ; i < n ; i++){
		for( j = 0 ; j < l ; j++){
			C[i][j] =0;
//			printf("%ld ",C[i][j]);
		}
//		printf("\n");
	}

	/*??????A???????????????*/
	for( i = 0 ; i < n ; i++){
		for( j = 0 ; j < m ; j++){
			scanf("%d", &A[i][j]);
		}
	}

	/*??????B???????????????*/
	for( i = 0 ; i < m ; i++){
		for( j = 0 ; j < l ; j++){
			scanf("%d", &B[i][j]);
		}
	}

	/*??????C????¨??????¨??????*/
	for(i = 0 ; i < n ; i++){
		for(j = 0 ; j < l ; j++){
			for(k = 0 ; k < m ; k++){
				C[i][j] += A[i][k]*B[k][j] ;
			}

			printf("%ld", C[i][j]);

			if( j != l-1){
				printf(" ");	//????????\?????§??????????????????
			}

		}//???(???)??????????????????????????§

		printf("\n");			//????????§??????????????????

	}//n(???)??????????????????????????§




	return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

int main(){	
	long long N;
	string S;
	scanf("%lld",&N);
	cin >> S;
	
	set<ll> st1, st2, st3;
	rep(i, N) {
		rep(j, 100) {
			if (st2.find(j) != st2.end()) st3.insert(*st2.find(j)*10+(S[i]-'0'));
		}
		rep(j, 10) {
			if (st1.find(j) != st1.end()) st2.insert(*st1.find(j)*10+(S[i]-'0'));
		}
		st1.insert(S[i]-'0');
	}
	ll res = 0;
	rep(j, 1000) {
		if (st3.find(j) != st3.end()) {
			res++;
			// cout << j << endl;
		}
	}
	cout << res << endl;

	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

void output(int i,int j,int d)
{
	cout<<i+1<<' '<<j+1<<' '<<"NESW"[d]<<endl;
}

int main()
{
	int h,w; long long l;
	for(;cin>>h>>w>>l,h|w|l;){
		vector<string> grid(h);
		for(int i=0;i<h;i++) cin>>grid[i];
		
		vector<vector<vector<int>>> vis(h,vector<vector<int>>(w,vector<int>(4,-1)));
		
		queue<tuple<int,int,int,int>> q; // (i,j,dir,time)
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++){
				int d=string("NESW").find(grid[i][j]);
				if(d!=-1){
					q.emplace(i,j,d,0);
					grid[i][j]='.';
				}
			}
		
		while(q.size()){
			auto c=q.front(); q.pop();
			int ci=get<0>(c),cj=get<1>(c),cd=get<2>(c),ct=get<3>(c);
			if(ct==l){
				output(ci,cj,cd);
				break;
			}
			if(vis[ci][cj][cd]!=-1){
				int len=ct-vis[ci][cj][cd];
				for(int i=0;i<h;i++)
					for(int j=0;j<w;j++)
						for(int k=0;k<4;k++)
							if(vis[i][j][k]==(l-vis[ci][cj][cd])%len+vis[ci][cj][cd])
								output(i,j,k);
				break;
			}
			vis[ci][cj][cd]=ct;
			for(int i=0;i<4;i++){
				int nd=(cd+i)%4,ni=ci+"\xff\0\x1\0"[nd],nj=cj+"\0\x1\0\xff"[nd];
				if(0<=ni && ni<h && 0<=nj && nj<w && grid[ni][nj]!='#'){
					q.emplace(ni,nj,nd,ct+1);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 1820
#include <iostream>


using namespace std;
 

void swap(int& x, int& y){
    int tmp = x;
    x=y;
    y=tmp;
}
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
     
    cout << a << " " << b << " "  << c << endl;
}


Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
                  new Main().run();
        }
	int[][] cost;
	boolean[] visit;
	int[] dist;
	int n;
	int def = Integer.MAX_VALUE;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			cost = new int[n][n];
			for(int i = 0;i < n;i++){
				Arrays.fill(cost[i],def);
			}
			for(int i = 0;i < m;i++){
				int a = scan.nextInt() - 1;
				int b = scan.nextInt() - 1;
				cost[a][b] = 1;
				cost[b][a] = 1;
			}
			dist = new int[n];
			visit = new boolean[n];
			Arrays.fill(dist,def);
			dijkstra(0);
			int count = 0;
			for(int i = 1;i < n;i++){
				if(dist[i] <= 2){
					count++;
				}
			}
			System.out.println(count);
		}
	}
	public void dijkstra(int start){
		dist[start] = 0;
		while(true){
			int min = def;
			int next = -1;
			for(int u = 0;u < n;u++){
				if(visit[u]){
					continue;
				}
				dist[u] = (cost[start][u] == def)?dist[u]:Math.min(dist[u],dist[start]+cost[start][u]);
				if(dist[u] < min){
					min = dist[u];
					next = u;
				}
			}
			visit[start] = true;
			start = next;
			if(start == -1){
				break;
			}
		}
	}
}

Measured memory_bytes: 46560