akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, k;
    ll x[100010];
    cin >> n >> k;
    imfor(i, n) {
        cin >> x[i];
    }
    int ans = 1<<30;
    imfor(i, n) {
        if (i + k - 1 > n - 1) {
            continue;
        }
        int tmp = 0;
        if (x[i] <= 0 && x[i + k - 1] <= 0) {
            tmp = abs(x[i]);
        }
        else if (x[i] <= 0 && x[i + k - 1] >= 0) {
            tmp = min( abs(x[i]) + 2 * abs(x[i + k - 1]) ,2 * abs(x[i]) + abs(x[i + k - 1])) ;
        }
        else {
            tmp = abs(x[i + k - 1]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b)a=b;};

template <typename T>
struct ConvexHullTrick{
  using P = pair<T,T>;
  deque<P> L;
  Int isdec;

  ConvexHullTrick():isdec(-1){}

  inline T getY(const P &a, const T &x){
    return a.first * x + a.second;
  }

  inline bool check(const P &a, const P &b, const P &c){
    return (b.first - a.first) * (c.second - b.second)
      >= (b.second - a.second) * (c.first - b.first);
  }
  inline bool empty(){return L.empty();}

  void add(T a, T b){
    //cout<<isdec<<":"<<a<<" "<<b<<endl;
    a*=-1;b*=-1;
    P line(a, b);
    if(isdec == -1 && !L.empty()){
      if(a < L[0].first) isdec = 1;
      else if(a > L[0].first) isdec = 0;
    }

    if(isdec){
      if(!L.empty() && L.back().first == a){
	line.second = min(line.second, L.back().second);
	L.pop_back();
      }
      while(L.size() >=2 && check(*prev(L.end(), 2), L.back(), line)) L.pop_back();
      L.emplace_back(line);
    } else {
      if(!L.empty() && L.front().first == a){
	line.second = min(line.second, L.front().second);
	L.pop_front();
      }
      while(L.size() >= 2 && check(L[0], L[1], line)) L.pop_front();
      L.emplace_front(line);
    }
  }

  T get(T x){
    Int low = -1, high = L.size()-1;
    while(low+1 < high){
      Int mid = (low + high) >> 1;
      if(getY(L[mid], x) >= getY(L[mid+1], x)) low = mid;
      else high = mid;
    }
    return -getY(L[high], x);
  }

  T getMonotone(T x){
    while(L.size() >= 2 && getY(L[0], x) >= getY(L[1], x)) L.pop_front();
    return -getY(L[0], x);
  }    
};

const Int MAX = 4040;
Int dp[MAX][MAX];

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


  Int n,x;
  cin>>n>>x;
  vector<Int> t(n),p(n),f(n);
  for(Int i=0;i<n;i++) cin>>t[i]>>p[i]>>f[i];

  const Int INF = 1e15;
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=-INF;
  
  using T = tuple<Int, Int, Int>;
  vector<T> vt(n);
  for(Int i=0;i<n;i++) vt[i]=T(f[i],p[i],t[i]);
  sort(vt.begin(),vt.end());
  for(Int i=0;i<n;i++) tie(f[i],p[i],t[i])=vt[i];
  //for(Int i=0;i<n;i++) cout<<f[i]<<" "<<p[i]<<" "<<t[i]<<endl;
  
  Int ans=0;
  vector<ConvexHullTrick<Int> > vh(MAX);
  
  for(Int i=0;i<n;i++){
    for(Int j=x;j>t[i];j--){
      if(vh[j-t[i]].L.empty()) continue;
      chmax(dp[i][j],vh[j-t[i]].getMonotone(f[i])+p[i]-f[i]*f[i]);
      vh[j].add(2*f[i],dp[i][j]-f[i]*f[i]);      
      chmax(ans,dp[i][j]);
    }
    chmax(dp[i][t[i]],p[i]);
    vh[t[i]].add(2*f[i],dp[i][t[i]]-f[i]*f[i]);   
    chmax(ans,dp[i][t[i]]); 
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 133836
# coding: utf-8
# Your code here!
def pattern(n,x):
    ans=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            k = x - i - j
            if i + j + k == x and max(i,j) < k <= n:
                ans += 1
                #print(i,j,k)
    return ans
Flg=True
while Flg:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    else:
        print(pattern(n,x))
    


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

int main(){
  while(1){
    int H;
    cin>>H;

    if(H==0)
      break;

    int S[10][5];
    for(int y=0; y<H; y++){
      for(int x=0; x<5; x++){
        cin>>S[y][x];
      }
    }

    int sco = 0;

    while(1){
      bool flg = false;

      for(int y=0; y<H; y++){
        int m = S[y][2];
        if(m==0)
          continue;

        if(S[y][0]==m && S[y][1]==m){
          sco+= m*3;
          S[y][0] = S[y][1] = S[y][2] =0;
          flg = true;
          if(S[y][3] == m){
            sco += m;
            S[y][3] = 0;
            if(S[y][4] == m){
              sco+=m;
              S[y][4] = 0;
            }
          }
        }
        else if(S[y][1] == m && S[y][3] == m){
          sco += m*3;
          S[y][1] = S[y][2] = S[y][3] =0;
          flg = true;
          if(S[y][4] == m){
            sco+=m;
            S[y][4] = 0;
          }
        }
        else if(S[y][3] == m && S[y][4] == m){
          sco += m*3;
          S[y][2] = S[y][3] = S[y][4] =0;
          flg = true;
        }
      }
      if(!flg)
        break;

      for(int x=0; x<5; x++){
        for(int y=H-1; y>=0; y--){
          if(S[y][x]!=0)
            continue;

          for(int y2=y-1; y2>=0; y2--){
            if(S[y2][x]!=0){
              S[y][x] = S[y2][x];
              S[y2][x] = 0;
              break;
            }
          }
        }
      }
    }
    cout<<sco<<endl;
  }
  return 0;
}



Measured memory_bytes: 3012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int d = a / b;
            int r = a % b;
            double f = (double)a / b;
            Console.WriteLine(d + " " + r + " " + f.ToString("#.####################"));
        }
    }
}


Measured memory_bytes: 19920
Module Program
  Sub Main
    Dim s=GetInts()(0)
    Dim t=GetInts()(0)
    Dim ans=s*s-t
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
#include <stdio.h>
  
int main(void) {
    int n;
    char s[300000+1];
    int min = 300000;
    int nw = 0;
    int ne = 0;

    scanf("%d%s", &n, s);

    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') nw++;
        else ne++;
    }

    int wcnt = 0;
    int ecnt = 0;
    for (int i = 0; i < n; i++) {
        if (i - 1 >= 0 && s[i - 1] == 'W') wcnt++;
        ecnt = ne - (i - wcnt) - (s[i] == 'E' ? 1 : 0);

        if (min > wcnt + ecnt) {
            min = wcnt + ecnt;
        }
    }

    printf("%d\n", min);

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_A 200000
#define MAX_N 200000
#define MAX 60

ll dp[MAX + 1][MAX_N + 1];

signed main(){
    ll n,k;
    cin >> n >> k;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }
    int nxt[MAX_A + 1];
    for(int i = 2 * n - 1; i >= 0; i--){
        dp[0][i % n] = nxt[a[i % n]] - i + 1;
        nxt[a[i % n]] = i;
    }
    for(int i = 0; i < MAX; i++){
        for(int j = 0; j < n; j++){
            dp[i + 1][j] = dp[i][j] + dp[i][(dp[i][j] + j) % n];
            dp[i + 1][j] = min(dp[i + 1][j], n * k + 1);
        }
    }
    int now = 0;
    ll sum = n * k;
    while(sum > 0){
        for(int i = MAX; i >= 0; i--){
            if(dp[i][now] < sum){
                sum -= dp[i][now];
                now = (now + dp[i][now]) % n;
                goto ok;
            }
        }
        break;
        ok:;
    }
    bool exist[MAX_A + 1] = {};
    vector<int> ans;
    for(int i = now; i < n; i++){
        if(exist[a[i]]){
            while(exist[a[i]]){
                exist[ans.back()] = false;
                ans.pop_back();
            }
        }else{
            ans.emplace_back(a[i]);
            exist[a[i]] = true;
        }
    }
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 99444
#include<iostream>

using namespace std;

int main() {
	int r, c;
	cin >> r >> c;
	int **oldTable = new int*[r];
	for (int i = 0; i < r; i++) {
		oldTable[i] = new int[c];
	}

	int **newTable = new int*[r + 1];
	for (int i = 0; i < r + 1; i++) {
		newTable[i] = new int[c + 1];
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			int temp;
			cin >> temp;
			oldTable[i][j] = temp;
		}
	}

	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			newTable[i][j] = 0;
			if (i < r&&j < c) {
				newTable[i][j] = oldTable[i][j];
			}
		}
	}

	// start computing here;
	int sum = 0;
	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			if (i == r&&j == c) {
				cout << sum;
			}else if (j == c) {
				cout << newTable[i][j];
			}
			else if (i == r) {
				cout << newTable[i][j];
				cout << ' ';
			}
			else{
				cout << newTable[i][j];
				cout << ' ';
				newTable[i][c]+= newTable[i][j];
				newTable[r][j] += newTable[i][j];
				sum += newTable[i][j];
			}

		}
		cout << endl;
	}



	for (int i = 0; i < r+1; i++) {
		delete[] newTable[i];
	}
	delete[] newTable;

	for (int i = 0; i < r; i++) {
		delete[] oldTable[i];
	}
	delete[] oldTable;
	return 0;
}

Measured memory_bytes: 3108
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
}

void insertionSort(vector<int> &A, int n, int g, int &cnt) {
    int v, j;
    rep(i, g, n) {
        v = A[i];
        j = i - g;
        while(j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> G = {1};
    while(G[0] * 3 + 1 < N) {
        G.insert(G.begin(), G[0] * 3 + 1);
    }
    int cnt = 0;
    int m = G.size();

    rep(i, m) { insertionSort(A, N, G[i], cnt); }

    cout << m << endl;
    vecout(G);
    cout << cnt << endl;
    rep(i, N) cout << A[i] << endl;
}



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

struct Node1{
  int key1;
  struct Node1 *left,*right,*parent;
};

struct Node1 *root,*NIL;

struct Node1 *find(struct Node1 *,int);
void insert (int);
void ins_order(struct Node1 *);
void pri_order(struct Node1 *);
int main(){
  int n,i,x,y;
  char order[7];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",order);
    if(strcmp(order,"find")==0){
      scanf("%d",&x);
      struct Node1 *t=find(root,x);
      if(t!=NIL){
	  printf("yes\n");
      } else printf("no\n");
    }else if(strcmp(order,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }else if(strcmp(order,"print")==0){
      ins_order(root);
      printf("\n");
      pri_order(root);
      printf("\n");
    }
  }
  return 0;
}
void insert(int a){
  struct  Node1 *x=root;
  struct Node1 *y=NIL;
  struct  Node1 *z;

  z=(struct Node1 *)malloc(sizeof(struct Node1));
  z->key1=a;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key1 < x->key1){
      x= x->left;
    }else{
      x= x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key1<y->key1){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
void ins_order(struct Node1 *u){
  if(u==NIL)return ;
  ins_order(u->left);
  printf(" %d",u->key1);
  ins_order(u->right);
}
void pri_order(struct Node1 *u){
  if(u==NIL)return ;
  printf(" %d",u->key1);
  pri_order(u->left);
  pri_order(u->right);
}
struct Node1 *find(struct Node1 *u,int k){
  while(u!=NIL && k!=u->key1){
    if(k<u->key1) u=u->left;
    else u=u->right;
  }
  return u;
}

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

int GetDigit(int64_t x){
  int cnt = 0;
  while (x > 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}

int main(){
  int64_t n;
  cin >> n;
  
  int ans = 100;

  for (int64_t i=1; i<= sqrt(n); i++){
    if (n%i == 0){
      ans = min(ans, GetDigit(n/i));
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int a;
  cin >> a;
  cout << 3*a*a << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    int N;
    bool flag = false;
    cin >> N;
    if(N % 7 == 0 || N % 4 == 0){
        flag = true;
    }
    while(N > 0){
        if(N % 4 == 0){
            flag = true;
            break;
        }
        N -= 7;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = gets.to_i
k, *a = gets.split.map(&:to_i)
(0..2**k-1).each do |b|
  s = a.select.with_index {|_, i| b[i] == 1 }
  x = s.map {|i| 1 << i }.inject(:|) || 0
  puts ("#{x}: " + s * ' ').strip
end


Measured memory_bytes: 7128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, c;

int main()
{
    cin >> a >> b >> c;
    if (b < a)
        swap(a, b);
    cout << (a < c && c < b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=1e6+777;
int flag[mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,A; cin>>N;
	for (int i=0; i<N; i++)
		cin>>A, flag[A]++;
	int ret=0;
	for (int i=1; i<mx; i++) {
		if(flag[i]) {
			if(flag[i]==1) ret++;
			for (int j=2*i; j<mx; j+=i)
				flag[j]=false;
		}
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 7556
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        s: chars,
        es: [(usize1, usize1); m],
    }

    let mut g = vec![vec![]; n];
    for (f, t) in es {
        g[f].push(t);
        g[t].push(f);
    }

    let mut enable = vec![true; n];

    for i in 0..n {
        remove(i, &g, &s, &mut enable);
    }

    // let mut ans = false;

    // for i in 0..n {
    //     if detect_loop(i, &g, &s, &mut enable) {
    //         ans = true;
    //         break;
    //     }
    // }

    let ans = enable.iter().any(|&b| b);

    println!("{}", if ans { "Yes" } else { "No" });
}

fn remove(u: usize, g: &Vec<Vec<usize>>, s: &Vec<char>, enable: &mut Vec<bool>) {
    if !enable[u] {
        return;
    }

    let ok = g[u]
        .iter()
        .map(|&v| {
            if enable[v] {
                if s[v] == 'A' {
                    1
                } else {
                    2
                }
            } else {
                0
            }
        })
        .fold(0, |l, r| l | r) == 3;

    if !ok {
        enable[u] = false;

        for &v in g[u].iter() {
            remove(v, g, s, enable);
        }
    }
}


Measured memory_bytes: 20732
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a[5];
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    sort(a, a + 5);
    for (int i = 4; i > 0; i--) {
        cout << a[i] << " ";
    }
    cout << a[0] << endl;

    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int f(int n) {
    int res = 0;
    while (n != 0) {
        n = n % __builtin_popcount(n);
        ++res;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    int popx = 0;
    rep(i, n) if (x[i] == '1') ++popx;
    vi popa(n), popb(n);
    int xi = 1;
    rep(i, n) {
        popa[i] = xi % (popx+1);
        xi = (xi * 2) % (popx+1);
    }
    if (popx-1>0) {
        xi = 1;
        rep(i, n) {
            popb[i] = xi % (popx-1);
            xi = (xi * 2) % (popx-1);
        }
    }
    int xmoda = 0, xmodb = 0;
    rep(i, n) if (x[n-i-1] == '1') {
        xmoda = (xmoda + popa[i]) % (popx+1);
        if (popx-1>0) xmodb = (xmodb + popb[i]) % (popx-1);
    }
    rep(i, n) {
        int fxi = 0;
        if (x[i] == '1') {
            if (popx-1>0) fxi = (xmodb - popb[n-i-1] + (popx-1)) % (popx-1);
            else {
                cout << 0 << endl;
                continue;
            }
        }
        else {
            fxi = (xmoda + popa[n-i-1]) % (popx+1);
        }
        cout << (1+f(fxi)) << endl;
    }
    return 0;
}


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

int main() {
    string t;
    cin >> t;
    rep(i,t.size()){
        if(t[i]=='?') t[i]='D';
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3720
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  void run() {
    for (; ; ) {
      int N, A, B, C, X;
      N = ni();
      A = ni();
      B = ni();
      C = ni();
      X = ni();

      if ( (N | A | B | C | X) == 0 ) {
        break;
      }

      int[] Y = new int[ N ];
      for ( int i = 0; i < N; ++i ) {
        Y[ i ] = ni();
      }

      int f = 0;
      for ( int i = 0; i < N; ++i ) {
        for (; ; ) {
          int X_ = ((A % C) * (X % C) + (B % C)) % C;

          if ( f > 10000 || X == Y[ i ] ) {
            X = X_;
            ++f;
            break;
          }

          X = X_;
          ++f;
        }
      }
      --f;

      System.out.println(f <= 10000 ? f : -1);
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 30400
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;

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

  std::cout << ((n>=3200)?s:"red") << std::endl;
}





Measured memory_bytes: 256
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
import sys
dxy = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = 0
            for dy,dx in dxy:
                if 0<= i+dy < H and 0 <= j+dx < W and s[i+dy][j+dx] == "#":
                    flag = 1
            if flag == 0:
                print("No")
                sys.exit(0)
print("Yes")


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

int main(){
    
    int n;
    int a[10][10][10] = {};
    cin >> n;
    
    for (int i = 0; i < n; i++)
    {
        int x, y, g, h;
        cin>>x>>y>>g>>h;
        a[x][y][g]+=h;
    }
    for(int x=1;x<5;x++){
        for (int y = 1; y < 4; y++)
        {
            for (int g = 1; g < 11; g++)
            {
                cout<< " "<<a[x][y][g];
            }
            if(x==10 && y ==3){}
            else{cout<<endl;}
        }
        if(x<4){cout<<"####################"<<endl;}
    }
    
    return 0;
}




Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
	int n,m,p,mon,pre,x,sum;
	while(cin>>n>>m>>p,n||m||p){
		pre=0;
		sum=0;
		for(int i=0;i<n;i++){
			cin>>x;
			if(i+1==m)
			pre=x;
			sum+=x;
		}
		mon=sum*(100-p);
		if(pre==0)
		cout<<0<<endl;
		else{
		mon=mon/pre;
		cout<<mon<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            p.add(sc.nextInt());
        }
        sc.close();

        Collections.sort(p);

        p.add(p.remove(n - 1) / 2);
        int ans = p.stream().mapToInt(e -> e).sum();
        System.out.println(ans);
    }

}


Measured memory_bytes: 28244
import java.util.*;
public class Main {
	
	static int G[];
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),m=in.nextInt();
		G=new int[n];
		List<List<Integer>> ls=new ArrayList<>();
		
		for(int i=0;i<n;i++) {
			ls.add(new ArrayList<>());
			G[i]=-1;
		}
		for(int i=0;i<m;i++) {
			int s=Integer.parseInt(in.next()),t=Integer.parseInt(in.next());
			ls.get(s).add(t);
			ls.get(t).add(s);
		}
		
		for(int i=0;i<n;i++) {
			if(G[i]==-1)solve(ls,i);
		}
// 		for(int i=0;i<n;i++)System.out.print(G[i]+" ");
		int q=in.nextInt();
		for(int i=0;i<q;i++) {
			int s=Integer.parseInt(in.next()),t=Integer.parseInt(in.next());
			if(G[s]==G[t])System.out.println("yes");
			else System.out.println("no");
		}
	}
	
	static void solve(List<List<Integer>> ls,int n) {
		Queue<Integer> que=new ArrayDeque<>();
		que.add(n);
		G[n]=n;
		while(!que.isEmpty()) {
			int p=que.remove();
			for(int i=0;i<ls.get(p).size();i++) {
				int next=ls.get(p).get(i);
				if(G[next]==-1) {
					G[next]=n;
					que.add(next);
				}
			}
		}
	}
}



Measured memory_bytes: 88944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
    vector<P> res;
    for (long long p = 2; p * p <= n; ++p)
    {
        if (n % p != 0)
            continue;
        int num = 0;
        while (n % p == 0)
        {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1)
        res.push_back(make_pair(n, 1));
    return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return gcd(y, x % y);
    }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i, n)
    {
        cin >> A[i];
        A[i]--;
    }
    deque<int> a;
    vector<bool> seen(n, false);
    int cur = 0;
    while(true){
        if(seen[cur]){
            while(a[0]!=cur){
                k--;
                a.pop_front();

                if (k == 0){
                    cout << a[0] + 1 << endl;
                    return 0;
                }
            }
            break;
        }
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout << a[k % a.size()] + 1 << endl;
    return 0;
}

Measured memory_bytes: 4820
#include <stdio.h>

int main(void) {
  int a, b;
  int bl = 0;
  int btmp, num, i;
  
  scanf("%d %d", &a, &b);
  btmp = b;
  while(btmp) { bl++; btmp /= 10; }
  for(i = 0; i < bl; i++) a *= 10;
  num = a + b;
  
  for(i = 1; i*i < num; i++) ;
  if(i * i == num) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

bool solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    int one = 0;
    int mmax = -inf, mmin = inf;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 1) one++;
        chmax(mmax, a[i]);
        chmin(mmin, a[i]);
    }
    
    if (one >= 2 && one != n) return 0;
    if (mmax - mmin > 1) return 0;
    
    if (mmax - mmin == 0)
    { // 差が0のケース
        // 全部帽子の色違う
        if (mmax == n - 1) return 1;
        if (n / mmax >= 2) return 1;
        return 0;
    }
    
    { // 差が1のケース
        // 低いのが1つだけ
        int cnt = 0;
        rep(i, n) if (a[i] == mmin) cnt++;
        
        // 4 3 3 3 4
        // a b c d a
        
        // 4 4 3 3 4 4
        // a b c d a b
        
        // 3って言ってるのは全部別の色
        // 残った猫の数で、残った色の数をそれぞれ2匹以上が持てるか
        if (mmax - cnt <= 0) return 0;
        if ((n - cnt) / (mmax - cnt) >= 2) return 1;
        
        return 0;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    if (solve()) out("Yes");
    else out("No");
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	int cnt = 0,cnt2 = 0,cnt4 = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x % 4 == 0) cnt4++;
		else if (x % 2 == 0) cnt2++;
		else cnt++;
	}
	//cout << cnt << endl;
	if((n / 2) <= cnt4) cout << "Yes" << endl;
	else {
		if(cnt4 >= cnt) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
#define ld long double
ld maxvolume(long double s) 
{ 
    // finding length 
    ld length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    ld breadth = s / 2; 
  
    // finding height 
    ld height = s - breadth; 
  
    return length * breadth * height; 
} 
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    ld l;
    cin>>l;
    ld ans = maxvolume(l);
    cout<<fixed<<setprecision(11)<<ans<<"\n";
    }
    return 0;
}

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

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


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

int main(){
  int N; cin >> N;
  int L[10];
  for(int i=0; i<N; i++) cin >> L[i];
  sort(L,L+N);
  int sum=0;
  for(int i=0; i<N-1; i++) sum+=L[i];
  cout << ((L[N-1]<sum)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
import sys
n = int(input())
a = [int(input()) for i in range(n)]
x = 0
cnt = 0
l = [False] * n
while x != 1:
    l[x] = True
    x = a[x]-1
    cnt += 1
    if l[x]:
        print(-1)
        sys.exit()
print(cnt)

Measured memory_bytes: 13776
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i > 0: plus.append(i)
    if i < 0: minus.append(i)

ans = 1
if k > len(plus) + len(minus):
    ans = 0
elif len(minus) == 0:
    plus.sort(reverse=True)
    for i in range(k):
        ans = (ans * plus[i]) % mod
elif len(plus) == 0:
    if k % 2 == 0:
        minus.sort()
        for i in range(k):
            ans = (ans * minus[i]) % mod
    else:
        if n != len(minus):
            ans = 0
        else:
            minus.sort(reverse=True)
            for i in range(k):
                ans = (ans * minus[i]) % mod
elif k == len(plus) + len(minus) and (len(minus) % 2) == 1:
    if n != len(plus) + len(minus):
        ans = 0
    else:
        for x in plus:
            ans = (ans * x) % mod
        for y in minus:
            ans = (ans * y) % mod
else:
    plus.sort(reverse=True)
    minus.sort()
    i, j = 0, 0
    if k % 2 == 1:
        ans = plus[0]
        i = 1
    while i + j < k:
        tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else 1
        tmp_m = minus[j] * minus[j + 1] if j <= len(minus) - 2 else 1
        if tmp_p >= tmp_m:
            ans = (ans * (tmp_p % mod)) % mod
            i += 2
        else:
            ans = (ans * (tmp_m % mod)) % mod
            j += 2
print(ans)


Measured memory_bytes: 31740
import sys

class modNumber:
    prime = 10**9 + 7
    def __init__(self, num):
        self.num = num % modNumber.prime

    def __add__(self, other):
        if type(other) is int:
            return modNumber(self.num + other)
        return modNumber(self.num + other.num)

    def __sub__(self, other):
        if type(other) is int:
            return modNumber(self.num - other)
        return modNumber(self.num - other.num)

    def __mul__(self, other):
        if type(other) is int:
            return modNumber(self.num * other)
        return modNumber(self.num*other.num)

    def __truediv__(self, other):
        if type(other) is int:
            return modNumber(self.num + modNumber(other).reciprocal())
        return (self*other.reciprocal())

    def __pow__(self, power, modulo=None):
        if type(power) is int:
            answer = 1
            base = self.num
            while True:
                if power == 0:
                    return modNumber(answer)
                elif power%2 == 0:
                    power = power//2
                    base = base*base % modNumber.prime
                else:
                    power = power // 2
                    answer = answer * base % modNumber.prime
                    base = base*base % modNumber.prime
        return self.num.__pow__(power)

    def __str__(self):
        return str(self.num)

    def __int__(self):
        return self.num

    def reciprocal(self):
        ans = modNumber(1)
        buffer = modNumber(self.num)
        exp = modNumber.prime - 2
        while exp:
            if exp & 1:
                ans = ans * buffer
            buffer = buffer * buffer
            exp = exp >> 1
        return ans

if __name__ == '__main__':
    n, a, b = map(int, input().split())

    total = modNumber(2)**n - 1
    # a を引く
    denom = modNumber(1)  # 分母
    numer = modNumber(1)  # 分子
    for i in range(1, a+1):
        denom = denom*i
    for i in range(n-a+1, n+1):
        numer = numer*i
    total -= numer/denom
    # b を引く
    denom = modNumber(1)  # 分母
    numer = modNumber(1)  # 分子
    for i in range(1, b+1):
        denom = denom*i
    for i in range(n-b+1, n+1):
        numer = numer*i
    total -= numer/denom


    print(total)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll d, g;
    cin >> d >> g;
    vll p(d), c(d);
    REP(i, d) cin >> p[i] >> c[i];
    ll ans = 1e15, res, num;
    for(int i = 0; i < (1<<d); i++){
        res = 0, num = 0;
        vll last(d, 0);
        REP(j, d){
            if((i>>j)&1){
                num += p[j];
                res += p[j] * 100 * (j + 1) + c[j];
            }
            else last[j] = 1;
        }
        if(res >= g){
            ans = min(ans, num);
            continue;
        }
        ll rest = g - res;
        REP(j, d){
            if(last[j] && (p[j] - 1) * 100 * (j + 1) >= rest){
                ans = min(ans, num + 1 + (rest - 1) / (100 * (j + 1)));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>vec(10001,0);
  int num=0;
  int sum=0;
  
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      cin>>vec[num];
      num++;
    }
  }
  
  sort(vec.begin(),vec.end());
  for(int i=1;i<10001;i++){
    if(vec[i]>0 && vec[i]!=vec[i-1])sum++;
  }
  
  cout<<n-sum<<endl;
}

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

int main() {
  int n; cin >> n;
  int a[n]; REP(i,n) cin >> a[i];
  int cur = 0;
  REP(i,n) {
    if (a[cur] == 2) { cout << i+1 << endl; return 0; }
    cur = a[cur]-1;
  }
  cout << -1 << endl;
  return 0;
}

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

int main() {
  string str;
  cin >> str;
  int count = 0;
  for (int i = 0;i < 3;i++) {
    if (str.at(i) == '1') {
      count++;
    }
  }
  cout << count <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define fi first
#define se second
int n,m;
vector<int> tmp;
vector<pair<int,int> > vp;
priority_queue<int> pq;
signed main(){
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i ++){
		int x; cin >> x;
		pq.push(-x);
	}
	while(m --){
		int b,c;
		cin >> b >> c;
		vp.push_back({c, b});
	}
	sort(vp.begin(), vp.end());
	for(int i = vp.size() - 1 ; i >= 0 ; i --){
		if(tmp.size() == n) break;
		int rem = n - tmp.size();
		for(int j = 1 ; j <= min(rem, vp[i].se) ; j ++) 
			tmp.push_back(vp[i].fi);
	}
	for(int u: tmp){
		int cur = -pq.top();
		if(cur < u){
			pq.pop();
			pq.push(-u);
		}
	}
	int sum = 0;
	while(pq.size()){
		sum -= pq.top();
		pq.pop();
	}
	cout << sum;
}


Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(5e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int ans = IINF;
    string s;
    cin >> s;
    REP(i,s.size()-2){
        ans = min(ans,abs(753-stoi(s.substr(i,3))));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

int a[111111], b[111111], c[111111];
int N;
int deg[111111];
int ans[111111];

vector<int> path[111111];
set<pii> dlist;

void solve() {
  cin>>N;
  for (int i=0;i<N-1;i++){
  	cin>>a[i]>>b[i];
  	a[i]--;
  	b[i]--;
  	deg[a[i]]++;
  	deg[b[i]]++;
  	path[a[i]].PB(b[i]);
  	path[b[i]].PB(a[i]);

  }
  for (int i=0;i<N;i++) cin>>c[i];
  sort(c, c+N);
  // reverse(c, c+N);

  for (int i=0;i<N;i++){
  	dlist.insert(MP(deg[i], i));
  }
  int j = 0;
  while (dlist.size() > 0) {
  	pii largest = *dlist.begin();
  	int node = largest.second;
    
    deg[node] = 0;
    ans[node] = c[j++];
  	//remove
  	dlist.erase(largest);

   for (int v: path[node]){
     if (deg[v] == 0) continue;
     dlist.erase(MP(deg[v], v));
     deg[v]--;
     dlist.insert(MP(deg[v], v));
   }
  }
  long long tot = 0;
  for (int i=0;i<N-1;i++){
  	tot += min(ans[a[i]], ans[b[i]]);
  }

  cout<<tot<<endl;
  cout<<ans[0];
  for (int i=1;i<N;i++) {
    cout<<" "<<ans[i];
  }
  cout<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 5248
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef pair<int, pair<int, pair<int, int>>> PP;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;

const long long INF = 1LL << 60;
const int inf = 1e9;
const long long MOD = 1e9+7;

int main() {
	int n;
	cin >> n;
	vec a(n + 1, 0), b(n + 1, 0), c(n), d(n);
	rep(i, n) {
		int k;
		cin >> k;
		a[k]++;
	}
	rep(i, n) {
		int k;
		cin >> k;
		c[i] = k;
		b[k]++;
	}
	rep(i, n) {
		a[i + 1] += a[i];
		b[i + 1] += b[i];
	}
	bool f = 0;
	rep(i, n) {
		if (a[i + 1] - a[i] + b[i + 1] - b[i] >= n + 1)f = 1;
	}
	if (f) {
		cout << "No" << endl;
		return 0;
	}
	int t = 0;
	repd(i,1, 1+n) {
		t = max(t, a[i] - b[i - 1]);
	}
	cout << "Yes" << endl;
	rep(i, n) {
		d[(i + t) % n] = c[i];
	}
	rep(i, n)cout << d[i] << " ";
	return 0;
}

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

int a[200010];
int main(){
  int N;
  cin>>N;
  
  int A[N+1];
  int minus[N+1]={0},plus[N+1]={0};
  
  long long int ans=0;
  for(int i=0;i<N;i++)cin>>A[i];
  //for(int i=0;i<N;i++)scanf("%d",a+i);
  for(int i=0;i<N;i++){
    if(i+A[i]<=N)ans+=minus[i+A[i]];
    
    if(i-A[i]>=0)ans+=plus[i-A[i]];
    
    if(i+A[i]<=N)plus[i+A[i]]++;
    if(i-A[i]>=0)minus[i-A[i]]++;
    
    
  }
  cout<<ans<<endl;
  

}

Measured memory_bytes: 5984
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  string S;
  cin >> S;
  int L=S.length();
  int ans=0;
  for(int i=1;i<L;i++){
    if(S[i]==S[i-1]){
      if(S[i]=='0') S[i]='1';
      else S[i]='0';
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int ans = r * r;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=60,mod=1000000007;
typedef long long ll;
int dp[2][N][N],T,n,ans,inv[N],jc2[N];
inline void upd(int&x,const int&y){x+=y-mod;x+=x>>31&mod;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;	
	dp[0][1][0]=1;jc2[0]=jc2[1]=1;inv[1]=1;
	for(int i=2;i<=n;++i){
		dp[0][1][0]=(ll)dp[0][1][0]*i%mod;
		inv[i]=mod-mod/i*(ll)inv[mod%i]%mod;
		jc2[i]=(ll)jc2[i-1]*inv[i]%mod;
	}
	dp[0][1][1]=dp[0][1][0];upd(ans,dp[T][n][0]);
	for(int i=1;i<n;++i){
		T^=1;memset(dp[T],0,sizeof dp[T]);
		for(int j=1;j<n;++j)
			for(int k=0;k<=j;++k)if(dp[!T][j][k])
				for(int l=k;l<=n-j;l+=2)if(l)
					for(int r=0;r<=l;++r)
						upd(dp[T][j+l][abs((k+l)/2-r)],(ll)dp[!T][j][k]*jc2[r]%mod*jc2[l-r]%mod);
		upd(ans,dp[T][n][0]);
	}
	cout<<ans<<'\n';
	return 0;
}


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

typedef pair<int, int> pi;

vector<pi> edges;
vector<pi> copy1;

int main()
{
    int n;
    cin >> n;
    for (int i = 3; i <= n; i++)
    {
        if (i % 2 == 1)
        {
            for (int j = 1; j < i; j++)
            {
                edges.push_back(pi(j, i));
            }
        }
        else
        {
            copy1 = vector<pi>();
            for (pi p : edges)
            {
                copy1.push_back(pi(p.first + 1, p.second + 1));
            }
            for (int j = 2; j < i; j++)
            {
                copy1.push_back(pi(1, j));
            }
            edges = copy1;
        }
    }
    cout << edges.size() << endl;
    for (pi p : edges)
    {
        cout << p.first << " " << p.second << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

string cmp(string a,string b){
    if(a.size()==b.size())return a<b?b:a;
    else return a.size()<b.size()?b:a;
}

int main(){
	int w,h;
	while(cin>>w>>h,w){
	    string ans="";
	    vector<vs> v(h+2,vs(w+2,""));
	    range(i,1,h+1)range(j,1,w+1){
	        cin>>setw(1)>>v[i][j];
	        if(!isdigit(v[i][j][0])) v[i][j]="";
	        else v[i][j]=cmp(v[i-1][j],v[i][j-1])+v[i][j];
	        if(v[i][j][0]=='0')v[i][j]=v[i][j].substr(1);
	        ans=cmp(ans,v[i][j]);
	    }
	    cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3308