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

using namespace std;

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

  int H,W; cin>>H>>W;
  int A[H][W], B[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin>>A[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin>>B[i][j];
    }
  }

  constexpr int MAX_D = 12800;
  bitset<MAX_D*2+1> dp[W];
  dp[0][MAX_D+A[0][0]-B[0][0]] = 1;
  dp[0][MAX_D-A[0][0]+B[0][0]] = 1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j + 1 < W) {
        auto d = abs(A[i][j+1]-B[i][j+1]);
        dp[j+1] |= dp[j] << d | dp[j] >> d;
      }
      if (i + 1 < H) {
        auto d = abs(A[i+1][j]-B[i+1][j]);
        dp[j] = dp[j] << d | dp[j] >> d;
      }
    }
  }
  int ans = numeric_limits<int>::max();
  for (int i = 0; i <= MAX_D; i++) {
    if (dp[W-1][MAX_D+i] or dp[W-1][MAX_D-i]) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long INF = 2147483647;
constexpr long long INFF = 9223372036854775807;;

ll res(long long N,long long X){
    if(N == 0) return 1;
    long long len = (1LL << (N + 1)) - 3;
    long long pty = (1LL << N) - 1;
    if(X == 1) return 0;
    else if(X <= len + 1) return res(N - 1, X - 1);
    else if(X == len + 2) return pty + 1;
    else if(X <= 2*len + 2) return pty + 1 + res(N - 1,X - len - 2);
    else return 2*pty + 1;
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N,X;
    cin >> N >> X;
    cout << res(N,X) << endl;
}

Measured memory_bytes: 256
n = int(input())
ls = [list(map(int,input().split())) for i in range(n)]
a = 0
for j in range(n):
    for k in range(n):
        if j < k:
            a += ((ls[k][0]-ls[j][0])**2+(ls[k][1]-ls[j][1])**2)**(1/2)
b = a/(n*(n-1)/2)
print(b*(n-1))
            

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

int main() {
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  char c;
  vector<vector<int>> S(H, vector<int>(W));
  for (int i = 0; i < H; i++)
    for (int j = 0, k = 0; j < W && cin >> c; j++)
      S.at(i).at(j) += (c != '#') ? ++k : k = 0;
  for (int i = 0; i < W; i++)
    for (int j = 0, k = 0; j < H; j++)
      S.at(j).at(i) += (S.at(j).at(i) != 0) ? ++k : k = 0;
  for (int i = 0; i < H; i++)
    for (int j = W - 1, k = 0; j >= 0; j--)
      S.at(i).at(j) += (S.at(i).at(j) != 0) ? ++k : k = 0;

  int ans = 0;
  for (int i = 0; i < W; i++)
    for (int j = H - 1, k = 0; j >= 0; j--) {
      S.at(j).at(i) += (S.at(j).at(i) != 0) ? ++k : k = 0;
      ans = max(ans, S.at(j).at(i) - 3);
    }

  cout << ans << "\n";
}

Measured memory_bytes: 16000
N,K,S=map(int,input().split())
a=[]

for i in range(K):
  a.append(S)

if N>len(a):
  for i in range(N-len(a)):
    if S==10**9:
      a.append(S-1)
    else:
      a.append(S+1)
      
print(' '.join(map(str, a)))
  


Measured memory_bytes: 15128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int r, D, x;
  int Dx;
  cin >> r >> D >> x;
  for (int i = 0; i < 10; i++)
  {
    if (i == 0)
    {
      Dx = r * x - D;
    }
    else
    {
      Dx = r * Dx - D;
    }
    cout << Dx << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

int main(){
  int R,G,B,N;
  cin>>R>>G>>B>>N;
  int ans = 0;
  rep(i,3001){
    rep(j,3001){
      int tmp = i*R+j*G;
      if(N >= tmp && (N-tmp) % B == 0)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include<bits/stdc++.h>
using namespace std;

int n,v,ans,a[100005],b[100005];

int main(){
    std::ios::sync_with_stdio(false);
    cin>>n>>v;
    for (int i=1;i<=n;i++) cin>>a[i]>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    for(int i=n;i>=1&&b[i]>a[n]&&v>0;v-=b[i],i--,ans++);
    if(v>0) ans=ans+v/a[n]+(v%a[n]!=0);
    cout<<ans;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}

int main() {
	ll k;
	string s;
	cin >> s >> k;
	ll x = 0;
	rep(i, 0, s.size()) {
		if (s[i] == '1') {
			x += s[i] - '0';
		}
		else x +=1000000000000000000;
		if (k <= x) {
			cout << s[i] << endl;
			return 0;
		}
	}
	return 0;
}


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

typedef long long int64;
#define REP(i,n) for(int64 i=0;i<(int64)(n);i++)
#define REPD(i,n) for(int64 i=(int64)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int64 i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int64)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define GSORT(x) sort(ALL(x), greater<int64>());
#define SUM(x) accumulate(ALL(A), 0);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

void Main() {
	int64 N;
	cin >> N;

	int64 result = 0;
	result = N * N * N;
	cout << result << endl;
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3152
N,C = map(int,input().split())
T = [[0 for i in range(10**5+1)] for j in range(30)]

for i in range(N):
    s,t,c = map(int,input().split())
    T[c-1][s] += 1
    T[c-1][t] -= 1
for i in range(C):
    for j in range(10**5):
        T[i][j+1] += T[i][j]

for i in range(C):
    for j in range(10**5):
        if T[i][-j-1] == 0 and T[i][-j-2] == 1:
            T[i][-j-1] = 1
ans = 0
for i in range(10**5+1):
    ans = max(ans,sum(T[j][i] for j in range(C)))
print(ans)

Measured memory_bytes: 118216
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>

using namespace std;

typedef tuple<int, int, int> T3;

int H, W;
bool field[100 + 10][100 + 10];

int dp[100 + 10][100 + 10][3][2];//0->何もなし　1->h方向継続　2->w方向継続   0->初めての継続　1->続けての継続

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '.')field[i][j] = true;
			for (int k = 0; k < 3; k++)for (int l = 0; l < 2; l++)dp[i][j][k][l] = 1145141919;
		}
	}

	if (field[0][0])dp[0][0][0][0] = 0;
	else dp[0][0][0][0] = 1;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < 2; l++) {
					if (dp[i][j][k][l] == 1145141919)continue;
					if (i + 1 < H) {
						//h方向
						if (k == 0) {
							if (field[i][j] && !field[i + 1][j]) {
								dp[i + 1][j][0][0] = min(dp[i][j][0][0] + 1, dp[i + 1][j][0][l]);
							}
							else if (!field[i][j] && !field[i + 1][j]) {
								//h方向に延びる
								dp[i + 1][j][1][0] = min(dp[i + 1][j][1][0], dp[i][j][0][l]);
							}
							else if (field[i][j] && field[i + 1][j]) {
								//変わりなし！ｗ
								dp[i + 1][j][0][0] = min(dp[i + 1][j][0][0], dp[i][j][0][l]);
							}
							else if (!field[i][j] && field[i + 1][j]) {
								//ｽﾄﾘｰｸが終了
								dp[i + 1][j][0][0] = min(dp[i + 1][j][0][0], dp[i][j][0][0]);
							}
						}
						else if (k == 1) {
							if (!field[i + 1][j] && !field[i][j]) {
								dp[i + 1][j][1][l] = min(dp[i + 1][j][1][l], dp[i][j][k][l]);
							}
							else {
								dp[i + 1][j][0][0] = min(dp[i + 1][j][0][0], dp[i][j][k][l]);
							}
						}
						else if (l == 0)
							dp[i + 1][j][1][1] = min(dp[i + 1][j][1][1], dp[i][j][k][l]);
					}

					if (j + 1 < W) {
						//w方向
						if (k == 0) {
							if (field[i][j] && !field[i][j + 1]) {
								dp[i][j + 1][0][0] = min(dp[i][j][0][0] + 1, dp[i][j + 1][0][l]);
							}
							else if (!field[i][j] && !field[i][j + 1]) {
								//w方向に延びる
								dp[i][j + 1][1][0] = min(dp[i][j + 1][1][0], dp[i][j][0][l]);
							}
							else if (field[i][j] && field[i][j + 1]) {
								//変わりなし！ｗ
								dp[i][j + 1][0][0] = min(dp[i][j + 1][0][0], dp[i][j][0][l]);
							}
							else if (!field[i][j] && field[i][j + 1]) {
								//ｽﾄﾘｰｸが終了
								dp[i][j + 1][0][0] = min(dp[i][j + 1][0][0], dp[i][j][0][l]);
							}
						}
						else if (k == 2) {
							if (!field[i][j] && !field[i][j + 1]) {
								dp[i][j + 1][1][l] = min(dp[i][j + 1][1][l], dp[i][j][k][l]);
							}
							else {
								dp[i][j + 1][0][0] = min(dp[i][j + 1][0][0], dp[i][j][k][l]);
							}
						}
						else {
							if (l == 0) dp[i][j + 1][0][1] = min(dp[i][j + 1][0][1], dp[i][j][k][l]);
							else {
								dp[i][j + 1][0][0] = min(dp[i][j + 1][0][0], dp[i][j][k][l]);
							}
						}
					}
				}
			}
		}
	}
	int ans = 1145141919;
	for (int k = 0; k < 3; k++)for (int l = 0; l < 2; l++)ans = min(ans, dp[H - 1][W - 1][k][l]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1144
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;

int w,h;
int dim[52][52];
int mark[52][52];
int dirx[8] = {-1,-1,-1,0,0,1,1,1};
int diry[8] = {-1,0,1,-1,1,-1,0,1};
queue<pair<int,int> > q;
int check(int x,int y){
	if (x <0 || x >= h || y<0 || y>=w)return 0;
	return 1;
}
int main(){
	while(scanf("%d %d", &w, &h)!= EOF){
		if (w==0 && h==0)return 0;
		memset(mark, -1, sizeof(mark));
		for (int i=0;i<h;i++){
			for (int j=0;j<w;j++){
				scanf("%d", &dim[i][j]);
			}	
		}
		int island = 0;
		for (int i=0;i<h;i++){
			for (int j=0;j<w;j++){
				if (dim[i][j] == 1 && mark[i][j] == -1){
					island++;
					q.push(make_pair(i, j));
					mark[i][j] = 1;
					while(!q.empty()){
						pair<int, int> temp= q.front();
						q.pop();
						for (int k=0;k<8;k++){
							int tx = temp.first + dirx[k];
							int ty = temp.second + diry[k];
							if (check(tx,ty) == 1){
								if (dim[tx][ty] && mark[tx][ty] == -1){
									mark[tx][ty] = 1;
									q.push(make_pair(tx,ty));
								}
							}
						}
					}
				}
			}	
		}
		printf("%d\n", island);
	}
	return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

int main() {
    vector<int> n(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(), n.end(), greater<int>());

    int ans = (n[0] * 10 + n[1] * 1) + n[2];
    cout << ans << endl;
}

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

int main() {
    int h,w; cin >> h >> w;
    vector<string> b(h); rep(i,h) cin >> b[i];
    vector<bool> hf(h), wf(w);
    rep(i,h)rep(j,w) if (b[i][j] == '#') {
        hf[i] = true;
        wf[j] = true;
    }
    rep(i,h) {
        rep(j,w) if (hf[i] && wf[j]) {
            cout << b[i][j];
        }
        cout << endl;
    }
}

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

int main() {
  ll N,c=1000000007,p=1;
  cin>>N;
  for(int i=0;i<N;i++){
    p*=i+1;
    while(p>=c)p%=c;
  }
  cout<<p<<endl;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int K;
  cin >> K;

  int answer {(K/2)*(K/2+(K%2))};
  cout << answer << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

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

  if(a<=b*2)
    cout << 0;

  else
    cout << a - b*2;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, h, w, r, c;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> r >> c;
        if (r >= h && c >= w)
            ans += 1;
    }
    cout << ans << endl;
    return 0;
}


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

int icicle[105000], n, l, table[105000];

int snap(int x){
  if(table[x] != 0)return table[x];
  int res = 0;
  if(icicle[x - 1] > icicle[x]){
    res = max(res, snap(x - 1));
  }
  if(icicle[x + 1] > icicle[x]){
    res = max(res, snap(x + 1));
  }
  res += l - icicle[x];
  return table[x] = res;
}

int main(){
  cin >> n >> l;
  for(int i = 1;i <= n;i++){
    cin >> icicle[i];
  }
  int res = 0;
  for(int i = 1;i <= n;i++){
    res = max(res, snap(i));
  }
  cout << res << endl;
}

Measured memory_bytes: 3116
N = int(input())
A = list(map(int, input().split()))

ans = [0] * (max(A) + 2)

for a in A:
    if a == 0:
        ans[a] += 1
        ans[a + 1] += 1
    if a != 0:
        ans[a - 1] += 1
        ans[a] += 1
        ans[a + 1] += 1

print(max(ans))


Measured memory_bytes: 20900
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll n;
  priority_queue<double, vector<double>, greater<double>> q;
  cin >> n;
  int v;
  for (int i = 0; i < n; i++) {
    cin >> v;
    q.push(v);
  }
  double a, b;
  for (int i = 0; i < n - 1; i++) {
    a = q.top();
    q.pop();
    b = q.top();
    q.pop();
    q.push((double)((a + b) / 2));
  }
  printf("%.7lf", q.top());

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll k,x;

void init(){
	cin>>k>>x;
}

int main(void){
	init();
	reg(i,x-k+1,x+k-1)cout<<i<<" ";
	cout<<endl;
	return 0;
}

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

int main(){
    int n,a,b;
    cin>>n>>a>>b;

    cout<<min(a*n,b)<<endl;
    
}

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


int main() {
    int N,M,P;
    while (true) {
        cin >> N >> M >> P;
        vector<int> X(N);
        if ( N == 0 && M ==  0 && P == 0) return 0;
        int s = 0;
        rep(i,N) {
            cin >> X[i];
            s += X[i];
        }
        if (X[M-1] == 0) cout << 0 << endl;
        else cout << (100 * (s) * (100 - P) / 100) / X[M-1] << endl;
        
    }
}



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

int main(){
    int n;
    cin >> n;
    vector<string> w(n) ,s(n);
    rep(i,n) {
        cin >> w[i];
        s[i] = w[i];
    }
    sort(s.begin(),s.end());
    rep(i,n-1){
        if(w[i+1][0] != w[i][w[i].size()-1]){
            cout << "No" << endl;
            return 0;
        }
        if(s[i] == s[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;
using LL = long long;

int main(){
    int n;cin >> n;
    vector<vector<char>> bottoms = {{'.', ',', '!', '?', ' '},
                                    {'a', 'b', 'c'},
                                    {'d', 'e', 'f'},
                                    {'g', 'h', 'i'},
                                    {'j', 'k', 'l'},
                                    {'m', 'n', 'o'},
                                    {'p', 'q', 'r', 's'},
                                    {'t', 'u', 'v'},
                                    {'w', 'x', 'y', 'z'},
                                   };
    for(int i = 0;i < n;i++){
        string s;cin >> s;
        vector<int> indexes(9);
        string ans;
        for(char c : s){
            if(c == '0'){
                for(int a = 0;a < 9;a++){
                    if(indexes.at(a) != 0){
                        ans += bottoms.at(a).at((indexes.at(a)-1)%(bottoms.at(a).size()));
                        indexes = vector<int>(9,0);
                        break;
                    }
                }
                continue;

            }
            int w = c - '1';
            indexes.at(w)++;
        }
        cout<<ans<<endl;
    }
}



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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

ll dis[10000000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin>>s;
	string st = s.substr(0,(s.length()-1)/2);
	string sd = s.substr((s.length()+3)/2-1);

	string cd = s;
			reverse(s.begin(),s.end());

	if(s != cd){
		writeln("No");
		return 0;
	}

	 cd = st;
			reverse(st.begin(),st.end());

	if(st != cd){
		writeln("No");
		return 0;
	}

	cd = sd;
			reverse(sd.begin(),sd.end());

	if(sd != cd){
		writeln("No");
		return 0;
	}

	writeln("Yes");
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int B = 63;
int a, b;
int p;
int ans;

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> a >> b;

	if (a == b) return cout << "1\n", 0;

	for (int i = B - 1; i >= 0; i--)
	{
		if ((b & (1ll << i)) && !(a & (1ll << i)))
		{
			p = i;

			for (int k = p - 1; k >= 0; k--)
			{
				if (b & (1ll << k))
				{
					b |= ((1ll << (k + 1)) - 1);
					break;
				}
			}

			break;
		}
	}

	int l = a + (1ll << p), r = a | ((1ll << (p + 1)) - 1);
	
	ans += max(0ll, b - a + 1);
	ans += max(0ll, r - l + 1);
	ans -= max(0ll, b - l + 1);

	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const long long inf = 1LL << 22;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	if (s == "AKIHABARA" || s == "AKIHABAR" || s == "AKIHABRA" || s == "AKIHBARA" || s == "KIHABARA" || s == "AKIHABR" || s == "AKIHBAR" || s == "AKIHBRA" || s == "KIHABAR" || s == "KIHABRA" || s == "KIHBARA" || s == "AKIHBR" || s == "KIHBRA" || s == "KIHABR" || s == "KIHBAR" || s == "KIHBR") {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string ans = "No";
  cin >> N;
  int cnt=0;
  for(int i = 0 ; i < N ; i++){
    int D1, D2;
    cin >> D1 >> D2;
    if(D1 == D2){
      cnt++;
    }else{
      cnt = 0;
    }

    if(cnt == 3){
      ans = "Yes";
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

map<ll, ll> memo;
ll A;
ll B;
ll C;
ll D;

ll f(ll N){
    if(memo.count(N)){
        return memo.at(N);
    }
    if(N == 0){
        memo[0] = 0;
        return 0;
    }
    if(N == 1){
        memo[1] = D;
        return D;
    }
    if(N == 2){
        ll v = min(min(f(1)+A, f(1)+D+B), 2*D);
        memo[2] = v;
        return v;
    }
    if(N == 3){
        ll v = min(min(min(f(1)+D+A, f(1)+B), f(1)+2*D+C), 3*D);
        memo[3] = v;
        return v;
    }
    if(N == 4){
        ll v = min(min(min(f(2)+A, f(1)+D+B), f(1)+D+C), 4*D);
        memo[4] = v;
        return v;
    }
    long double p = (long double)(N);
    ll a = floor(p/2);
    ll b = ceil(p/2);
    ll v1 = f(a)+D*(N-2*a)+A;
    ll v2 = f(b)+D*(2*b-N)+A;
    a = floor(p/3);
    b = ceil(p/3);
    ll v3 = f(a)+D*(N-3*a)+B;
    ll v4 = f(b)+D*(3*b-N)+B;
    a = floor(p/5);
    b = ceil(p/5);
    ll v5 = f(a)+D*(N-5*a)+C;
    ll v6 = f(b)+D*(5*b-N)+C;
    ll v = min(v1, v2);
    chmin(v, v3);
    chmin(v, v4);
    chmin(v, v5);
    chmin(v, v6);
    long double q = (long double)(D);
    long double max = 9223372036854775807;
    if(log10(p)+log10(q) <= log10(max)){
        chmin(v, N*D);
    }
    memo[N] = v;
    return v;
}

int main()
{
    ll T;
    cin >> T;
    rep(i, T){
        memo.clear();
        ll N;
        cin >> N >> A >> B >> C >> D;
        ll ans = f(N);
        cout << ans << endl;
    }
}

Measured memory_bytes: 4240
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

vector<pii> v;

signed main(){
    IOS;
    int n, m;
    cin >> n >> m;
    int b, e;
    if (n == 1) b = 0, e = 9;
    else if (n == 2) b = 10, e = 99;
    else if (n == 3) b = 100, e = 999;
    while (m--) {
    	int a, b;
    	cin >> a >> b;
    	v.pb({a, b});
    }
    for (int i = b; i <= e; i++) {
    	string s = to_string(i);
    	int flag = 0;
    	for (auto it : v) {
    		if (s[it.fi-1] - '0' != it.se) {flag = 1; break;}
    	}
    	if (flag == 0) return cout << i, 0;
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;
#define ll long long 
#define pb(a) push_back(a)
#define fi first
#define se second
#define rep(a,b,c) for(int a = b ;a<=c;a++)
#define repn(a,b,c) for(int a = b ; a>=c ; a--)
#define FOR(a,b,c) for(int a = b ; a<c ;a++)
#define mem(a,b) memset(a,b , sizeof(a))
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define Size(a) ((int)a.size())
#define ii int
const int INF=0x3f3f3f3f;
const int maxn=5e9+10;
const int maxk=30;


ll f[(int)1e5 + 10];
ll a[(int)1e5 + 10];

ll min(ll a, ll b){
	return (a > b) ? b : a;
}

 int main(){

 	ll n;
 	cin>>n;

 	vector<int>h(n);

 	FOR(i,0,n){
 		cin>>h[i];
 	}

 	vector<int>dp(n , INF);

 	dp[0] = 0;

 	FOR(i, 0 , n){
 		for(int j = i + 1 ; j <= i + 2 ; j ++){
 			if(j < n){
 				dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j]));
 			}
 		}
 	}

 	cout<<dp[n-1]<<endl;

    return 0;
 }

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        
        int start = scan.nextInt();
        int end = scan.nextInt();
        int ans = 0;
        
        for(int i = start; i <= end; i++){
            if(i/1000 == underHundred(i))
                ans++;
        }
        
        System.out.println(ans);
    }
    
    private static int underHundred(int i){
        int temp = i%100;
        return temp%10*10 + temp/10;
    }
}


Measured memory_bytes: 22996
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CXYZTriplets {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> f(N+1, 0);
        for(int i=1;i*i<=N;++i){
            for(int j=1;j*j<=N;++j){
                for(int k=1;k*k<=N;++k){
                    int cur = i*i+j*j+k*k+i*j+j*k+k*i;
                    if(cur<=N) f[cur]++;
                }
            }
        }
        FOR(i, 1, N+1) out<<f[i]<<'\n';
    }
};


int main() {
	CXYZTriplets solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3604
S=input()
dp=[[0]*13 for i in range(len(S)+1)]
dp[0][0]=1
mod=10**9+7
for i in range(len(S)):
  if(S[i]=='?'):
    for j in range(13):
      for k in range(10):
        l=(j*10+k)%13
        dp[i+1][l]+=dp[i][j]
    for j in range(13):
      dp[i+1][j]%=mod
  else:
    k=int(S[i])
    for j in range(13):
      l=(j*10+k)%13
      dp[i+1][l]+=dp[i][j]
    for j in range(13):
      dp[i+1][j]%=mod
print(dp[len(S)][5])



Measured memory_bytes: 61916
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
using namespace std;

typedef long long i64;

i64 N;

int dig[50], tot;
deque<int> res;

int main() {
  scanf("%lld", &N);
  int num;
  for (int i = 40; i; --i) {
    i64 X = (1LL << i) - 1;
    if (X <= N) {
      num = i, N -= X;
      break;
    }
  }

  for (int i = num, now = 0; i >= 0; --i) {
    i64 X = 1LL << i;
    if (N >= X) {
      res.push_front(++now);
      N -= X;
    } 
    if (i) res.push_back(++now);
  }

  printf("%d\n", res.size() * 2);

  for (int i = 0; i < res.size(); ++i)
    printf("%d ", res[i]);
  
  // static i64 f[205];

  // i64 way = 0;
  // for (int i = 0; i < res.size(); ++i) {
  //   f[i] = 1;
  //   for (int j = 0; j < i; ++j)
  //     if (res[j] < res[i]) f[i] += f[j];
  //   way += f[i];
  // }
  // printf("%lld\n", way);
  
  for (int i = 0; i < res.size(); ++i)
    printf("%d ", i + 1);
  puts("");
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Main {
    static ArrayList<Integer>[]adj;
    static void bfs(int s,int []d){
        Arrays.fill(d,-1);
        d[s]=0;
        Queue<Integer>q= new LinkedList<>();
        ((LinkedList<Integer>) q).add(s);
        while (!q.isEmpty()){
            int u = q.poll();
            for (int v:adj[u]){
                if (d[v]==-1){
                    d[v]=1+d[u];
                    ((LinkedList<Integer>) q).add(v);
                }
            }
        }
    }
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[]a = new int[n];
        for (int i =0;i<n;i++)a[i]=sc.nextInt();
        int ans =(int)1e9;
        for (int i =0;i<n-1;i++){
            ans=Math.min(ans,k-Math.abs(a[i]-a[i+1]));
            if (i>0)
                ans=Math.min(ans,k-Math.abs(a[i-1]-a[i]));
        }
        ans=Math.min(ans,k-(k-a[n-1]+a[0]));
        pw.println(ans);
        pw.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

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

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

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

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

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

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

}

Measured memory_bytes: 47956
S = input()

def isPalin(s):
    flag = True
    for i in range(len(s)):
        if s[i] != s[-i-1]:
            flag = False
            break
    return flag

if isPalin(S) and isPalin(S[:(len(S)-1)//2]):
    print('Yes')
else:
    print('No')

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		D2(sc);
	}
	

	public static void D2(Scanner sc) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		HashMap<Integer,Integer>[] edge = new HashMap[N]; // edge[a].get(b) はノードaからノードbへの距離   
		boolean[] visit = new boolean[N];
		long[] value = new long[N];
		for(int i=0;i<N;i++) edge[i] = new HashMap<Integer,Integer>();
		for(int i=0;i<M;i++) {
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			int d = sc.nextInt();
			if(!putedge(edge,l,r,d)) {
				out.println("No");
				return;
			}
		}
		for(int i=0;i<N;i++) {
			if(!bfs(edge,i,value,visit)) {
				out.println("No");
				return;
			};
		}
		out.println("Yes");
	}
	
	public static boolean putedge(HashMap<Integer,Integer>[] edge, int l, int r, int d) {
		if(edge[l].containsKey(r) && edge[l].get(r)!=d) return false;
		edge[l].put(r,d);
		edge[r].put(l,-d);
		return true;
	}
	// BFSでvalueを計算して行く。　valueが矛盾すればfalse
	public static boolean bfs(HashMap<Integer,Integer>[] edge, int n, long[] value, boolean[] visit) {
		if(visit[n]) return true;
		LinkedList<Integer> que = new LinkedList<Integer>();
		visit[n] = true;
		value[n] = 0;
		que.add(n);
		while(!que.isEmpty()) {
			int node = que.removeFirst();
			for(int neigh : edge[node].keySet()) {
				if(visit[neigh] && value[neigh]!=(value[node]+edge[node].get(neigh))) {
					return false;
				}
				else if(!visit[neigh]){
					visit[neigh] = true;
					value[neigh] = value[node]+edge[node].get(neigh);
					que.add(neigh);
 				}
			}
		}
		return true;
	}
	
}

Measured memory_bytes: 190376
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

flag = 'No'
for i in range(c1[0] + 1):
    a1 = i
    b1 = c1[0] - a1
    b2 = c1[1] - a1
    b3 = c1[2] - a1
    a2 = c2[0] - b1
    a3 = c3[0] - b1

    c22 = a2 + b2
    c23 = a2 + b3
    c32 = a3 + b2
    c33 = a3 + b3

    if (c2[1] - c22) ** 2 + (c2[2] - c23) ** 2 + (c3[1] - c32) ** 2 + (c3[2] - c33) ** 2 == 0:
         flag = 'Yes'
print(flag)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!

a=input()
if a=="SAT":
    print("1")
if a=="SUN":
    print("7")
if a=="MON":
    print("6")
if a=="TUE":
    print("5")
if a=="WED":
    print("4")
if a=="THU":
    print("3")
if a=="FRI":
    print("2")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
N = int(input())
v_list = list(map(int, input().split()))

v_list.sort(reverse=True)

for i in range(len(v_list) - 1):
    append_num = (v_list.pop() + v_list.pop()) / 2
    v_list.append(append_num)

print(v_list[0])

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  string s; cin >> s;
  if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(size_t i = (j); i < (n); ++i)
#define rrep(i, j, n) for(size_t i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	
	int n, a; cin >> n;

	map<int, int> cnt;
	rep(i, 0, n) {
		cin >> a;
		cnt[a]++;
	}

	int ans = 0;
	for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
		int k = itr->first;
		int v = itr->second;
		if (k > v) ans += v;
		else if (k < v) ans += v - k;
	}
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 8056
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
//最大公約数
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
//最小公倍数
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    int n;
    cin>>n;
    if(n%1000==0){
        cout<<"0"<<endl;
    }
    else{
        cout<<(n/1000+1)*1000-n<<endl;
    }
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	a := make([]int, N)

	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	sum := 0
	for _, l := range a[(N - K):] {
		//fmt.Printf("l=%v\n", l)
		sum += l
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<vector<double>>>dp(303, vector<vector<double>>(303, vector<double>(303, -1)));
int n;
double F(int x, int y, int z)
{
	if (x == 0 && y == 0 && z == 0)
		return 0;
	if (dp[x][y][z] != -1)
		return dp[x][y][z];
	double ans = n;
	if (x)
		ans += x * F(x - 1, y, z);
	if (y)
		ans += y * F(x + 1, y - 1, z);
	if (z)
		ans += z * F(x, y + 1, z - 1);
	return (dp[x][y][z] = ans / (x + y + z));
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> n; vector<int>a(n);
	int x = 0; int y = 0; int z = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		x += (a[i] == 1);
		y += (a[i] == 2);
		z += (a[i] == 3);
	}
	cout << fixed << setprecision(11) << F(x, y, z);

	return 0;
}

Measured memory_bytes: 224008
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define NMAX 100000
#define P pair<int,int>
int main(){
  int n;
  cin >> n;
  int a,b;
  vector<int> v[NMAX+1];
  queue<P> q;
  bool used[NMAX+1]={};
  for(int i=0;i<n-1;i++){
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  q.push(P(1,1));
  q.push(P(n,0));
  int fcnt=0, scnt=0;
  while(!q.empty()){
    P tp = q.front();
    q.pop();
    if(used[tp.first]) continue;
    if(tp.second==1) fcnt++;
    else scnt++;
    used[tp.first] = true;
    for(int i=0;i<v[tp.first].size();i++){
      if(!used[v[tp.first][i]])
        q.push(P(v[tp.first][i], tp.second));
    }
  }
  if(fcnt > scnt) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

Measured memory_bytes: 6144
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2],bit[maxn],f[maxn];
int i,j,k,l,t,n,m,tot,top,ans;
void add(int x,int y){
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x,int y){
	bit[x]=f[x]=0;
	int t=h[x],l=0;
	while (t){
		if (go[t]!=y){
			dfs(go[t],x);
			l|=(bit[x]&bit[go[t]]);
			bit[x]|=bit[go[t]];
		}
		t=nxt[t];
	}
	if (!bit[x]) bit[x]=1;
	else{
		while ((1<<f[x])<l||(1<<f[x])&bit[x]) f[x]++;
		bit[x]=(bit[x]>>f[x]<<f[x])|(1<<f[x]);
	}
	ans=max(ans,f[x]);
}
int main(){
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&j,&k);
		add(j,k);add(k,j);
	}
	dfs(1,0);
	printf("%d\n",ans);
}

Measured memory_bytes: 6272
def f(As):
    Bs = [0] * N

    if N % 2:
        iB, d = 0, N - 1
    else:
        iB, d = 0, N - 2
    for A in As[N//2:]:
        Bs[iB] = A
        iB += d
        if d > 0:
            d = -d + 2
        else:
            d = -d - 2

    if N % 2:
        iB, d = 1, N - 3
    else:
        iB, d = N - 1, -(N - 2)
    for A in reversed(As[:N//2]):
        Bs[iB] = A
        iB += d
        if d > 0:
            d = -d + 2
        else:
            d = -d - 2

    ans = 0
    for i in range(N - 1):
        ans += abs(Bs[i + 1] - Bs[i])

    return ans


N = int(input())
As = [int(input()) for _ in range(N)]

As.sort()

print(max(f(As), f(As[::-1])))


Measured memory_bytes: 9016
#include <stdio.h>

int digit(int x)
{
    int i = 1;
    
    while (1) {
        x /= 10;
        if (x == 0) break;
        i++;
    }
    
    return i;
}

int main(void)
{
    int a, b;
    int s;
    int i;

    while (scanf("%d %d", &a, &b) != EOF) {
        printf("%d\n", digit(a + b));
    }

    return 0;
}

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

const int KIND = 26;
int D;
int c[KIND];
int s[400][KIND];
int last[KIND];

ll calc_score(vector<ll> t) {
    ll score = 0;
    fill(last, last + 26, -1);
    for(int d = 0; d < D; d++) {
        score += s[d][t[d]];
        last[t[d]] = d; 
        for(int i = 0; i < KIND; i++) {
            score -= c[i] * (d - last[i]);
        }
    }
    return score;
}

int main() {
    cin >> D;
    for(int i = 0; i < KIND; ++i) {
        cin >> c[i];     
    }
    for(int d = 0; d < D; d++) {
        for (int i = 0; i < KIND; i++) {
            cin >> s[d][i];
        }
    }

    vector<ll> t(D);
    for (auto &elem : t) {
        cin >> elem;
        elem--;
    }

    ll current_score = calc_score(t);

    ll m;
    cin >> m;
    for(int i = 0; i < m; i++) {
        int d, q;
        cin >> d >> q;
        d--;
        q--;
        int old = t[d];
        t[d] = q;
        ll new_score = calc_score(t);
        cout << new_score << endl;
    //     if (new_score < current_score) {
    //         t[d] = old;
    //     }
    //     else {
    //         current_score = new_score;
    //     }
    //     cout << current_score << endl;

        current_score = new_score;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1000000005;
const ll INF2 = INF * 300;

int main() {
  int n, m, a, b, q;
  ll l, c;
  cin >> n >> m >> l;
  ll d[n][n];
  int e[n][n];
  rep(i, n) {
    rep(j, n) {
      if (i == j) {
        d[i][j] = 0;
        e[i][j] = 0;
      }
      else {
        d[i][j] = INF2;
        e[i][j] = INF;
      }
    }
  }
  rep(i, m) {
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  rep(k, n) {
    rep(i, n) {
      if (d[i][k] == INF2) continue;
      rep(j, n) {
        if (d[k][j] == INF2) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      if (d[i][j] <= l) e[i][j] = 1;
    }
  }

  rep(k, n) {
    rep(i, n) {
      if (e[i][k] == INF) continue;
      rep(j, n) {
        if (e[k][j] == INF) continue;
        e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
      }
    }
  }

  cin >> q;
  rep(i, q) {
    cin >> a >> b;
    a--;
    b--;
    if (e[a][b] == INF) cout << -1 << endl;
    else cout << e[a][b]-1 << endl;
  }


  
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char a,b; cin>>a>>b;
	if(a=='D') {
		if(b=='D') b='H';
		else b='D';
	}
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main(){
    int n;
    string s;cin>>s;
    n=s.size();
    for(int i=n-2;i>0;--i){
        if((i-0+1)&1)continue;
        int len=i-0+1;
        string s1;
        for(int j=0;j<len/2;++j){
            s1+=s[j];
        }
        string s2;
        for(int j=len/2;j<=i;++j){
            s2+=s[j];
        }
        if(s1==s2){
            cout<<len<<"\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256