akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//   0 1 2
//   3 4 5
//   6 7 8
int main() {
    vector<int> a (9);
    for(int i = 0;i < 9;i++){
	cin >> a.at(i);
    }
    int i = 1;
    while(i){
    	i = 0;
    	if(a.at(0) > 0 && a.at(1) > 0 && a.at(2) > 0){
    		i = 1;
    		a.at(0) -= 1;
    		a.at(1) -= 1;
    		a.at(2) -= 1;
    	}
    	if(a.at(3) > 0 && a.at(4) > 0 && a.at(5) > 0){
    		i = 1;
    		a.at(3) -= 1;
    		a.at(4) -= 1;
    		a.at(5) -= 1;
    	}
    	if(a.at(6) > 0 && a.at(7) > 0 && a.at(8) > 0){
    		i = 1;
    		a.at(6) -= 1;
    		a.at(7) -= 1;
    		a.at(8) -= 1;
    	}
    	if(a.at(0) > 0 && a.at(3) > 0 && a.at(6) > 0){
    		i = 1;
    		a.at(0) -= 1;
    		a.at(3) -= 1;
    		a.at(6) -= 1;
    	}
    	if(a.at(1) > 0 && a.at(4) > 0 && a.at(7) > 0){
    		i = 1;
    		a.at(1) -= 1;
    		a.at(4) -= 1;
    		a.at(7) -= 1;
    	}

    	if(a.at(2) > 0 && a.at(5) > 0 && a.at(8) > 0){
    		i = 1;
    		a.at(2) -= 1;
    		a.at(5) -= 1;
    		a.at(8) -= 1;
    	}
    }
    int test = 0;
    for(int i = 0;i < 9;i++){
    	if(a.at(i) == 0){
    		test++;
    	}
    }
    if(test == 9){
    	cout << "Yes" << endl;
    }
    else{
    	cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())

def bfs(s):
    que = deque()
    que.append(s)
    cnt = 0
    while que.__len__() != 0:
        s = que.popleft()
        for ds in '753':
            ss = s + ds
            if int(ss) > N:
                continue
            if all(ss.count(i) > 0 for i in '753'):
                cnt += 1
            que.append(ss)
    return cnt

ans = 0
ans += bfs('3')
ans += bfs('5')
ans += bfs('7')

print(ans)


Measured memory_bytes: 9632
import copy
n,m = map(int,input().split())
tall = [int(e) for e in input().split()]

bridge = copy.copy(tall)

for i in range(m):
    c = [int(f)-1 for f in input().split()]
    a,b = c[0],c[1]
    if bridge[a] < tall[b]:
        bridge[a] = tall[b]
    elif bridge[a] == tall[b]:
        bridge[a] = 10**10
    if bridge[b] < tall[a]:
        bridge[b] = tall[a]
    elif bridge[b] == tall[a]:
        bridge[b] = 10**10

cnt = 0
for j in range(n):
    if tall[j] == bridge[j]:
        cnt += 1

print(cnt)

Measured memory_bytes: 20916
#include <iostream>

using namespace std;

int main(){
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for(int x = 0; x <= K; x++){
        for(int y = 0; y <= K; y++){
            if(0 <= S-x-y && S-x-y <= K){
                ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

cnt = [0 for _ in range(N)]

for i in range(1, N):
    if i == 0:
        continue

    cnt[i] = cnt[i - 1]

    if S[i - 1] == 'A' and S[i] == 'C':
        cnt[i] += 1

for _ in range(Q):
    l, r = map(int, input().split())
    print(cnt[r - 1] - cnt[l - 1])


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

int main()
{
	int64_t n, m, inf = (1LL << 60);
	cin >> n >> m;
	vector<int64_t> as(m), bs(m);
	vector<vector<int64_t>> css(m);
	for (int64_t i = 0; i < m; i++)
	{
		cin >> as[i] >> bs[i];
		css[i].resize(bs[i]);
		for (auto &&c : css[i])
		{
			cin >> c;
			c--;
		}
	}

	// dp[i][T] := i番目までの鍵を使って 錠前の集合Tを開く際のコストの最小値
	vector<vector<int64_t>> dp(m + 1, vector<int64_t>((1 << n), inf));
	dp[0][0] = 0;

	for (int i = 0; i < m; i++)
	{
		for (int T = 0; T < (1 << n); T++)
		{
			dp[i + 1][T] = min(dp[i + 1][T], dp[i][T]);
			int U = T;
			for (auto &&c : css[i])
			{
				U |= (1 << c);
			}
			dp[i + 1][U] = min(dp[i + 1][U], dp[i][T] + as[i]);
		}
	}

	cout << ((dp[m][(1 << n) - 1] == inf) ? -1 : dp[m][(1 << n) - 1]) << endl;

	return 0;
}

Measured memory_bytes: 32512
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    for(int i = 0; i < n; i++){
        int tmp = 0;
        for(int j = 0; j <= i; j++){
            tmp += a[j];    
        }
        for(int k = i ; k < n; k++){
            tmp += b[k];
        }
        ans = max(ans, tmp);
    }

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n;
    cin>>n;
    int a[n+1],cnt[n]={},l,r;
    for(int i=0;i<n+1;i++){
        cin>>a[i];
        if(++cnt[a[i]-1]==2)r=i;
    }
    for(int i=0;i<r;i++){
        if(a[i]==a[r])l=i;
    }
    COMinit();
    for(ll i=1;i<=n+1;i++){
        ll ans=COM(n+1,i);
        if(i-1<=l+n-r){
            ans=(MOD+ans-COM(l+n-r,i-1))%MOD;
        }
        cout<<ans<<endl;
    }
}


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

typedef long long ll;
const int INF = 1e9;
const int N = 1e5 + 5;

int a[N];

int main()
{
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x; scanf("%d", &x);
		a[x]++, a[x + 1]++, a[x + 2]++;
	}
	int ans = 0;
	for (int i = 0; i < N; i++) ans = max(ans, a[i]);
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rec(i, n) for(i = 0; i < n; i++)
 
int main(){
  int i,n;
  bool ans = true;
  cin >> n;
  vector<int> height(n);
  vector<int> flag(n);
  flag.at(0) = 0;
  rec(i,n) {cin >> height.at(i);}
  rec(i,n-1){
    if(height.at(i) - 1 == height.at(i+1) && flag.at(i) == 0){
      flag.at(i+1) = 1;
    }
    else if(height.at(i) > height.at(i+1)){
      ans = false;
    }
    else if(height.at(i) == height.at(i+1)){
      flag.at(i+1) = flag.at(i);
    }
    else flag.at(i+1) = 0;
  }
  if(ans == true)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

char str[10];
int mp[100];
int main(){
	scanf("%s", str);
	rep(i,3)mp[str[i]-'a']++;
	if(mp[0] == 1 && mp[1] == 1 && mp[2] == 1)
	printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    string ans;
    if(a < 0 && b >= 0) ans = "Zero";
    if(b < 0){
        int tmp = abs(b - a) + 1;
        if(tmp % 2 == 0) ans = "Positive";
        else ans = "Negative";
    }

    else if(b > 0){
        int tmp;
        if(a < 0){
            ans = "Zero";
        }
        else if(a > 0) ans = "Positive";
    }

    if(a == 0 || b == 0) ans = "Zero";

    cout<<ans<<endl;

    return 0;
}

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

int p[30];
int main(){
	int n;cin>>n;
	rep(i,n){
		cin>>p[i];
	}
	int cnt=0;
	for(int i=1;i+1<n;i++){
		int a[]{p[i-1],p[i],p[i+1]};
		sort(a,a+3);
		if(a[1]==p[i])cnt++;
	}
	cout<<cnt<<endl;
}

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

#define Cpy(a, b) memcpy(a, b, sizeof (a))
#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("e.in", "r", stdin);
	freopen("e.out", "w", stdout);
}

const int N = 700 + 5;

int G[N][N], n, m, col[N], c[2];

bitset<N << 1> F, T;

inline void dfs(int x, int nw) {
	++ c[col[x] = nw];
	For(v, 1, n) if (v ^ x && !G[v][x]) {
		if (col[v] == nw) { puts("-1"); exit(0); }
		if (col[v] == -1) dfs(v, nw ^ 1);
	}
}

int main() {

	n = read(), m = read();
	For(i, 1, m) {
		int x = read(), y = read();
		G[x][y] = G[y][x] = 1;
	}

	Set(col, -1); F.set(0); 

	For(i, 1, n) if (col[i] == -1) {
		Set(c, 0), dfs(i, 0);	
		T.reset();
		T = (F << c[0]) | (F << c[1]);
		F = T;
	}
	
	int ans = INT_MAX;
	For(i, 0, n) if (F.test(i)) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
using namespace std;

#define N 100002

vector<pair<long long,int> >edge[N];

bool vis[N][2];

long long val[N][2];

bool dfs(int node,int bit,long long value) {
  if(vis[node][bit]) {
    if(value!=val[node][bit]) {
      return false;
    }
    return true;
  }
  vis[node][bit] = true;
  val[node][bit] = value;
  int sz = edge[node].size(),ch;
  long long w;
  for(int i=0;i<sz;++i) {
    ch = edge[node][i].second,w = edge[node][i].first;
    if(!dfs(ch,bit^1,w-value)) {
      return false;
    }
  }
  return true;
}
long long mini[N];
void solve() {
  int n,m;scanf("%d %d",&n,&m);
  const long long inf = 2e18;
  for(int i=n;i;--i) {
    mini[i] = inf;
  }
  for(int i=m;i;--i) {
    int x,y;
    long long w;
    scanf("%d %d %lld",&x,&y,&w);
    edge[x].push_back(make_pair(w,y));
    edge[y].push_back(make_pair(w,x));
    mini[x] = min(mini[x],w);
    mini[y] = min(mini[y],w);
  }
  int root = 1;
  if(!dfs(root,0,0)) {
    printf("0\n");
    return;
  }
  if(vis[root][0] && vis[root][1]) {
    //only one value accepted
    long long t = val[root][1] - val[root][0];
    int r = 1;
    if(t%2==0 && t>0) {
      for(int i=1;i<=n;++i) {
        if(val[i][1] - val[i][0] != t) {
          r = 0;
          break;
        }
      }
      if(r) {
        t/=2;
        for(int i=1;i<=n;++i) {
          long long value = t + val[i][0];
          if(value<=0 || value>=mini[i]) {
            r = 0;
            break;
          }
        }
      }
    } else {
      r = 0;
    }
    printf("%d\n",r);
  } else {
    long long cmini = 0, cmaxi = inf;
    for(int i=n;i;--i) {
      long long w;
      if(vis[i][0]) {
        w = val[i][0];
        //x + value[i][0] , x + w>0 && x + w < mini
        cmini = max(cmini, -w);
        cmaxi = min(mini[i]-w,cmaxi);
      } else {
        w = val[i][1];
        // -x + w, -x+w>0 && -x+w <mini
        // x -w<0 & x >-mini+w
        cmaxi = min(cmaxi, w);
        cmini = max(cmini, w -mini[i]);
      }
    }
    if(cmaxi<=1 || cmini>= cmaxi) {
      printf("0\n" );
      return;
    } else {
      printf("%lld\n", cmaxi-cmini-1);
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 17280
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int p[n];
    int problem1=0,problem2=0,problem3=0;
    for(int i=0;i<n;i++) {
        cin >> p[i];
        if(p[i] <= a) problem1++;
        else if(p[i] <= b) problem2++;
        else problem3++;
    }
    cout << min(min(problem1,problem2),problem3) << endl;;

}

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


int main()
{
  const long double PI = 3.14159265359;
  long double a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long double angle = abs(((c + (d / 60)) / 6) * PI - (d / 30) * PI);
  angle = min(angle, 2 * PI - angle);
  //cout << angle << endl;
  
  long double res = a * a + b * b;
  res -= (a * b * cos(angle)) * 2;
  res = sqrt(res);
  cout << setprecision(10) << res << endl;
  
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main(){
	
	ll X,K,Q;cin >> X >> K;
	vector<pair<ll,ll>> v;
	REP(i,K){
		ll r;cin >> r;
		v.EB(r,-1);
	}
	cin >> Q;
	REP(i,Q){
		ll a, b;cin >> a >> b;
		v.EB(a,b);
	}
	
	sort(ALL(v));
	
	ll minX = 0;
	ll minY = 0;
	ll maxX = X;
	ll maxY = X;
	ll type = -1;
	ll nowT = 0;
	
	REP(i,v.size()){
		minY += type * (v[i].FI - nowT);
		if(minY < 0){
			minX -= minY;
			minY = 0;
		}
		if(minY > X)minY = X;
		maxY += type * (v[i].FI - nowT);
		if(maxY > X){
			maxX -= (maxY - X);
			maxY = X;
		}
		if(maxY < 0)maxY = 0;
		maxX = max(maxX,minX);
		
		if(v[i].SE == -1)type = -type;
		else {
			if(v[i].SE <= minX){
				cout << minY << endl;
			}
			else if(v[i].SE < maxX){
				cout << minY + (v[i].SE - minX) << endl;
			}
			else {
				cout << maxY << endl;
			}
		}
		nowT = v[i].FI;
	}
	
	return 0;
}


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

int main() {
  std::string s;
  std::cin >> s;

  uint64_t b = 0, r = 0;
  for (const auto i : s) {
    if (i == '0') {
      r++;
    } else {
      b++;
    }
  }

  std::cout << std::min(r, b) * 2 << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    ll n;
    cin>>n;
    ll a[n];
    ll sum1=0,sum2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum1+=a[i];
    }
    ll maxv=0;
    for(int i=0;i<n;i++){
        maxv=max(maxv,a[i]);
        sum2+=maxv;
    }
    cout<<sum2-sum1<<endl;
}

Measured memory_bytes: 5212
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n + 1):
        t = str(i)
        cnt += 1 if len(t) % 2 != 0 else 0
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38768
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

x = read().rstrip().decode()[::-1]
p = 0
m = 0
for xx in x:
    if xx == 'S' and m != 0:
        m -= 1
        p += 1
    if xx == 'T':
        m += 1
print(len(x) - 2 * p)


Measured memory_bytes: 3444
def solve():
    N, M = map(int, input().split())
    S = list(input())[::-1]
    ans_l = []

    i = 0
    while i < N:
        for j in range(M, 0, -1):
            if i + j > N:
                continue
            if int(S[i+j]) == 0:
                ans_l.append(j)
                i += j
                break
            if j == 1:
                print(-1)
                exit()

    ans_l = ans_l[::-1]
    print(' '.join(map(str, ans_l)))


if __name__ == '__main__':
    solve()

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

int maxn,a[100009],n,k,g;

int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];maxn=max(maxn,a[i]);
		if(i==1) g=a[i];
		else g=__gcd(g,a[i]);
	}
	if(k%g==0 && k<=maxn) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 640
use std::io;
fn read_line()-> String {
	let mut s = String::new();
	let _ = io::stdin().read_line(&mut s).unwrap();
    	s.trim().to_string()
}
fn main() {
	let abcd = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	let a = abcd[0];
	let b = abcd[1];
	let c = abcd[2];
	let d = abcd[3];
	if ((d >= (a - c).abs()) || (d >= (a - b).abs()) && (d >= (b - c).abs())) {
		println!("Yes");
	}else{
		println!("No");
	}

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N)  for(int i = 0; i < (N); i++)
typedef long long ll;
const int MOD = 1000000007;
int n, m;
ll x[100000], y[100000];

ll xs[100000];
ll sy;
void solve(){
	ll ans = 0;
	rep(i, n - 1)
		xs[i] = ((x[i + 1] - x[i]) * (i + 1) * (n - i - 1)) % MOD;
	rep(i, m - 1)
		sy = (sy + (y[i + 1] - y[i]) * (i + 1) * (m - i - 1)) % MOD;
	rep(i, n - 1)
		ans = (ans + xs[i] * sy) % MOD;
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i, n)
		cin >> x[i];
	rep(i, m)
		cin >> y[i];
	solve();
	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if (c - a - b < 0) printf("No");
	else {
		if (4 * a * b < (c - a - b) * (c - a - b)) printf("Yes");
		else printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
    int n, a[110];
    cin >> n;
    for (int i=1; i<=n; i++){
        a[i-1] = i;
    }

    int max_count=0, max_index=1;
    int count;

    for(int j=0; j<n; j++){
        count = 0;

        while(true){
            if (a[j]%2==0){
                a[j] /= 2;
                count++;
            }
            else {
                break;
            }
            
        }
        if (max_count<count) {
            max_count = count;
            max_index = j+1;
        }
    }

    cout << max_index << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <limits>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl


using namespace std;

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template<class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
    int64_t gcd(int64_t u, int64_t v) {
        while (v != 0) {
            int64_t r = u % v;
            u = v;
            v = r;
        }
        return u;
    }
    int64_t lcm(int64_t m, int64_t n)
    {
        if ((0 == m) || (0 == n))
            return 0;

        return ((m / math::gcd(m, n)) * n);
    }
}

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

    cout << 2 * min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1')) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol a,b,c,d;
  cin >>a>>b>>c>>d;
    cout <<max(max(d*b,d*a),max(c*b,c*a))<<'\n';
  return(0);
}

Measured memory_bytes: 3644
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        break
    for i in range(a):
        for j in range(b):
            if i == 0 or j == 0 or i == a-1 or j == b-1:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()
        
    


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define fi first
#define se second
#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)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  long double a,b;
  cin >> a >> b;
  long double ans = a*b;
  ll x = ans;
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 3728
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

# aをi冊読む
sum_a = [0]*n
sum_b = [0]*m
sum_a[0] = a[0]
sum_b[0] = b[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1]+a[i]
for i in range(1, m):
    sum_b[i] = sum_b[i-1]+b[i]

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if list[high] <= item:
        return high+1
    if list[low] > item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low == 1:
            return high
        if guess > item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n):
    tmp_ans = i+1
    tmp_k = k-sum_a[i]
    # print(i, tmp_k)
    if tmp_k < 0:
        pass
    else:
        b_index = binary_search(sum_b, tmp_k)
        tmp_ans += b_index
        # print('a', i, b_index)
        if tmp_ans > ans:
            ans = tmp_ans

tmp_ans = 0
if sum_b[0] <= k:
    tmp_ans = binary_search(sum_b, k)
if tmp_ans > ans:
    ans = tmp_ans
print(ans)


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for(int i = 0; i < n; i++)
    	cin >> a[i] >> b[i] >> c[i];
  int maxi[n][3];
  maxi[0][0] = a[0];
  maxi[0][1] = b[0];
  maxi[0][2] = c[0];
  for(int i = 1; i < n; i++) {
    maxi[i][0] = max(maxi[i-1][1], maxi[i-1][2]) + a[i];
    maxi[i][1] = max(maxi[i-1][0], maxi[i-1][2]) + b[i];
    maxi[i][2] = max(maxi[i-1][0], maxi[i-1][1]) + c[i];
  }
  cout << max(max(maxi[n-1][0], maxi[n-1][1]), maxi[n-1][2]);
}

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

#define mp make_pair
#define pb push_back
#define el cout<<endl;
#define flog(n) 31-__builtin_clz((n))
#define clog(n) 32-__builtin_clz((n)-1)
#define fori(i,a,b) for(int i=(a);i<=(b);i++)
#define forib(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(n) fori(asdasdasd_RaNdOm_VaRiAbLe_NaMe_asdasdasd,1,(n))

using ui=unsigned int;
using ll=long long; using pi=pair<int,int>;
#define vec vector
using vb=vec<bool>; using vc=vec<char>; using vs=vec<string>; using vi=vec<int>; using vl=vec<ll>; using vpi=vec<pi>;
using sb=set<bool>; using sc=set<char>; using ss=set<string>; using si=set<int>; using sl=set<ll>; using spi=set<pi>;

void solve() {
    int n,m; cin>>n>>m;
    vector<vi> g(n+1);
    fori(i,1,m){
        int a,b; cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    vb vis(n+1);
    vi par(n+1);
    queue<int> q;
    q.push(1);
    vis[1]=true;
    int db=0;
    while(!q.empty()){
        db++;
        int p=q.front();
        q.pop();
        for(int i:g[p]){
            if(!vis[i]){
                vis[i]=true;
                par[i]=p;
                q.push(i);
            }
        }
    }
    if(db<n){
        cout<<"No ";
        return;
    }
    cout<<"Yes"<<endl;
    fori(i,2,n) cout<<par[i]<<endl;
}

int main() {
    if(false){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    }
    int t=1;
    //cin>>t;
    rep(t) solve();
    return 0;
}


Measured memory_bytes: 10072
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX_N = 100;

int main() {
	int N, X;
	int m[MAX_N] = {0};
	int min = 100000;
	scanf("%d %d", &N, &X);
	for (int i = 0; i < N; i++) {
		scanf("%d", &m[i]);
		X -= m[i];
		min = std::min(min, m[i]);
	}
	int sum = N;
	while (X >= min) {
		sum++;
		X -= min;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 128
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e5 + 10;
vector<pair<int,int>> graph[MAXN];
int dist[MAXN];

void dfs(int u,int p,int w){
    dist[u] = dist[p] + w;
    for(auto v:graph[u]){
        if(v.f == p) continue;
        dfs(v.f,u,v.s);
    }
}

void solve(){
    int n; cin>>n;
    FOR(i,1,n-1){
        int u,v,w; cin>>u>>v>>w;
        graph[u].push_back({v,w});
        graph[v].push_back({u,w});
    }    

    int q,s; cin>>q>>s;

    dfs(s,0,0);

    while(q--){
        int x,y; cin>>x>>y;
        cout<<dist[x] + dist[y]<<endl;
    }
}

signed main(){

   FastRead;    

    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		int sub = 1;
		int ans = 1;
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
			if(a[i]%2!=0){
				sub*=1;
			}else{
				sub*=2;
			}
			ans*=3;
		}
		System.out.println(ans - sub);
	}
}

Measured memory_bytes: 23380
def solve(N, Cs):
    dp = [-1 for _ in Cs]
    latest_c = {}
    ans = 1
    d = 10 ** 9 + 7
    for i, c in enumerate(Cs):
        if c not in latest_c:
            latest_c[c] = i
            dp[i] = ans
        else:
            previous_i = latest_c[c]
            if previous_i != i - 1:
                ans += dp[previous_i]
            latest_c[c] = i
            dp[i] = ans
    return ans % d


if __name__ == "__main__":
    N = int(input())
    Cs = [int(input()) for _ in range(N)]
    print(solve(N, Cs))


Measured memory_bytes: 760472
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=20005;

int n,a[N],sz,tim,tot,cnt,last[N*6],low[N*6],dfn[N*6],stack[N*6],bel[N*6],top,pos[N];
bool inst[N*6];
struct edge{int to,next;}e[N*300];
struct tree{int num;}t[N*5];
pair<int,int> w[N];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

void addedge(int u,int v)
{
    e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
}

void tarjan(int x)
{
    dfn[x]=low[x]=++tim;
    stack[++top]=x;inst[x]=1;
    for (int i=last[x];i;i=e[i].next)
        if (!dfn[e[i].to])
        {
            tarjan(e[i].to);
            low[x]=min(low[x],low[e[i].to]);
        }
        else if (inst[e[i].to]) low[x]=min(low[x],dfn[e[i].to]);
    if (dfn[x]==low[x])
    {
        tot++;int y=0;
        while (y!=x)
        {
            y=stack[top];top--;
            inst[y]=0;bel[y]=tot;
        }
    }
}

void build(int d,int l,int r)
{
    t[d].num=++sz;
    if (d>1) addedge(t[d/2].num,sz);
    if (l==r)
    {
        int id=w[l].second;
        id+=id<=n?n:-n;
        addedge(t[d].num,id);
        return;
    }
    int mid=(l+r)/2;
    build(d*2,l,mid);build(d*2+1,mid+1,r);
}

void ins(int d,int l,int r,int x,int y,int z)
{
    if (x>y) return;
    if (l==x&&r==y) {addedge(z,t[d].num);return;}
    int mid=(l+r)/2;
    ins(d*2,l,mid,x,min(y,mid),z);
    ins(d*2+1,mid+1,r,max(x,mid+1),y,z);
}

pair<int,int> get_lim(int x,int len)
{
    int l=1,r=x;
    pair<int,int> ans;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (w[x].first-w[mid].first<len) r=mid-1;
        else l=mid+1;
    }
    ans.first=r+1;
    l=x;r=n*2;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (w[mid].first-w[x].first<len) l=mid+1;
        else r=mid-1;
    }
    ans.second=l-1;
    return ans;
}

bool check(int len)
{
    for (int i=1;i<=n*2+n*4;i++) last[i]=low[i]=dfn[i]=0;
    sz=n*2;cnt=0;
    build(1,1,n*2);
    for (int i=1;i<=n*2;i++)
    {
        int id=w[i].second;
        pair<int,int> u=get_lim(i,len);
        ins(1,1,n*2,u.first,i-1,id);
        ins(1,1,n*2,i+1,u.second,id);
    }
    tot=tim=0;
    for (int i=1;i<=n*2;i++) if (!dfn[i]) tarjan(i);
    for (int i=1;i<=n;i++) if (bel[i]==bel[i+n]) return 0;
    return 1;
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++)
    {
        a[i]=read();a[i+n]=read();
        w[i*2-1]=make_pair(a[i],i);
        w[i*2]=make_pair(a[i+n],i+n);
    }
    sort(w+1,w+n*2+1);
    for (int i=1;i<=n*2;i++) pos[w[i].second]=i;
    int l=0,r=1000000000;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (check(mid)) l=mid+1;
        else r=mid-1;
    }
    printf("%d",l-1);
    return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18

//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;
ll mod;
ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int foo(int x)
{
	return __builtin_popcount(x);
}

int main(){

    fast;
    int T;
    T=1;
    //cin>>T;
    while(T--){
    	int n,i,j;
        cin>>n;
        string s;
        cin>>s;
        map<int,int>m;
        int mx=200005;
        for(i=0;i<=mx;i++)
        {
        	int x=foo(i);
        	int y=i;
        	int cnt=0;
        	while(y!=0)
        	{
        		y=y%foo(y);
        		cnt++;
			}
			m[i]=cnt;
		}
        int x=0;
        for(i=0;i<n;i++)
        {
        	if(s[i]=='1')
        	x++;
		}
		int y=x+1;
		int z=x-1;
		ll z1=0,y1=0;
		if(z>=1)
		{
			mod=z;
		    for(i=0;i<n;i++)
		    {
		    	if(s[i]=='1')
		    	{
		    		z1=(z1+powm(2,n-i-1))%mod;
				}
			}
		}
		mod=y;
		for(i=0;i<n;i++)
		{
			if(s[i]=='1')
			{
				y1=(y1+powm(2,n-i-1))%mod;
			}
		}
		for(i=0;i<n;i++)
		{
			if(s[i]=='0')
			{
				mod=y;
				ll q=(y1+powm(2,n-i-1))%mod;
				cout<<m[q]+1<<"\n";
			}
			else
			{
				mod=z;
				if(z>=1)
				{
					ll q=(z1-powm(2,n-i-1)+mod)%mod;
					cout<<m[q]+1<<"\n";
				}
				else
				{
					cout<<0<<"\n";
				}
			}
		}
		
		
    	

    }

}

Measured memory_bytes: 13092
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    REP(i,n){
        cin>>h[i];
    }
    sort(all(h),greater<ll>());
    ll ans=0;
    REP(i,n){
        if(k>0){
            k--;
        }
        else {
            ans+=h[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let* ((n (read))
	   (l (loop repeat n collect (read))))
  (princ (length (remove-duplicates l))))


Measured memory_bytes: 14520
#include<stdio.h>

#define  N 100

int main(){
  int M[N][N];
  int i, j, n, u, k, v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for (j = 0; j < n; j++) {
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
  for(j=0;j<k;j++){
    scanf("%d", &v);
    v--;
    M[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0){
        printf(" ");
      }
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    /**
     * Consider small intervals and evaluate them before larger intervals
     * @param a
     * @return max difference when the game is played optimally
     */
    public static long maxDiff(long[] a){
        long[][] dp = new long[a.length+1][a.length+1];
        for (int L = a.length-1; L >= 0; L--) {
            for (int R = L; R < a.length; R++) {
                if (L==R){
                    dp[L][R] = a[L];
                } else {
                    dp[L][R] = Math.max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
                }
            }
        }
        return dp[0][a.length - 1];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        StringTokenizer st = new StringTokenizer(reader.readLine());
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        System.out.println(maxDiff(a));
    }
}


Measured memory_bytes: 130004
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 3e5 + 5;
int n, a[N], s[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int check(int mid)
{
	int res = 0;
	for(int i = 1; i <= n; i ++) if(s[i] - res >= mid) res = min(res, s[i + 1]);
	return s[n] - res >= mid;
}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	if(n % 2 == 0)
	{
		int sum1 = 0, sum2 = 0;
		for(int i = 1; i <= n; i ++) if(i & 1) sum1 += a[i]; else sum2 += a[i];
		printf("%d %d\n", max(sum1, sum2), min(sum1, sum2));
	}
	else
	{
		int sum = 0;
		for(int i = 1; i <= n; i ++)
		{
			if(i & 1) s[i] = s[i - 1] + a[i];
			else s[i] = s[i - 1] - a[i];
			sum += a[i];
		}
		int l = 0, r = n * 1000, ans = 0;
		while(l <= r)
		{
			int mid = (l + r) >> 1;
			if(check(mid)) ans = mid, l = mid + 1;
			else r = mid - 1;
		}
		for(int i = 1; i <= n; i ++) if(i % 2 == 0) ans += a[i];//
		printf("%d %d\n", ans, sum - ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a,b;
char s;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>a>>s>>b;
 if(s=='+') cout<<a+b<<endl;
 else cout<<a-b<<endl;
 return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
N, K = 0, 0
H = [0]


def set_inputs():
    global N, K, H
    N, K = get_list_of_int()
    H = get_list_of_int()


def main():
    set_inputs()
    cost = [inf] * N
    cost[0] = 0
    cost[1] = abs(H[0] - H[1])
    for i in range(2, N):
        cost[i] = min(cost[i-j] + abs(H[i] - H[i-j]) if i - j >= 0 else inf for j in range(1, K+1))
    print(cost[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 57636
package main

import (
  "fmt"
  "math"
)

func main() {
  var a float64
  fmt.Scan(&a)
  var a2 = math.Pow(a,2)
  var a3 = math.Pow(a,3)
  var tmp = a + a2 + a3
  ans := int(tmp)
  fmt.Println(ans)
}

Measured memory_bytes: 1840
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int x,y;
    while(cin >> x >> y){
        if(x==0 && y==0) break;
        else{
            if(x  > y) swap(x, y);
            cout << x << " " << y << endl;
        }
    }
}



Measured memory_bytes: 3008
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
pair<ll,ll> a[55];
bool vis[55];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	sort(a,a+n);
	int ans=1000000000;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int cnt=0;
			ll p=a[j].first-a[i].first;
			ll q=a[j].second-a[i].second;
			memset(vis,0,sizeof(vis));
			for(int l=0;l<n;l++){
				if(!vis[l])cnt++;
				else continue;
				int laf=a[l].first;
				int lar=a[l].second;
				for(int o=l+1;o<n;o++){
					if(a[o].first-laf==p&&a[o].second-lar==q){
						vis[o]=1;
						laf=a[o].first;
						lar=a[o].second;
					}
				}
			}
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll t,n,m,x,y,z,i,j,k,l;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>x>>y;
	n=x*y;
	if(n%2==0) cout<<"Even\n";
	else cout<<"Odd\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

ll calc(ll a, ll b, ll p) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = calc(a, b/2, p);
        return (d * d) % p;
    } else {
        return (a * calc(a, b-1, p)) % p;
    }
}
     
int main()
{
    int a, b, c;cin >> a >> b >> c;
    cout << min(a+b, min(a+c, b+c)) << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    map<ll,ll> data;
    queue<ll> ans;
    ll n;
    cin >> n;
    ll sum = 0;
    rep(i,0,n){
        ll a;
        cin >> a;
        data[a]++;
        sum += a;
    }
    ll q;
    cin >> q;
    
    rep(i,0,q){
        ll f;
        ll s;
        cin >> f >> s;
        ll k = data[f];
        data[f]=0;
        data[s]+=k;
        sum += (s-f)*k;
        ans.push(sum);

    }
    while(!ans.empty()){
        cout<<ans.front()<<endl;
        ans.pop();
    }
    
  return 0;
}

Measured memory_bytes: 10316
import java.io.*;
 
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String str = br.readLine();
        String strArr[] = str.split(" ");
 
        int w, h, x, y, r;
 
        w = Integer.parseInt(strArr[0]);
        h = Integer.parseInt(strArr[1]);
        x = Integer.parseInt(strArr[2]);
        y = Integer.parseInt(strArr[3]);
        r = Integer.parseInt(strArr[4]);
 
        if(x+r<=w && x-r>=0 && y+r<=h && y-r>=0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 17080
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    vector<int> V(5);
    for(int i = 0; i< 5; i++){
        cin >> V.at(i);
        if(V.at(i) == 0){
            cout << i + 1 << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]
parity = (XY[0][0] + XY[0][1]) % 2
maxXY = 0
for x, y in XY:
    if (x + y) % 2 != parity:
        print("-1")
        exit()
    maxXY = max(x+y, maxXY)
arm = [1, 1, ]
if parity == 1:
    arm[1] = 2

tmp = arm[1]
m = 2

for _ in range(40):
    tmp *= 2
    m += 1
    arm.append(tmp)
    if tmp > maxXY:
        break
print(m)
print(" ".join(map(str, arm)))
armR = arm[::-1]
for x, y in XY:
    nowX, nowY = [x, y]
    ansR = ""
    for l in armR:
        if abs(nowX) >= abs(nowY):
            if nowX >= 0:
                nowX -= l
                ansR += "R"
            else:
                nowX += l
                ansR += "L"
        else:
            if nowY >= 0:
                nowY -= l
                ansR += "U"
            else:
                nowY += l
                ansR += "D"
    print(ansR[::-1])



Measured memory_bytes: 3444
package main

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

const maxBuf = 300100

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func dist(a int, b int) int {
	return int(math.Abs(float64(a - b)))
}

func main() {
	sc.Buffer(buf, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	b, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	c, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	d, _ := strconv.Atoi(sc.Text())
	if dist(a, c) <= d {
		fmt.Println("Yes")
	} else {
		if dist(a, b) <= d && dist(b, c) <= d {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 640
import scala.io.StdIn.readInt

object Main{
  def main(args: Array[String]): Unit = {
    val S = readInt
    var h = S / 3600
    var m = (S - h * 3600) / 60
    var s = S - h * 3600 - m * 60
    printf("%d:%d:%d\n", h, m, s)
  }
}

Measured memory_bytes: 43936