akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n, k;
    cin >> n >> k;

    deque<int> dq;
    for(int i = 0; i < n; i++){
        int v; cin >> v;
        dq.push_back(v);
    }

    ll ans = -INF;
    for(int i = 0; i <= min(n, k); i++){
        for(int j = 0; j <= min(n, k); j++){
            if(i + j > min(n, k)) continue;
            
            deque<int> tdq = dq;
            priority_queue<int, vector<int>, greater<int>> nn;
            ll tmpans = 0;

            for(int k = 0; k < i; k++){
                int tmp = tdq.front();
                tdq.pop_front();
                if(tmp < 0){
                    nn.push(tmp);
                } else {
                    tmpans += tmp;
                }
            }

            for(int k = 0; k < j; k++){
                int tmp = tdq.back();
                tdq.pop_back();
                if(tmp < 0){
                    nn.push(tmp);
                } else {
                    tmpans += tmp;
                }
            }

            int rest = k - (i + j);

            for(int k = 0; k < rest; k++){
                if(nn.empty()) break;
                nn.pop();
            }

            while(!nn.empty()){
                tmpans += nn.top();
                nn.pop();
            }
            ans = max(ans, tmpans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
S = list(input())
C_cnt = 0

if S[0] != "A":
    print("WA")
    sys.exit()
else:
    S.pop(0)

if str.isupper(S[0]) == True or  str.isupper(S[-1]) == True:
    print("WA")
    sys.exit()
else:
    S.pop(0)
    S.pop(-1)

for i in S:
    if i == "C":
        C_cnt += 1
    elif i != "C" and str.isupper(i) == True:
        print("WA")
        sys.exit()

if C_cnt == 1:
    print("AC")
else:
    print("WA")

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

int main() {
  int n, y;
  cin >> n >> y;

  for (int i = 0; i*1000 <= y; i++) {
    for (int j = 0; j*5000 <= y; j++) {
      if (i+j > n) continue;
      if (1000*i+5000*j+10000*(n-i-j) == y) {
        cout << n-i-j << " " << j << " " << i << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

from copy import deepcopy

c = deepcopy(b)

ans = 0

if sum(a) < sum(b):
    print(-1)
    sys.exit()

diff = 0
ad = []

for i, j in zip(a, b):
    if i == j:
        pass
    elif i > j:
        ad.append(i - j)
    else:
        diff += (j - i)
        ans += 1

ad.sort()

while diff > 0:
    diff -= ad.pop()
    ans += 1

print(ans)
        


Measured memory_bytes: 100272
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
int pr[2000000];

//素因数分解。O(√n)。
map<int,int> prime_factor(int m){
  map<int,int> rtn;
  for(int i=2;i*i<=m;i++){
    while(!(m%i)){
      ++rtn[i];
      m/=i;
    }
  }
  if(m!=1) rtn[m]=1;
  return rtn;
}

int main(){
  int n;cin>>n;

  REP(i,2000000) pr[i]=0;

  REP(i,n){
    int tmp;cin>>tmp;
    map<int,int> mp=prime_factor(tmp);
    for(auto p:mp){
      pr[p.first]++;
      //cout<<p.first<<"^"<<p.second<<" ";
    }
  }
 
  REP(i,2000000) if(pr[i]==n){
    cout<<"not coprime"<<endl;
    return 0;
  }

  REP(i,2000000){
    if(pr[i]>1){
      cout<<"setwise coprime"<<endl;
      return 0;
    }
  }

  cout<<"pairwise coprime"<<endl;
  return 0;
}

Measured memory_bytes: 11432
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		B[i] = A[i]
	}
	sort.Ints(B)
	for i := 0; i < N; i++ {
		if A[i] == B[N-1] {
			fmt.Fprint(out, B[N-2], "\n")
		} else {
			fmt.Fprint(out, B[N-1], "\n")
		}
	}
}

func solve(N int, a []int, used []int, s2, x1, x2, depth int) bool {
	// fmt.Fprint(out, used, depth, x1, x2, "\n")
	if depth == N {
		// fmt.Fprint(out, "atta\n")
		return x1^x2^a[0] == 0 && x2^a[0]^s2 == 0
	}
	for i := 0; i < N; i++ {
		if used[i] > 0 {
			continue
		}
		if depth >= 2 && x1^x2^a[i] != 0 {
			continue
		}
		used[i] = 1
		if depth == 1 {
			s2 = a[i]
		}
		if solve(N, a, used, s2, x2, a[i], depth+1) {
			return true
		}
		used[i] = 0
	}
	return false
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


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

const int max_N = 55;

using LL = long long;

int n, m;

LL dp[max_N][max_N * max_N];

int main() {
    scanf("%d%d", &n, &m);
    dp[0][0] = 1;
    for (int i = 1, a; i <= n; ++i) {
        scanf("%d", &a);
        for (int j = i; j; --j) {
            for (int k = a; k <= i * 50; ++k) {
                dp[j][k] += dp[j - 1][k - a];
            }
        }
    }
    LL ans = 0;
    for (int j = 1, k = 0; j <= n; ++j) {
        ans += dp[j][k += m];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

typedef pair<int, int> P;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    sort(a.begin(), a.end(), greater<>());
    ll N = a[0];
    ll mid = (N+2-1)/2;
    ll absR = LINF;
    ll R = 0;
    for (int i = 1; i < n; ++i) {
        if (absR > abs(a[i]-mid)) {
            R = a[i];
            absR = abs(a[i]-mid);
        }
    }
    cout << N << " " << R << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll k; cin >> n >> k;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  auto bsearch = [&]() {
    auto test = [&](ll t) {
      ll need = 0;
      rep(i, n) need += (A[i]+t-1)/t-1;
      return need <= k;
    };
    ll ok = *max_element(all(A)), ng = 0;
    while(ok-ng > 1) {
      ll mid = (ok+ng)/2;
      (test(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << bsearch() << endk;
  return 0;
}


Measured memory_bytes: 4760
/* In the name of Allah */

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

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define LL_INF 1LL << 62
#define INF 1 << 30
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
#define mod 1000000007

int n, w;

ll x[105], y[105];
ll dp[105][100005];

ll solve(int pos, int rem){
  if(rem < 0) return -LL_INF;
  if(pos >= n) return 0;

  if(dp[pos][rem] != -1) return dp[pos][rem];

  ll res = -LL_INF;
  res = max(res, solve(pos+1, rem));
  res = max(res, y[pos]+solve(pos+1, rem-x[pos]));
  
  return dp[pos][rem] = res;
}

int main()
{
  memset(dp, -1, sizeof dp);
  cin >> n >> w;
  for(int i = 0; i < n; i++)
    cin >> x[i] >> y[i];

  cout << solve(0, w) << "\n";

  return 0;
}

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

#define N 100
#define MAX 10000;

int main(void) {
    int n;
    int A[N][N];
    int min1, min2; //最小値の重みをもつ要素の添え字,min1は行,min2は列
    bool check[N]; //通ったらtrue
    int check_num[N]; //通った頂点の添え字
    int count; //通った頂点の数
    int weight;
    
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> A[i][j];
            if(A[i][j] == -1) A[i][j] = MAX;
        }
    }
    
    for(int i = 0; i < n; ++i) check[i] = false;
    
    //スタートは0
    check[0] = true;
    check_num[0] = 0;
    count = 1;
    weight = 0;
    while(count < n) {
        min1 = check_num[0];
        min2 = check_num[0];
        for(int i = 0; i < count; ++i) {
            for(int j = 0; j < n; ++j) {
                if(A[check_num[i]][j] < A[min1][min2] && !check[j]) {
                    min1 = check_num[i];
                    min2 = j;
                }
            }
        }
        weight += A[min1][min2];
        check[min2] = true;
        check_num[count] = min2;
        ++count;
    }
    
    cout << weight << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 50; int n;
const ldouble EPS = 1e-12;

struct Point
{
  ldouble x, y;
  Point operator+(const Point &other) { return Point{x + other.x, y + other.y}; }
  Point operator-(const Point &other) { return Point{x - other.x, y - other.y}; }
  Point operator*(const ldouble a) { return Point{x * a, y * a}; }
  ldouble operator*(const Point &other) { return x * other.x + y * other.y; }
  ldouble distance(Point &p) { return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  ldouble cross(Point &other) { return x*other.y - y*other.x; }
  void normalize()
  {
    double norm = sqrt(x*x + y*y);
    x /= norm, y /= norm;
  }
  Point pointOfInterception(Point &p1, Point &p2)
  {
    Point v = p2 - p1, u = p1 - *this, w = p2 - *this;
    double vu = v * u, vv = v * v;
    double t = -vu / vv;
    // return pointBetween(t, p1, p2); if it's a line and not a segment
    if (t >= 0 && t <= 1) return vectorToSegment(t, p1, p2);
    return u*u <= w*w ? p1 : p2;
  }
  bool ccw(Point &B, Point &C)
  {
    return (C.y - this->y) * (B.x - this->x) > (B.y - this->y) * (C.x - this->x);
  }
  Point vectorToSegment(double t, Point &p1, Point &p2)
  {
    return Point({(1 - t) * p1.x + t * p2.x,
                  (1 - t) * p1.y + t * p2.y});
  }
  void print() { printf("%.4Lf %.4Lf\n", x, y); }
};
vector<Point> points;

struct Circle
{
  Point center; ldouble radious;
  bool contains(Point &p) { return center.distance(p) <= radious + EPS; }
};

Circle circumCircle(Point &a, Point &b, Point &c)
{
  Point u = Point{(b - a).y, (a - b).x};
  Point v = Point{(c - a).y, (a - c).x};
  Point n = (c - b) * 0.5;
  ldouble t = u.cross(n) / v.cross(u);
  Point center = ((a + c)*0.5) + v*t;
  return Circle{center, center.distance(a)};
}

Circle minimumCircle(vector<Point> &p)
{
  random_shuffle(p.begin(), p.end());
  Circle circle = Circle{p[0], 0};
  for (int i = 0; i < p.size(); i ++)
  {
    if (circle.contains(p[i])) continue;
    circle = Circle{p[i], 0};
    for (int j = 0; j < i; j ++)
    {
      if (circle.contains(p[j])) continue;
      circle = Circle{(p[j] + p[i])*0.5, p[j].distance(p[i])*0.5};
      for (int k = 0; k < j; k ++)
      {
        if (circle.contains(p[k])) continue;
        circle = circumCircle(p[j], p[i], p[k]);
      }
    }
  }
  return circle;
}

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    points.resize(n);
    for (int i = 0; i < n; i ++)
      scanf("%Lf %Lf", &points[i].x, &points[i].y);

    Circle circle = minimumCircle(points);
    printf("%.15Lf\n", circle.radious);
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
t,a = (int(i) for i in input().split())
x = [t-int(i)*0.006 for i in input().split()]
m = float("inf")
for i in range(n):
	if m>abs(a-x[i]): m,k = abs(a-x[i]),i+1
print(k)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
ld dp[3000][3000]={},h[3000]{};
void solve()
{
    int n,k=1,m=0,i=1,j,x,y,l,r,p,q,z;
    ld ans=0;
    cin>>n;
    for(i=1;i<=n;i++) cin>> h[i];
    dp[0][0]=1;
    for(i=1;i<=n;i++)
    {
        for(int heads=0;heads<=i;heads++)
        {
            if(heads)
            dp[i][heads]=dp[i-1][heads-1]*h[i];
            dp[i][heads]+=dp[i-1][heads]*(1-h[i]);
        }
    }
    for(i=(n+1)/2;i<=n;i++)
    ans+=dp[n][i];
    cout<<fixed<<setprecision(15)<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 85736
#include <stdio.h>

int main()
{
  int a, b;
  int s[13] = {-1,1,0,1,2,1,2,1,1,2,1,2,1};

  scanf("%d%d", &a, &b);

  printf("%s\n", s[a] == s[b] ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll N,M,L,R; cin >> N >> M;
  ll lb = 0, rb = N;
  for (ll i = 0; i < M; ++i) {
  	cin >> L >> R;
    lb = max(lb,L);
    rb = min(rb,R);
  }
  if (rb >= lb) cout << rb+1-lb << endl;
  else cout << 0 << endl;
  return 0;
}


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

int top = 0; // 最後の要素の位置
int S[1000]; // Stackのデータ

// topにxを追加する
void push(int x){
  // topを加算してからSのその位置へ挿入
  top++;
  S[top] = x;
}

// topから要素を取り出す
int pop(){
  //topが指していた要素を返す
  int res = S[top];
  top--;
  return res;
}

int main(){
  // 読み込んだ1シンボル(オペランドや演算子)
  char s[100];
  // 計算する時に一時的に使う変数
  int a,b;

  // スペースまで読む．
  // sには12などのオペランドや+などの演算子が入る
  while(cin>>s){
    if(s[0] == '+'){
        a = pop();
        b = pop();
        push(a+b);
    }
    else if(s[0] == '-'){
        b = pop();
        a = pop();
        push(a-b);
    }
    else if(s[0] == '*'){
        a = pop();
        b = pop();
        push(a*b);
    }
    else{
      push(atoi(s));
    }
  }

  // 最後の1シンボルが計算結果になる
  cout << pop() << endl;
  return 0;
}



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

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<int>> a(H,vector<int>(W));
    for ( int i = 0; i < H; ++i){
        for ( int j = 0; j < W; ++j){
            cin >> a[i][j];
        }
    }
    
    vector<vector<int>> ans;
    for ( int i = 0; i < H; ++i){
        if ( i % 2 == 0 ){
            for ( int j = 0; j < W; ++j){
                if ( a[i][j] % 2 != 0 ){
                    if ( j == W - 1 and i == H - 1 ) break;
                    else if ( j == W - 1 ){
                        a[i][j] = a[i][j] - 1;
                        a[i+1][j] = a[i+1][j] + 1;
                        vector<int> sub = {i,j,i+1,j};
                        ans.push_back(sub);
                    } else {
                        a[i][j] = a[i][j] - 1;
                        a[i][j+1] = a[i][j+1] + 1;
                        vector<int> sub = {i,j,i,j+1};
                        ans.push_back(sub);
                    }
                }
            }
        } else {
            for ( int j = W-1; j >= 0; --j){
                if ( a[i][j] % 2 != 0 ) {
                    if ( j == 0 and i == H - 1 ) break;
                    else if ( j == 0 ) {
                        a[i][j] = a[i][j] - 1;
                        a[i+1][j] = a[i+1][j] + 1;
                        vector<int> sub = {i,j,i+1,j};
                        ans.push_back(sub);
                    } else {
                        a[i][j] = a[i][j] - 1;
                        a[i][j-1] = a[i][j-1] + 1;
                        vector<int> sub = {i,j,i,j-1};
                        ans.push_back(sub);
                    }
                }
            }
        }
    }
    
    int N = ans.size();
    cout << N << endl;
    for ( int i = 0; i < N; ++i){
        cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2]+1 << " " << ans[i][3]+1 << endl;
    }
    
    return 0;
}


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


using namespace std;

int main()
{
    int a[4],i;
    for(i=0;i<3;i++)
        cin >> a[i];
    sort(a,a+3);
    int sum = 0 ;
    for(i=1;i<3;i++)
        sum += (a[i]-a[i-1]);
    cout << sum ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n), b;
    rep(i,n) cin >> a[i];
    if(n%2){
        ll tmp = n-1;
        while(tmp>=0){
            b.push_back(a[tmp]);
            tmp -= 2;
        }
        ll tmp2 = 1;
        while(tmp2<=n-2){
            b.push_back(a[tmp2]);
            tmp2 += 2;
        }
    }else{
        ll tmp = n-1;
        while(tmp>=1){
            b.push_back(a[tmp]);
            tmp -= 2;
        }
        ll tmp2 = 0;
        while(tmp2<=n-2){
            b.push_back(a[tmp2]);
            tmp2 += 2;
        }
    }
    rep(i,n){
        cout << b[i];
        if(i != n-1) cout << ' ';
        else cout << endl;
    }
    return 0;
}

Measured memory_bytes: 6924
X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
SUM=[]
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)<=K:
        SUM.append(A[i]+B[j]+C[k])
      else:
        break
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

Measured memory_bytes: 8708
/*
  Lower bound: first element that is greater-or-equal.
  int i=lower_bound(a,a+n,x)-a;
  Upper bound: first element that is strictly greater.
  #include<boost/multiprecision/cpp_int.hpp>
  namespace mp=boost::multiprecision;
  mp::cpp_int u=1; for(unsigned i=1;i<=n;i++) u*=i;
*/
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
const int WASTE=(int)2e5;
int power(int a,int b,int m=mod){
	if(b == 0) return 1;
	if(b == 1) return a;
	int x = power(a,b/2,m)%m;
	x = (x*x)%m;
	if(b%2) return (x*a)%m;
	return x;
}
//#define int long long
const int N=1e5+5;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    cout<<24+(24-n);
    return 0;	
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int A=sc.nextInt();
    int B=sc.nextInt();
    int C=sc.nextInt();
    if((A==B)&&
      (A==C)){System.out.println("No");}
    else if((((!(A==B))&&
            (!(B==C)))&&
            (!(C==A)))){System.out.println("No");}
    else{System.out.println("Yes");}
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < 3; ++i) ans += s[i] == t[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
import collections, numbers
import random

def compute(array, window, maximize):
    if not isinstance(window, numbers.Integral):
        raise TypeError()
    if not isinstance(maximize, bool):
        raise TypeError()
    if window <= 0:
        raise ValueError("Window size must be positive")

    result = []
    deque = collections.deque()
    for i, val in enumerate(array):
        val = array[i]
        while len(deque) > 0 and ((not maximize and val < deque[-1]) or (maximize and val > deque[-1])):
            deque.pop()
        deque.append(val)

        j = i + 1 - window
        if j >= 0:
            result.append(deque[0])
            if array[j] == deque[0]:
                deque.popleft()
    return result


if __name__ == "__main__":
    n, l = (int(x) for x in input().split())
    array = list((int(x) for x in input().split()))

    answer = compute(array, l, False)
    print(*answer)



Measured memory_bytes: 122036
const MOD: usize = 1_000_000_007;

struct Combination {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
}

impl Combination {
    fn new(n: usize) -> Combination {
        let mut fact = vec![0; n + 1];
        let mut inv_fact = vec![0; n + 1];
        fact[0] = 1;
        for i in 1..=n {
            fact[i] = fact[i - 1] * i % MOD;
        }
        inv_fact[n] = Self::pow(fact[n], MOD - 2);
        for i in (1..=n).rev() {
            inv_fact[i - 1] = inv_fact[i] * i % MOD;
        }

        Combination { fact, inv_fact }
    }

    fn pow(mut a: usize, mut n: usize) -> usize {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % MOD;
            }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    }
    
    fn c(&self, n: usize, r: usize) -> usize {
        if n < r { return 0; }
        let tmp = self.inv_fact[n - r] * self.inv_fact[r] % MOD;
        self.fact[n] * tmp % MOD
    }

    fn f(&self, r: usize, c: usize) -> usize {
        self.c(r + c, r)
    }

    fn g(&self, r: usize, c: usize) -> usize {
        self.f(r + 1, c + 1) - 1
    }
}

fn main() {
    let (r1, c1, r2, c2): (usize, usize, usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let comb = Combination::new(r2 + c2 + 2);
    let mut ans = comb.g(r2, c2);
    ans = (ans + MOD - comb.g(r2, c1 - 1)) % MOD;
    ans = (ans + MOD - comb.g(r1 - 1, c2)) % MOD;
    ans = (ans + comb.g(r1 - 1, c1 - 1)) % MOD;
    println!("{}", ans);
}

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

int main () {
  int n;
  cin >> n;
  int cnt = 0;
  int maxnum = 0;
  for (int i = 1; i <= n; i++) {
    int temp = i;
    int tempcnt = 0;
    while (temp % 2 == 0) {
      tempcnt++;
      temp /= 2;
    }
    if (max(cnt, tempcnt) == tempcnt) {
      cnt = tempcnt;
      maxnum = i;
    }
  }
  cout << maxnum << endl;
}

Measured memory_bytes: 256
s = str(input())

def count1(str):
    count = 0
    for i in range(len(str)):
        x = str[i]
        if i%2==0:
            if x!='0':
                count += 1
        else:
            if x!='1':
                count += 1

    return count

def count2(str):
    count = 0
    for i in range(len(str)):
        x = str[i]
        if i%2==0:
            if x!='1':
                count += 1
        else:
            if x!='0':
                count += 1

    return count

answer = min(count1(s),count2(s))
print(answer)

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int D;
vector<int> c(26);
vector<int> last(26, 0);
vector<vector<int>> s(365, vector<int>(26));
void input();
int score;
int next_num;
const int Way = 26;
const int Nest = 0;
/*void dfs(int nest, int d) {
	int M = 0, temp = score;
	int prev, n;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp;
		score += s[d - 1][j];
		prev = last[j];
		last[j] = d;
		rep(k, 0, 26)score -= c[k] * (d - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
		last[j] = prev;
	}
	//sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way) {
		//prev = last[kouho[j].second];
		//last[kouho[j].second] = d;
		score = kouho[j].first;
		if (nest && d < D)dfs(nest - 1, d + 1);
		if (M < score)M = score, n = kouho[j].second;
		printf("j:%2d score:%d\n", j, score);
		//last[kouho[j].second] = prev;
	}
	score = M;
	next_num = n;
}*/
int dfs(int i) {
	ll M = 0, temp = score;
	int prev, p;
	rep(j, 0, 26) {
		score = temp + s[i - 1][j];
		prev = last[j];
		last[j] = i;
		rep(k, 0, 26)score -= c[k] * (i - last[k]);
		last[j] = prev;
		if (M < score)M = score, p = j;
	}
	last[p] = i;
	score = M;
	return p;
}
int main()
{
	input();
	/*rep(i, 1, D + 1) {
		//score = 0;
		dfs(Nest, i);
		printf("%d\n", next_num + 1);
		last[next_num] = i;
		printf("%d\n", score);
	}*/
	rep(i, 1, D + 1) {
		printf("%d\n", dfs(i) + 1);
		//printf("%d\n", score);
	}
	return 0;
}
void input() {
	cin >> D;
	rep(i, 0, 26)cin >> c[i];
	rep(i, 0, D) {
		rep(i2, 0, 26)cin >> s[i][i2];
	}
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
//#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,inf=1e9+10,mod=1e9+7,M2=1e6+10,M3=3e3+10;
int l[M],r[M],q[M],d[M];
vector<int>adj[M],edg[M],adj2[M],edg2[M];
bool mark[M];
int cur[M];
void dfs(int v)
{
	mark[v]=1;
	for(int i=0;i<adj[v].size();i++)
	{
		int u=adj[v][i];
		if(mark[u] && cur[u]!=edg[v][i]+cur[v])
		{
			cout<<"No";
			exit(0);
		}
		if(!mark[u])cur[u]=cur[v]+edg[v][i],dfs(u);
	}
}
main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)scanf("%d%d%d",&l[i],&r[i],&d[i]),adj[l[i]].pb(r[i]),adj[r[i]].pb(l[i]),edg[l[i]].pb(d[i]),edg[r[i]].pb(-d[i]);	
	int tail=0,head=0;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(!mark[i])dfs(i);
	}
	cout<<"Yes";
}

Measured memory_bytes: 33664
#include <bits/stdc++.h>
using namespace std;
using edge= pair<int64_t, int>;
using Graph= vector<vector<edge>>;

void solve(const Graph &gph, int s, vector<int64_t> *dists){
  using path= edge;

  priority_queue<path, vector<path>, greater<path>> search;
  search.push(make_pair(0, s));
  while( !search.empty() ){
    int64_t d_tmp; int from_tmp;
    tie(d_tmp, from_tmp)= search.top();
    search.pop();

    if(dists->at(from_tmp) <= d_tmp){ continue; }
    else{
      dists->at(from_tmp)= d_tmp;
      for(auto e:gph.at(from_tmp)){
        int64_t d_to; int to_tmp;
        tie(d_to, to_tmp)= e;
        search.push(make_pair(d_tmp+ d_to, to_tmp));
      }
    }
  }
}

int main(){
  int N;
  cin >> N;
  const int M= N-1;

  Graph gph(N);
  int v1,v2; int64_t w;
  for(int i=0; i<M; i++){
    cin >> v1 >> v2 >> w;
    v1--; v2--; // 1-indexed -> 0-indexed

    gph.at(v1).emplace_back(make_pair(w, v2));
    gph.at(v2).emplace_back(make_pair(w, v1));
  }

  int Q,K;
  cin >> Q >> K;
  K--; // 1-indexed -> 0-indexed

  vector<int64_t> dists(N, INT64_MAX);
  solve(gph, K, &dists);

  for(int i=0; i<Q; i++){
    cin >> v1 >> v2;
    v1--; v2--; // 1-indexed -> 0-indexed

    cout << dists.at(v1)+ dists.at(v2) << endl;
  }
}

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

int main() {
  
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;

  if (L > R) {
    cout << "Left" << endl;
  }
  else if(L == R){
    cout << "Balanced" << endl;
  }
  else{
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;
const int INF = 3e18;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

int n, t[1010], a[1010];
int nowt, nowa;
signed main()
{
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> t[i] >> a[i];
  }

  nowt = t[0], nowa = a[0];
  
  for(int i = 1; i < n; i++){
    int times = max(nowt / t[i] + !!(nowt % t[i]), nowa / a[i] + !!(nowa % a[i]));
    nowt = t[i] * times, nowa = a[i] * times;
  }

  cout << nowt + nowa << endl;
  return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  rep(i,0,n) cin>>h[i];
  int dp[n];
  rep(i,0,n) dp[i]=1e9;
  dp[0]=0;
  rep(i,1,n){
    rep(j,1,k+1){
      if(j<=i){
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
      }
    }
  }
  cout<<dp[n-1]<<endl;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

const ll MOD = 1e+9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    
    ll sum = A[0];
    ll ans = 0;
    for ( int i = 1; i < N; ++i){
        ans = ( ans + sum * A[i] ) % MOD;
        sum = ( sum + A[i] ) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

#define MAX_NODE 10000
#define INF 1000000000

using namespace std;

struct Edge {
	int to, w;
};
typedef pair<int, int> P;

vector<Edge> adj[MAX_NODE];
int d[MAX_NODE];

void dijkstra(int n, int start) {
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d, d + n, INF);
	d[start] = 0;
	que.push({0, start});

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)
			continue;
		for (int i = 0; i < adj[v].size(); i++) {
			Edge e = adj[v][i];
			if (d[e.to] > d[v] + e.w) {
				d[e.to] = d[v] + e.w;
				que.push({d[e.to], e.to});
			}
		}
	}
}

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		while (k--) {
			int v, c;
			cin >> v >> c;
			adj[u].push_back({v, c});
		}
	}

	dijkstra(n, 0);

	for (int i = 0; i < n; i++)
		cout << i << " " << d[i] << endl;

	return 0;
}

Measured memory_bytes: 6308
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int>v(n);
  for(int i; i<n; i++) cin >> v[i];
  vector<int>c(n);
  for(int i; i<n; i++) cin >> c[i];
  int r=0;
  for(int i; i<n; i++){
    if(v[i]>=c[i]) r += v[i]-c[i];
  }
  cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    ll d, t, s; cin >> d >> t >> s;
    if (d<=t*s) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	string str;
	int alp[26] = {};
	while (getline(cin, str))
	{
		for (int i = 0, l = str.size(); i < l; i++)
		{
			if (str[i] >= 'a'&&str[i] <= 'z')
			{
				alp[str[i] - 'a']++;
			}
			else if (str[i] >= 'A'&&str[i] <= 'Z')
			{
				alp[str[i] - 'A']++;
			}
		}
	}
	for (int i = 0; i < 26; i++)
	{
		printf("%c : %d\n", i + 'a', alp[i]);
	}
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;

const int maxn = (1 << 15) + 5;
const int mod = 998244353;

inline int power(int x, int p) {
	int res = 1;
	while (p) {
		if (p & 1) 
			res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		p >>= 1;
	}
	return res;
}

namespace NTT {
	const int G = 3;
	int g[maxn], R[maxn], a[maxn], b[maxn];
	int n, L, tmp;
	
	void ntt(int a[], int n, int flag) {
		rep (i, 0, n - 1)
			if (i < R[i]) swap(a[i], a[R[i]]);
				
		for (int d = 1, t = n >> 1; d < n; d <<= 1, t >>= 1)
			for (int i = 0; i < n; i += (d << 1))
				for (int j = 0; j < d; j++) {
					tmp = 1ll * g[!flag ? t*j : n - t*j] 
							  * a[i+j+d] % mod;
					a[i+j+d] = a[i+j] - tmp;
					if (a[i+j+d] < 0) a[i+j+d] += mod;
					a[i+j] = a[i+j] + tmp;
					if (a[i+j] >= mod) a[i+j] -= mod;
				}
		
		if (!flag) return;
		
		int rev = power(n, mod - 2);
		rep (i, 0, n - 1)
			a[i] = 1ll * a[i] * rev % mod;
	}
	
	void mul(int n, int N, int A[], int B[], int C[]) {
		rep (i, 0, N - 1) a[i] = A[i];
		rep (i, N, n - 1) a[i] = 0;
		rep (i, 0, N - 1) b[i] = B[i];
		rep (i, N, n - 1) b[i] = 0;
			
		ntt(a, n, 0);
		ntt(b, n, 0);
		
		rep (i, 0, n - 1)
			a[i] = 1ll * a[i] * b[i] % mod;
			
		ntt(a, n, 1);
		
		rep (i, 0, N - 1) C[i] = a[i];
		rep (i, N, n - 1) C[i] = 0;
	}
	
	void solve(int N, int x[], int p, int res[]) {
		for (n = 1; n <= 2 * N + 1; n <<= 1, L++);
		rep (i, 0, n - 1)
			R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
		g[0] = g[n] = 1;
		g[1] = power(G, (mod - 1) / n);
		rep (i, 2, n - 1)
			g[i] = 1ll * g[i-1] * g[1] % mod;
		
		res[0] = 1;
		while (p) {
			if (p & 1) mul(n, N, res, x, res);
			mul(n, N, x, x, x);	p >>= 1;
		}
	}
}

char s[maxn], t[maxn];
int A[maxn], B[maxn], fac[maxn], rev[maxn];
int n, x, y, ans;

int main() {
	scanf("%s%s", s + 1, t + 1);
	n = strlen(s + 1);
	
	fac[0] = 1;
	rep (i, 1, n + 1) 
		fac[i] = 1ll * fac[i-1] * i % mod;
	rev[n+1] = power(fac[n+1], mod - 2);
	per (i, n, 0)
		rev[i] = 1ll * rev[i+1] * (i + 1) % mod;
	
	rep (i, 1, n)
		if (s[i] == '1' && t[i] == '1') x++;
		else if (s[i] == '1' && t[i] == '0') y++;
			
	rep (i, 0, x) A[i] = rev[i+1];
	NTT::solve(x + 1, A, y, B);
	
	rep (i, 0, x) {
		ans = ans + B[i];
		if (ans >= mod) ans -= mod;
	}
	
	ans = 1ll * ans * fac[x] % mod;
	ans = 1ll * ans * fac[y] % mod;
	ans = 1ll * ans * fac[x+y] % mod;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define I int
#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define P(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB(a) push_back(a)
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define ll long long 
using namespace std;
#define mx 500004
#define md 1000000007ll
typedef pair<int, int >P;
typedef vector<ll>V;

////////define value/////
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}

int main(){
int n,m;
    cin>>n>>m;
    double res =0;
    for(int i=1;i<=n;i++){

        int cnt =0;
        for(int j =i;j<m;j*=2)cnt++;
        double am = 1;
        for(int j=1;j<=cnt;j++)am*=.5;
        double sum = (am)/(double)n;
        res+=sum;
    }
    printf("%.10lf\n",res);
   //cout<<res<<endl;

    return 0;
}


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

int main() {
  int N,D;
  cin >> N >> D;
  vector<vector<int>> data(N, vector<int>(D));
  for(int i = 0; i <N; i++){
    for(int j = 0; j <D; j++){
      cin >> data.at(i).at(j);
    }
  }
  int ans = 0;
  for(int i = 0; i<N;i++){
   for(int j = i+1; j <N; j++){
     int norm = 0;
  for(int k = 0; k < D;k++){
   int diff = abs(data.at(i).at(k) - data.at(j).at(k));
    norm += diff * diff;
  }
     bool flag = false;
     for(int K =0; K<=norm;K++){
     if(K*K == norm) {
       flag = true;
       break;
     }
     }
     if(flag) ans++;
   }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#include <array>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__)
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
template <typename T>
vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}
template <typename T>
map<T, int> prime_factor(T n) {
    map<T, int> res;
    for (T i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n]++;
    }
    return res;
}
template <typename T>
T gcd(T a, T b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);
    cout << a <<" " << b << " " << c << endl;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[5050];

ll i, j, k, ans;

const ll b1 = 1009, b2 = 1007, m1 = 1000000007, m2 = 1000000009;
vector<pll> hashh;
vector<ll> hpow1, hpow2;
void createHash(){
    hashh.resize(N + 5);
    hpow1.resize(N + 5);
    hpow2.resize(N + 5);
    hpow1[0] = 1;
    hpow2[0] = 1;
    ll i = 0, a = 0, b = 0;
    fornum(i,0,N){
        a = (S[i] + a) * b1 % m1;
        b = (S[i] + b) * b2 % m2;
        hashh[i + 1] = {a, b};
        hpow1[i + 1] = hpow1[i] * b1 % m1;
        hpow2[i + 1] = hpow2[i] * b2 % m2;
    }
}
pll getHash(ll l,ll r){
    ll a = (hashh[r].first - hashh[l].first * hpow1[r - l] % m1 + m1) % m1;
    ll b = (hashh[r].second - hashh[l].second * hpow2[r - l] % m2 + m2) % m2;
    return {a, b};
}

bool bs(ll a){
    if(a==0)
        return true;
    ll i = 0;
    set<pll> st;
    fornum(i,a,N){
        if(i+a>N)
            break;
        st.insert(getHash(i - a, i));
        auto h = getHash(i, i + a);
        if(st.count(h))
            return true;
    }
    return false;
}
int main(){
    scanf("%lld%s", &N, S);

    createHash();
    
    ll l = 0, r = N;
    while(l<r){
        ll c = (l + r + 1) / 2;
        if(bs(c)){
            l = c;
        }else{
            r = c - 1;
        }
    }
    printf("%lld", l);
    return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int s[n];
  for (int i=0; i<n; i++) cin>>s[i];
  int sum = 0;
  for (int i=0; i<n; i++) sum += s[i];
  if (sum % 10 != 0) {
    cout<<sum<<endl;
  } else {
    sort(s, s+n);
    for (int i=0; i<n; i++) {
      if (s[i] % 10 != 0) {
        cout<<sum-s[i]<<endl;
        return 0;
      }
    }
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]
dp = [[0]*(W+1) for i in range(N+1)]
cnt = [[0]*(W+1) for i in range(N+1)]
a = []
b = []

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    a.append(A)
    b.append(B)

for n in range(1,N+1):
    for w in range(1,W+1):
        if  w-a[n-1] >= 0:
            
            dp[n][w] = max(dp[n-1][w],dp[n-1][w-a[n-1]]+b[n-1])
            
            if dp[n-1][w] >= dp[n-1][w-a[n-1]]+b[n-1]:
                cnt[n][w] = cnt[n-1][w]
            else:
                cnt[n][w] = cnt[n-1][w-a[n-1]] + 1
                
        dp[n][w] = max(dp[n-1][w],dp[n][w])
        if dp[n][w] == dp[n-1][w]:
            cnt[n][w] = cnt[n-1][w]
        #cnt[n][w] = cnt[n-1][w]

print(dp[N][W])

Measured memory_bytes: 193944
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,A,B = inpl()
S = input()
tmp = 1
tmpf = 1

for s in S:
	if s == 'a':
		if tmp <= A+B:
			print('Yes')
			tmp += 1
		else:
			print('No')
	elif s == 'b':
		if tmp <= A+B and tmpf <= B:
			print('Yes')
			tmpf += 1
			tmp += 1
		else:
			print('No')
	else:
		print('No')


Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B and A != C) or (A == C and A != B) or (B == C and A != B))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn=500005;
const int maxq=500005;
const int maxm=500005;
int n,sqr,Q;
int a[maxn];
struct query{
	int l,r,lb,pos;
}q[maxq]; 
bool cmp(query a,query b){
	if(a.lb==b.lb)return a.lb&1?a.r>b.r:a.r<b.r;
	return a.lb<b.lb;
}
int ans[maxq],num[maxm],cnt;
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
inline void write(int x){
	if(x/10)write(x/10);
	putchar(x%10+'0');
}
void solve(){
	int l=1,r=0;
	for(int i=1;i<=Q;++i){
		while(r<q[i].r)cnt+=!num[a[++r]]++;
		while(r>q[i].r)cnt-=!--num[a[r--]];
		while(l>q[i].l)cnt+=!num[a[--l]]++;
		while(l<q[i].l)cnt-=!--num[a[l++]];
		ans[q[i].pos]=cnt;
	}
	for(int i=1;i<=Q;++i)write(ans[i]),puts("");
}
int main(){
	n=read();Q=read();
	for(int i=0;i<n;++i)a[i]=read();
	sqr=sqrt(n)+1;
	for(int i=1;i<=Q;++i){
		q[i].l=read();q[i].r=read();
		--q[i].l;--q[i].r;q[i].pos=i;
		q[i].lb=q[i].l/sqr;
	}
	sort(q+1,q+Q+1,cmp);
	solve();
	return 0;
}


Measured memory_bytes: 17416
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var n, x int
	fmt.Scan(&n, &x)
	var a, b int
	a = nextInt()
	sum := 0
	if a > x {
		sum += a - x
		a = x
	}
	for i := 1; i < n; i++ {
		b = nextInt()
		if a+b > x {
			sum += a + b - x
			b = x - a
		}
		a = b
	}

	fmt.Println(sum)
}


Measured memory_bytes: 2304