akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<55)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli sum[100100];

int main(){

    lli n,m;
    cin>>n>>m;

    lli target = (n*n)-m;

    vector<lli> a(n);
    REP(i,0,n)cin>>a[i];

    sort(a.begin(),a.end());

    lli small = a[0],large = 1e18;

    while(small+1<large){
        lli middle = (small+large)/2;

        lli sum=0;
        REP(i,0,n){
            lli num = middle-a[i];

            lli cnt = (lli)(lower_bound(a.begin(),a.end(),num)-a.begin());
            sum += cnt;
        }

        if(sum > target)large = middle;
        else small = middle;
    }

    lli ans = 0;
    REP(i,0,n)sum[i+1] = sum[i]+a[i];

    if(DEBUG)cout<<"small="<<small<<endl;

    //vector<lli> tes;
    //REP(i,0,n)REP(j,0,n)tes.push_back(a[i]+a[j]);
    //sort(tes.rbegin(),tes.rend());
    //REP(i,0,tes.size())cout<<tes[i]<<endl;

    lli diffCnt=0;
    REP(i,0,n){
        lli num = small-a[i];
        lli cnt = (lli)(lower_bound(a.begin(),a.end(),num)-a.begin());
        if(DEBUG)cout<<"i="<<i<<"num="<<num<<"cnt="<<cnt<<endl;
        ans += (a[i]*(n-cnt))+(sum[n]-sum[cnt]);
        diffCnt += cnt;
    }
    if(DEBUG)cout<<diffCnt<<" "<<target<<endl;
    lli diffSum = diffCnt-target;
    ans += diffSum*small;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1792
# EduDPA - Frog 1
n = int(input())
lst = list(map(int, input().rstrip().split()))
a, b = 0, abs(lst[0] - lst[1])
for i in range(2, n):
    dif_1 = a + abs(lst[i] - lst[i - 2])
    dif_2 = b + abs(lst[i] - lst[i - 1])
    a, b = b, min(dif_1, dif_2)
print(b)

Measured memory_bytes: 13928
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 505

ll N,K;
ll A[SIZE],work[SIZE];
set<ll> SET;

int main(){

	scanf("%lld %lld",&N,&K);

	ll sum = 0;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&A[i]);
		sum += A[i];
	}

	for(ll i = 1; i*i <= sum; i++){
		if(sum%i == 0){
			SET.insert(i);
			SET.insert(sum/i);
		}
	}

	ll ans = 1;

	for(ll x: SET){

		for(ll i = 0; i < N; i++){

			work[i] = A[i]%x;
		}
		sort(work,work+N);

		ll plus = 0;

		for(ll i = 0; i < N; i++){

			plus += x-work[i];
		}

		ll need = plus;
		ll minus = 0;

		for(ll i = 0; i < N; i++){
			minus += work[i];
			plus -= (x-work[i]);
			need = min(need,max(minus,plus));
		}
		if(need <= K){

			ans = max(ans,x);
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n-1),b(n-1);
    vector<vector<int>> G(n);
    rep(i,n-1){
        int A,B;
        cin>>A>>B;
        A--;
        B--;
        a[i]=A;
        b[i]=B;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    map<pair<int,int>,int> m;
    vector<bool> visit(n,false);
    vector<int> col(n,0);
    queue<int> que;
    que.push(a[0]);
    visit[a[0]]=true;

    int k=0;
    while(!que.empty()){
        int v = que.front();
        que.pop();
        int c = 1;
        for(int u : G[v]){
            if(visit[u]) continue;
            if(c==col[v]) c++;
            col[u]=c;
            m[make_pair(u,v)]=c;
            m[make_pair(v,u)]=c;
            c++;
            visit[u] = true;
            que.push(u);
        }
        k=max(k,c-1);
    }
    cout<<k<<endl;
    rep(i,n-1){
        cout<<m[make_pair(a[i],b[i])]<<endl;
    }

}

Measured memory_bytes: 19712
#Buffet

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = sum(B)
for i in range(N-1):
    if A[i+1] - 1 == A[i]:
        sum += C[A[i]-1]
        
print (sum)

"""
for i in range(N):
    sum += B[A[i]-1]
    if i > 0 and A[i] == 1 + A[i-1]:
        sum += C[A[i-1]-1]
"""


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lambda(res,...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define method(name,res,...) function<res(__VA_ARGS__)> name = (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define foreach(i,n) for(auto &i:(n))

using namespace std;
using ll = long long;


vector<ll> func(ll x,ll y,ll z,int n){
	vector<ll> line({x,y,z});
	sort(line.begin(),line.end());
	x = line[0];
	y = line[1];
	z = line[2];
	vector<ll> res(n,0);
	method(mul,ll,ll x){
		return x * (x+1) / 2;
	};

	ll sq = x * y;

	for(int i=0;i<x+y+z-2;++i){
		ll &it = res[i%n];
		it += sq;
		ll dis = max(0ll,i-z+1);
		it -= mul(dis);
		if(dis>x){
			it += mul(dis-x);
		}
		if(dis>y){
			it += mul(dis-y);
		}
		ll below = max(0ll,x+y-i-2);
		it -= below * (below + 1) / 2;
		if(below>x){
			it += mul(below-x);
		}
		if(below>y){
			it += mul(below-y);
		}
	}
	return res;
}

vector<ll> operator+(vector<ll> a,vector<ll> b){
	for(int i=0;i<a.size();++i){
		a[i] += b[i];
	}
	return a;
}


vector<ll> operator-(vector<ll> a,vector<ll> b){
	for(int i=0;i<a.size();++i){
		a[i] -= b[i];
	}
	return a;
}

vector<ll> operator*(vector<ll> a,ll k){
	foreach(i,a){
		i = i * k;
	}
	return a;
}

int main(){
	vector<ll> cube(3);
	vector<ll> origins(3);
	int n;
	foreach(i,cube)cin>>i;
	foreach(i,origins)cin>>i;
	cin >> n;
	vector<vector<ll>> lines(3);
	for(int i=0;i<3;++i){
		lines[i].emplace_back(1);
		lines[i].emplace_back(origins[i]+1);
		lines[i].emplace_back(cube[i]-origins[i]);
	}
	vector<ll> ans(n,0);
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				int sign = (lambda(int,vector<int> line){
						int res = 1;
						foreach(i,line){
						if(i==0)res = -res;
						}
						return res;
						})({i,j,k});
				ans = ans + func(lines[0][i],lines[1][j],lines[2][k],n) * sign;
			}
		}
	}
	{
		bool flag = false;
		foreach(i,ans){
			if(flag)cout << " ";
			cout << i;
			flag = true;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

const long long INF = 1LL << 60;

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

int main() {
    int N;
    ll v[100005][3];
    ll dp[100005][3];
    cin >> N;
    rep(i, N) {
        rep(j,3) {
            cin >> v[i][j];
        }
    }

    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];

    repp(i,1,N){
        rep(j,3){
            dp[i][j] = max(dp[i-1][(j+1)%3] + v[i][j], dp[i-1][(j+2)%3] + v[i][j]);
        }
        // dp[i][0] = max(dp[i-1][1] + v[i][0], dp[i-1][2] + v[i][0]);
        // dp[i][1] = max(dp[i-1][0] + v[i][1], dp[i-1][2] + v[i][1]);
        // dp[i][2] = max(dp[i-1][0] + v[i][2], dp[i-1][1] + v[i][2]);
    }

    ll res = max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]);
    cout << res << endl;
}


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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;


int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int tmp = b;
	int cnt = 0;
	while (tmp > 0) {
		cnt++;
		tmp /= 10;
	}
	REP(i, cnt) {
		a *= 10;
	}
	int num = a + b;
	if (num == (int)sqrt(num)*(int)sqrt(num)) {
		PRINTS("Yes");
	}
	else {
		PRINTS("No");
	}
}

Measured memory_bytes: 128
n = int(input())
s = [input() for i in range(n)]

r = s.count('AC')
y = s.count('WA')
z = s.count('TLE')
w = s.count('RE')

print('AC x ' + str(r))
print('WA x ' + str(y))
print('TLE x ' + str(z))
print('RE x ' + str(w))


Measured memory_bytes: 16280
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue<long long int> 
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;


int main()
{
    flash;
    ll T=1,n,q,k,i,j;
    cin>>k>>i>>j;
    q = i/k;
    int fl=0;
    for(n=q;n*k<=j;n++)
    {
        if((n*k<=j)&&(n*k>=i))
            fl=1;
    }
    if(fl)  cout<<"OK\n";
    else    cout<<"NG\n";
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, x: "List[int]"):
    return sum(min(xx, abs(xx-K)) for xx in x) * 2


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9104
s=input()
s_1="1"
s_0="0"
count_1=0
count_0=0

if len(s)%2:
  s_0+="10"*(len(s)//2)
  s_1+="01"*(len(s)//2)
else:
  s_0+="10"*(int(len(s)/2+1))
  s_1+="01"*(int(len(s)/2+1))

for i in range(len(s)):
  if s[i]==s_1[i]:
    count_1+=1
  if s[i]==s_0[i]:
    count_0+=1
print(min(len(s)-count_1,len(s)-count_0))

Measured memory_bytes: 3444
#include <stdio.h>
int main() {
    int n,a,max = 0;
    scanf("%d",&n);
    int x[100003];
    for(int i = 0;i < 100003;i++) x[i] = 0;
    for(int i = 0;i < n;i++) {
        scanf("%d",&a);
        x[a]++;
        x[a+1]++;
        x[a+2]++;
    }
    for(int i = 0;i < 100003;i++) if(x[i] > max) max = x[i];
    printf("%d",max);
    return 0;
}


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

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

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

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    vector< vector<P> > t( N );
    REP( i, N ){
        int M; cin >> M;
        REP( j, M ){
            int x, y; cin >> x >> y;
            x--;
            t[i].emplace_back( x, y );
        }
    }

    int ans = 0;
    for( int bit = 0; bit < ( 1 << N ); bit++ ){
        bool f = true;
        int tmp = 0;
        REP( i, N ){
            if( bit & ( 1 << i ) ){
                tmp++;
                REP( j, t[i].size() ){
                    if( ( bit & ( 1 << t[i][j].first ) ) == 0 && t[i][j].second == 1 ){
                        f = false;
                    }else if( bit & ( 1 << t[i][j].first ) && t[i][j].second == 0 ){
                        f = false;
                    }
                }
                if( !f ) break;
            }
        }

        if( f ){
            chmax( ans, tmp );
        }
    }

    cout << ans << endl;
}

/*

*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

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

    int N;
    cin >> N;
    vector<P> data;
    for(int i = 0; i < N; ++i){
        int A;
        cin >> A;
        data.emplace_back(A, i);
    }
    sort(data.rbegin(), data.rend());
    constexpr ll inf = 1e+15;
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -inf));
    dp[0][0] = 0;
    for(int i = 0; i < N; ++i){
        int A = data[i].first, prev_pos = data[i].second;
        for(int j = 0; j <= i; ++j){
            chmax(dp[i + 1][j + 1], dp[i][j] + (ll)A * abs(prev_pos - j));
            chmax(dp[i + 1][j], dp[i][j] + (ll)A * abs(N - (i - j) - 1 - prev_pos));
        }
    }
    ll ans = 0;
    for(int i = 0; i <= N; ++i) chmax(ans, dp[N][i]);
    cout << ans << endl;
}

Measured memory_bytes: 34576
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
#define mod 1000000007
signed main() {

	int H, W, K;
	cin >> H >> W >> K;
	K--;
	int dp[101][8] = { 0 };
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < 1 << (W - 1); j++) {
			bool F = true;
			for (int k = 0; k < W - 2; k++)
				if ((j >> k) % 4 == 3)F = false;
			if (!F)continue;

			vector<int> P(W);
			for (int a = 0; a < W; a++) P[a] = a;
			for (int a = 0; a < W - 1; a++)
				if ((j >> a) & 1)swap(P[a], P[a + 1]);
			for (int a = 0; a < W; a++) {
				dp[i + 1][P[a]] += dp[i][a];
				dp[i + 1][P[a]] %= mod;
			}
		}
	}

	cout << dp[H][K] << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = [int(e) for e in input().split()]
b_list = [int(e) for e in input().split()]
c_list = [int(e) for e in input().split()]

satisfuction = 0
for i, a in enumerate(a_list):
  satisfuction += b_list[a-1]
  if (i >= 1) & (a - a_list[i-1] == 1):
    satisfuction += c_list[a_list[i-1]-1]
print(satisfuction)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

void CountingSort(short unsigned int*,short unsigned int*,int);

int n,C[VMAX+1];

int main(){
  unsigned short *A, *B;;
  int i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
  
  CountingSort(A,B,VMAX);



  return 0;
}

void CountingSort(short unsigned int *A,short unsigned int *B,int k){
  int i,j;
  
  for (i=0;i<=k;i++)
    C[i] = 0;
    for (j=1;j<=n;j++){
      C[A[j]]++;
    }
      for (i=1;i<=k;i++) C[i] = C[i] + C[i-1];
	for (j=1;j<=n;j++){
	  B[C[A[j]]] = A[j];
	  C[A[j]]--;
	}
      for (i=1;i<n;i++) printf("%d ",B[i]);
      printf("%d\n",B[n]);
}




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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;


int main() {
int N;
int A[17],X[17][17],Y[17][17];
cin>>N;
rep3(i,N){
    cin>>A[i];
    rep3(j,A[i]){
        cin>>X[i][j]>>Y[i][j];
    }
}
ll max_honest =-INF;
bool judge;
rep(i,1<<N){
    judge=true;
    rep3(j,N){
        if((i>>(j-1))&1){
            rep3(k,A[j]){
                if((Y[j][k]==1)&&((i>>(X[j][k]-1)&1)==0)){
                    judge=false;
                }
                else if((Y[j][k]==0)&&(i>>(X[j][k]-1)&1)){
                    judge=false;
                }
            }
        }
        

    }
    if(judge){
        if(max_honest<__builtin_popcount(i)){
        max_honest=__builtin_popcount(i);
    }
    }


}
cout<<max_honest<<endl;
return 0;
}



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

int main(){
	int n, K;
	cin >> n >> K;
	vector<ll>x(n), y(n);
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> y[i];
	}

	ll ans = 4e18;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			for (int k = 0;k < n;k++) {
				for (int l = 0;l < n;l++) {
					ll minx = min(min(x[i], x[j]), min(x[k], x[l]));
					ll maxx = max(max(x[i], x[j]), max(x[k], x[l]));
					ll miny = min(min(y[i], y[j]), min(y[k], y[l]));
					ll maxy = max(max(y[i], y[j]), max(y[k], y[l]));
					int count = 0;
					for (int m = 0;m < n;m++) {
						if (x[m] >= minx && x[m] <= maxx && y[m] >= miny && y[m] <= maxy) {
							count++;
						}
					}
					if (count >= K) {
						ans = min(ans, (maxx - minx)*(maxy - miny));
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	string A, B;
	cin >> A >> B;
	map<string, int> val;
	cin >> val[A] >> val[B];
	string tmp;
	cin >> tmp;
	--val[tmp];
	cout << val[A] << ' ' << val[B] << '\n';
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = (1..N).filter(|&i| N - i != i).count() / 2;

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


Measured memory_bytes: 4352
/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` / _/
          `-.____`.___ \_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const long double DEL = 1e-12;
const int mod =  1000000007;
const int LIM = 100005;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define Rev(v) reverse(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define mem(a,b) memset(a,b,sizeof(a))
#define umii unordered_map<int,int>
#define all(a) a.begin() , a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout<<"\nhi\n"
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define nl cout<<"\n"
#define pb push_back
#define int long long
#define sp <<" "<<
#define ss second
#define ff first
 
int fpow(int x, int n)
{
    int res = 1;
    while(n){
          if(n&1){
                res = res * x % mod;
          }
          x = x * x % mod;
          n>>=1;
    }
    return res;
}
int gcd(int a,int b)
{
    if(b == 0)
    {
          return a;
    }
    return gcd(b,a % b);
}
void sieve(int n)
{
      bool prime[5*LIM];
      memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);
      for (int p = 2; p <= rootn; p++)
      {
            if (prime[p] == true)
            {
                  for (int i = p*p; i <= n; i += p)
                  {
                        prime[i] = false;
                  }
            }
      }
      prime[1] = 0;
}
int cnt, sum, mid, mx, mn, ans, a[2*LIM];
int n, m, d, p, q, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;

//******************************************* CHECK CONSTRAINTS **************************************************


int32_t main()
{     fio;
      cin>>n;
      if(n>=30)
      {
            cout<<"Yes";
      }
      else
      {
            cout<<"No";
      }
     
}


Measured memory_bytes: 3688
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[3],b[3],A,B;
	A = 0;
	B = 0;

	for (int i = 0; i < 4; i++)
	{
		cin >> a[i];
		A += a[i];
	}

	for (int i = 0; i < 4; i++)
	{
		cin >> b[i];
		B += b[i];
	}

	if (A <= B)
	{
		cout << B  << endl;
	}
	else if (A > B)
	{
		cout << A << endl;
	}
}

Measured memory_bytes: 3092
N,M = map(int, input().split())
C = list(map(int, input().split()))

C.sort()
DP = [i for i in range(N+1)]

for m in range(1,M):
    coin = C[m]
    for total in range(1, N+1):
        if total - coin >= 0:
            DP[total] = min(DP[total], DP[total - coin] + 1)

print(DP[-1])


Measured memory_bytes: 7636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int x=n%10;
		if(x==2 || x==4 || x==5 || x==7 || x==9) System.out.println("hon");
		else if(x==0 || x==1 ||x==6|| x==8)System.out.println("pon");
		else System.out.println("bon");
		
	}

}

Measured memory_bytes: 35520
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
struct state{
	int table[8][8];
};

int h,w,c;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int change(state tmp,int num,int col){
	int cmax=0;
	if(num==5){
		if(col==c){
			queue<P> q;
			int count=0;
			P cur;
			cur.first=0,cur.second=0;
			q.push(cur);
			while(!q.empty()){
				cur=q.front();q.pop();
				if(tmp.table[cur.first][cur.second]==0)
					continue;
				tmp.table[cur.first][cur.second]=0;
				count++;
				for(int i=0;i<4;i++){
					int cx=cur.first+dx[i],cy=cur.second+dy[i];
					if(0<=cx&&cx<w&&0<=cy&&cy<h&&tmp.table[cx][cy]==c)
						q.push(make_pair(cx,cy));
				}
			}
			return count;
		}else
			return 0;
	}

	for(int i=1;i<=6;i++){
		state next;
		next=tmp;
		if(i==col)
			continue;
		queue<P> q;
		P cur;
		cur.first=0,cur.second=0;
		q.push(cur);
		while(!q.empty()){
			cur=q.front();q.pop();
			next.table[cur.first][cur.second]=i;
			for(int j=0;j<4;j++){
				int cx=cur.first+dx[j],cy=cur.second+dy[j];
				if(0<=cx&&cx<w&&0<=cy&&cy<h&&next.table[cx][cy]==col)
					q.push(make_pair(cx,cy));
			}
		}
		cmax=max(cmax,change(next,num+1,i));
	}

	return cmax;
}

int main(void){
	state init;
	while(cin >> h >> w >> c,h|w|c){
		for(int y=0;y<h;y++)
			for(int x=0;x<w;x++)
				cin >> init.table[x][y];
		int ans=change(init,0,init.table[0][0]);
		cout << ans  << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      if(s.length() % 2 == 0) {
        System.out.println("No");
        return;
      }

      if(isPalindrom(s) && isPalindrom(s.substring(0, s.length() / 2)) && isPalindrom(s.substring(s.length() / 2 + 1)))
        System.out.println("Yes");
      else
        System.out.println("No");
  }

  private static boolean isPalindrom(String s) {
    int left = 0; 
    int right = s.length() - 1;
    while(left < right) {
      if(s.charAt(left) != s.charAt(right))
        return false;
      left++;
      right--;
    }
    return true;
  }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
vector <int> v[100005];
int dp[100005];

int dfs( int from )
{
	if( v[from].size() == 0 )return 0;
	
	if( dp[from] != -1 )return dp[from];
	
	int res = 0;
	
	for(int i = 0; i < (int)v[from].size(); i++)
	{
		res = max( res , dfs(v[from][i]) + 1 );
	}
	
	return dp[from] = res;
}



main()
{
	int n , m;
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)dp[i] = -1;
	
	for(int i = 1; i <= m; i++)
	{
		int a , b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans = max(ans , dfs(i));
	}
	
	cout << ans << endl;

}


Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll n, a[10]={}, b;

int main()
{
    for(int i=0; i<10; i++){
        cin>>a[i];
    }
    sort(a,a+10);
    reverse(a,a+10);
    for(int i=0; i<3; i++){
        cout<<a[i]<<endl;
    }
    
}

Measured memory_bytes: 3016
N = int(input())
L = list(map(int,input().split()))

L.sort()

K = [0] * (4 * (10 ** 3)+1)

K[L[0]+L[1]] = 1

count = 0

for i in range(2,N):
    count += sum(K[L[i]+1:])
    for j in range(i):
        K[L[j]+L[i]] += 1

print(count)

Measured memory_bytes: 3188
/**
*   @Author : MeGA
*   @InitTime :02/08/20 16:03:05
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     int n,a,b;
     cin>>n>>a>>b;
     cout<<min(b,n*a)<<endl;
}

Measured memory_bytes: 256
s=input()
l=[]
sm=0
arr=["0","1","2","3","4","5","6","7","8","9"]
for i in range(0,10):
  l.append(s.count(arr[i]))
for i in range(0,10):
    a=int(l[i])
    sm=sm+(a*i)
if sm%9==0:
  print("Yes")
else:
  print("No")

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


int main()
{
	int m, n, sum;
	cin >> m >> n;
	
	int mat[100][100], vec[100];

	for (int i = 0;i < m;i++) {
		for (int j = 0;j < n;j++) {
			cin >> mat[i][j];
		}
	}

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

	for (int i = 0;i < m;i++) {
		sum = 0;
		for (int j = 0;j < n;j++) {
			sum += mat[i][j] * vec[j];
		}

		cout << sum << endl;
	}

	return 0;
}



Measured memory_bytes: 3128
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
from operator import mul
from functools import reduce
def cmb1(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A_c=Counter(A)

    combi=0
    for ac in A_c.items():
        if ac[1]>=2:
            combi+=cmb1(ac[1],2)
    for i in range(n):
        print(combi-(A_c[A[i]]-1))

if __name__=='__main__':
    main()

Measured memory_bytes: 89564
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <cmath>
//#define _0219nice 
using namespace std;

long long comb(int n, int m) {
    if (m > n) {
        return 0;
    }
    long long ret = 1;
    for (int i = 0; i < m; i++) {
        ret *= n - i;
    }
    for (int i = 0; i < m; i++) {
        ret /= i + 1;
    }
    return ret;
}
int main() {
#ifdef _0219nice
    freopen("1.in", "r", stdin);
#endif
    int n, a[200005];
    while (cin >> n) {
        unordered_map<int, int> mp;
        long long tot = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            mp[a[i]]++;

        }
        for (auto p: mp) {
            tot += comb(p.second, 2);
        }
        for (int i = 0; i < n; i++) {
            cout << tot - mp[a[i]] + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8520
import math

def isprime(x):
    if x == 2:
        return 1

    if x < 2 or x % 2 == 0 :
        return 0

    i = 3
    while i <= math.sqrt(x) :
        if x % i == 0 :
            return 0
        i += 2
    else :
        return 1
        
ans=0
N=int(input())
for k in range(N):
    x=int(input())
    ans = ans + isprime(x)
print(ans)


Measured memory_bytes: 5676
#include <stdio.h>
#include <string.h>
#include <ctype.h>

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

void affine_decode(char* s, int* dec)
{
    int i;

    for (i = 0; s[i]; ++i){
        if (!isalpha(s[i])) continue;
        s[i] = dec[s[i] - 'a'] + 'a';
    }
}

int is_correct(char* s)
{
    int i;

    for (i = 0; s[i]; ++i){
        if (!strncmp(&s[i], "this", 4) || !strncmp(s + i, "that", 4)){
            return 1;
        }
    }
    return 0;
}

int main(void)
{
    int n;
    int i, j, k;

    scanf("%d\n", &n);
    while (n--){
        char s[512];
        int cnt = 0;
        int len;

        fgets(s, 258, stdin);
        len = strlen(s);
        if (s[len - 1] == 10) s[len - 1] = 0;
        for (i = 1; cnt < 26; ++i){
            if (gcd(i, 26) != 1) continue;
            ++cnt;
            for (j = 0; j < 26; ++j){
                char tmp[512];
                int enc[26];
                int dec[26];

                for (k = 0; k < 26; ++k) enc[k] = (k * i + j) % 26;
                for (k = 0; k < 26; ++k) dec[enc[k]] = k;
                strcpy(tmp, s);
                affine_decode(tmp, dec);
                if (is_correct(tmp)){
                    puts(tmp);
                    cnt = 26;
                    j = 26;
                    break;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    cin>>s;
    int j=0;
    char c=97;
    string A;
    sort(s.begin(), s.end());
    while(c>=97 && c<=122){
        bool yes=binary_search(s.begin(), s.end(),c);
        if(yes){c++;continue;}
        else if(c<=122){A.push_back(c);j++;}
        c++;
    }
    //for(auto x:A)cout<<x <<" ";
    int m=A.length();
    if(m==0){
        cout<<"None" <<"\n";
    }
    else {cout<<A[0] <<"\n";}
}




Measured memory_bytes: 3744
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, countAlice, countBob int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	// sort.Slice(a, func(i, j int) bool { return a[i] > a[j] }) 
	sort.Sort(sort.Reverse(sort.IntSlice(a))) // Go version < 1.8

	for i := 0; i < n; i++ {
		if i%2 == 0 {
			countAlice += a[i]
		} else {
			countBob += a[i]
		}
	}
	fmt.Println(countAlice - countBob)
}


Measured memory_bytes: 512
N = int(input())
L = []
for i in range(N):
  L.append(int(input()))
TF = [False]*(N+1)
dp = [0]*(N+1)
for i in range(N):
  TF[L[i]] = True
  if TF[L[i]-1] == True:
    dp[L[i]] = dp[L[i]-1]+1
print(N-max(dp)-1)

Measured memory_bytes: 60376
main :: IO ()
main = do
  [d, n] <- map read . words <$> getLine
  print $ solve d n

solve :: Int -> Int -> Int
solve d n = head $ drop (n-1) $ filter (\i -> divCnt i == d) [1..]
  where
    divCnt i
      | r == 0 = 1 + divCnt q
      | otherwise = 0
      where (q, r) = i `divMod` 100

Measured memory_bytes: 508
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 19:48:52 +0900
# LastModified: 2020-06-26 20:06:44 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, t = map(int, input().split())
    time = list(map(int, input().split()))
    total = 0
    for i in range(0,n-1):
        cur = time[i]
        nex = time[i+1]
        if cur+t+1<=nex:
            total += t
        else:
            total += nex-cur
#        print(total)
    print(total+t)


if __name__ == "__main__":
    main()


Measured memory_bytes: 30824
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
//const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

//below here

int main(){
	int n;
	cin >> n;
	vector<complex<double>> town;
	rep(i,n){
		int x,y;
		cin >> x >> y;
		town.emplace_back(x,y);
	}
	vector<int> order;
	rep(i,n){
		order.push_back(i);
	}
	double ans = 0;
	int time = 0;
	do{
		double sum = 0;
		rep(i,n-1){
			sum += abs(town[order[i+1]]-town[order[i]]);
		}
		ans += sum;
		++time;
	}while(next_permutation(all(order)));
	printf("%.10lf\n",ans / time);
	return 0;
}


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

using namespace std;

#define LL long long
#define N 300000
#define lowbit(x) ((x)&(-(x)))

LL n,m,x,ans,xb,cnt[N],son[N][2];
bool vis[N];
char s[N];

int main(){
    scanf("%lld%lld",&n,&m);
    vis[1]=1; son[1][0]=2; son[1][1]=3; xb=3;
    for (int i=1;i<=n;i++){
        scanf("%s",s+1); int l=strlen(s+1);
        x=1;
        for (int i=1;i<=l;i++){
            x=son[x][s[i]-'0'];
            if (!vis[x]){
                vis[x]=1; cnt[i-1]--;
                son[x][0]=++xb; son[x][1]=++xb;
                cnt[i]+=2;
            }
        }
    }
    for (int i=0;i<=m && i<=100000;i++) ans^=cnt[i]&1?lowbit(m-i):0;
    puts(ans?"Alice":"Bob");

    return 0;
}


Measured memory_bytes: 6144
object Main{
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n,k = sc.nextInt
    val ans = for(i <- 0 to n) yield{
      var x = 1
      for(j <- 1 to i){
        x *= 2
      }
      for(j <- 1 to (n-i)){
        x += k
      }
      x
    }
    println(ans.min)
  }

  def max(a:Int,b:Int):Int = if(a>b) a else b
  def min(a:Int,b:Int):Int = if(a>b) b else a
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<ll> s(201);
    for(int i = -100; i < 101; i++) {
        ll sum=0;
        for(int j = 0; j < n; j++) {
            sum += (a[j]-i)*(a[j]-i);
        }
        s[i+100]=sum;
    }
    sort(s.begin(),s.end());
    cout << s[0] << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



int main(void) {
    int L,R,d;
    int res=0;
    std::cin >> L >> R >> d;

    for(int i=L;i<=R;i++){
        if(i%d==0) res++;
    }

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void){
	char train[53];/*0 1 2 3 ... 25 26 27 ...49 50 51 52*/
	char str[1025];
	int n,i,j;
	int current;
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		for(j = 0; j < 53; j++){
			train[j] = '#';
		}
		current = 26;
		scanf("%s",str);
		for(j = 0; str[j] != 0; j++){
			if(str[j] == '-'){continue;}
			if('a' <= str[j] && str[j] <= 'z'){
				train[current] = str[j];
			}else if(str[j] == '<'){
				current--;
			}else if(str[j] == '>'){
				current++;
			}
		}
		for(j = 0; j < 53; j++){
			if(train[j] == '#'){continue;}
			putchar(train[j]);
		}
		putchar('\n');
	}
	

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;

const int INF = 1<<30;

struct Node{
  int use,to,weight;
  Node() {;}
  Node(int use,int to,int weight) : use(use), to(to), weight(weight) {;}
};
bool operator<(const Node &e,const Node &f) {
  return e.weight > f.weight;
}

int dist[110][110];
bool visited[110][110];
int cost[110][110];

int main() {
  int c,n,m,s,d,a,b,f;
    while(cin>>c>>n>>m>>s>>d, c|n|m|s|d) {
      s--,d--;

      for(int i=0; i<110; ++i) {
	for(int j=0; j<110; ++j) {
	  dist[i][j] = INF;
	  cost[i][j] = INF;
	  visited[i][j] = false;
	}
      }

      for(int i=0; i<m; ++i) {
	cin>>a>>b>>f;
	a--,b--;
	cost[a][b] = f;
	cost[b][a] = f;
      }

      priority_queue<Node> Q;
      Q.push(Node(0,s,0));
      while(!Q.empty()) {
	Node now = Q.top(); Q.pop();
	if(visited[now.use][now.to]) continue;
	visited[now.use][now.to] = true;

	if(now.to == d) {
	  cout<<now.weight<<endl;
	  break;
	}

	int from = now.to;
	for(int to=0; to<n; ++to) {
	  if(cost[from][to] == INF) continue;
	  int nuse = now.use;
	  if(nuse < c && !visited[nuse+1][to]) {
	    int newcost = now.weight + cost[from][to]/2;
	    if(newcost < dist[nuse+1][to]) {
	      dist[nuse+1][to] = newcost;
	      Q.push(Node(nuse+1, to, newcost));
	    }
	  }
	  if(!visited[nuse][to]) {
	    int newcost = now.weight + cost[from][to];
	    if(newcost < dist[nuse][to]) {
	      dist[nuse][to] = newcost;
	      Q.push(Node(nuse, to, newcost));
	    }
	  }
	}
      }
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int vector_finder(std::vector<int> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m),v(n,-1);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	v[0] = 1;
	v[1] = 2;
	if (vector_finder(a, 1)) {
		v[0] = 0;
		v[1] = 1;
	}
	if (vector_finder(a, 2))v[1] = 0;
	for (int i = 0; i < m; i++) {
		v[a[i]-1] = 0;
	}
	for (int i = 2; i < n; i++) {
		if(v[i]) v[i] = (v[i - 1] + v[i - 2]) % 1000000007;
	}
	cout << v[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();

		int disX = tx-sx;//distaneX
		int disY = ty-sy;//distanceY
		for(int i=0;i<disY;i++) System.out.print("U");
		for(int i=0;i<disX;i++) System.out.print("R");
		for(int i=0;i<disY;i++) System.out.print("D");
		for(int i=0;i<=disX;i++) System.out.print("L");
		for(int i=0;i<=disY;i++) System.out.print("U");
		for(int i=0;i<=disX;i++) System.out.print("R");
		System.out.print("DR");
		for(int i=0;i<=disY;i++) System.out.print("D");
		for(int i=0;i<=disX;i++) System.out.print("L");
		System.out.println("U");

	}
}

Measured memory_bytes: 27148
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string n;
  int s = 0;
  cin >> n;
  rep(i, n.size()) s = s + (n[i] - '0');
  cout << ((stoi(n) % s == 0) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
function bomb(x){
   var s="";
   var xLength=x.length;
   for(var i=0;i<xLength;i++)s+=x[i];
   var L=0;
   while(L!=s.length){
      L=s.length;
      s=s.replace(/1111+|2222+|3333+/,"");
   }
   if(min>s.length)min=s.length;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var N=Arr.shift()-0;
   if(N==0)break;
   var arr=[];
   for(var i=0;i<N;i++){
      var v=Arr.shift()-0;
      arr.push(v);
   }
   var min=Infinity;
   for(var i=0;i<N;i++){
      var memo=arr[i];
      if(i<N-1){
         arr[i]=arr[i+1];
         bomb(arr);
      }
      if(i>0){
         arr[i]=arr[i-1];
         bomb(arr);
      }
      arr[i]=memo;
   }
   console.log(min);
}

Measured memory_bytes: 44176
public class Main {
    public static void main(String[] srgs) {

        // ??????????????????????????????.
        // ???????????????????????´??° (?????????????´???°, ?????????????´?) ???????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = sc.nextInt();
        int array[] = new int[n];
        for (int i = 0; i < n; i ++) { array[i] = sc.nextInt(); }

        // ?????????????´????????´?????????????????????¨?????????.
        for (int i = n - 1; i >= 0; i --) {
            if (i != 0) { System.out.print(array[i] + " "); }
            else { System.out.print(array[i]); }
        }
        System.out.print("\n");
    }
}

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

int main(){
    int A,B,C;
    long X,Y;
    long long int ans = 0;

    cin >> A >> B >> C >> X >> Y;
    if(A+B <= 2*C){
        ans = A * X + B * Y;
    }
    else{
        if(X >= Y){
            ans = min(2*C*Y + A*(X-Y), 2*C*X);
        }
        else{
            ans = min(2*C*X + B*(Y-X), 2*C*Y);
        }
    }

    cout << ans << endl;

    return 0;
}

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

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

	int ans = 0;
	for (int i = 1; i < n-1 ; i++) {		
		
		if (p[i - 1] < p[i] && p[i] < p[i + 1])  ans++;
		if (p[i + 1] < p[i] && p[i] < p[i - 1])  ans++;

	}

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

Measured memory_bytes: 256
#include<cstdio>

#define Fast register
inline char Getchar(){
	static char BUF[16384],*S=BUF,*T=BUF;
	return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++;
}
inline int Getint(){
	Fast int s=0;Fast char c;
	while(c=Getchar(),c<48||c>57);
	while(s=s*10+c-48,c=Getchar(),c>47&&c<58);
	return s;
}

int main(){return(puts((Getint()%500<=Getint())?"Yes":"No"),0);}

Measured memory_bytes: 128
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: u64 = iter.parse();
    let mut v: Vec<(u64, u64)> = (0..n).map(|_| (iter.parse(), iter.parse())).collect();
    v.sort_by(|a, b| a.1.cmp(&b.1));
    let mut total = 0;
    for (a, b) in v {
        total += a;
        if total > b {
            println!("No");
            return;
        }
    }

    println!("Yes");
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  int a = 0;
  for (int i = 0; i + 1 < N; ++i) if (S[i] != S[i+1]) ++a;
  cout << N - 1 - max(a - K*2, 0) << endl;
}

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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
mod = K * 2
XY = []
MAX = K * 4
acc = list2d(MAX+1, MAX+1, 0)
for i in range(N):
    x, y, c = input().split()
    x = int(x)
    y = int(y)
    x %= mod
    y %= mod
    if c == 'B':
        x += K
    for a1 in range(3):
        for a2 in range(3):
            for b in [0, K]:
                if c == 'B':
                    b = -b
                x1 = x + a1 * mod + b
                y1 = y + a2 * mod + b
                x2 = x1 + K
                y2 = y1 + K
                x1 = max(min(x1, MAX), 0)
                y1 = max(min(y1, MAX), 0)
                x2 = max(min(x2, MAX), 0)
                y2 = max(min(y2, MAX), 0)
                acc[x1][y1] += 1
                acc[x2][y2] += 1
                acc[x1][y2] -= 1
                acc[x2][y1] -= 1

for i in range(MAX+1):
    acc[i] = list(accumulate(acc[i]))
for j in range(MAX+1):
    for i in range(MAX):
        acc[i+1][j] += acc[i][j]
ans = 0
for i in range(K*2, K*4+1):
    ans = max(ans, max(acc[i][K*2:K*4+1]))
print(ans)


Measured memory_bytes: 240264