akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nr;
            while (!(nr = readNums()).SequenceEqual(new int[] { 0, 0 }))
            {
                var cards = Enumerable.Range(1, nr[0]).Reverse().ToArray();
                foreach (var pc in new int[nr[1]].Select(_ => readNums()))
                {
                    var ncards = new int[nr[0]];
                    for (int i = 0; i < pc[1]; ncards[i] = cards[pc[0] - 1 + i], i++) ;
                    for (int i = 0; i < pc[0] - 1; ncards[pc[1] + i] = cards[i], i++) ;
                    for (int i = pc.Sum() - 1; i < cards.Length; ncards[i] = cards[i], i++) ;

                    cards = ncards;
                }
                Console.WriteLine(cards.First());
            }
        }
        
        static int[] readNums()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
    }
}

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

string grid[8];
int m,posx,posy;

void cookie(int y,int x,char t){
  int dx[] = {0,1,1,1,0,-1,-1,-1},dy[] = {1,1,-1,0,-1,1,-1,0};
  int ans = 0;

  for(int i=0;i<8;i++){
    int sx = x,sy = y;
    int tmp = -1;
    while(1){
      sx += dx[i],sy += dy[i];
      tmp++;
      if(sx<0 || sy<0 || sx>=8 || sy>=8)break;
      if(grid[sy][sx] == t || grid[sy][sx] == '.')break;
    }
    if(sx<0 || sy<0 || sx>=8 || sy>=8)continue;
    if(grid[sy][sx] == t)ans += tmp;
  }
  if(ans>m){
    m = ans;
    posx = x;
    posy = y;
  }
}

void change(int y, int x,char t){
  grid[y][x] = t;
  int dx[] = {0,1,1,1,0,-1,-1,-1},dy[] = {1,1,-1,0,-1,1,-1,0};
  for(int i=0;i<8;i++){
    int sx = x,sy = y;
    while(1){
      sx += dx[i],sy += dy[i];
      if(sx<0 || sy<0 || sx>=8 || sy>=8)break;
      if(grid[sy][sx] == t || grid[sy][sx] == '.')break;
    }
    if(sx<0 || sy<0 || sx>=8 || sy>=8)continue;
    if(grid[sy][sx] == t){
      sx = x,sy = y;
      while(1){
	sx += dx[i],sy += dy[i];
	if(sx<0 || sy<0 || sx>=8 || sy>=8)break;
	if(grid[sy][sx] == t || grid[sy][sx] == '.')break;
	grid[sy][sx] = t;
      }
    } 
  }
}

int main(){
  for(int i=0;i<8;i++)cin >> grid[i];
  while(1){
    bool f = false;
    m = 0;
    posx = posy = -1;
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
	if(grid[i][j]=='.')cookie(i,j,'o');
      }
    }
    if(m>0){
      f = true;
      change(posy,posx,'o');
    }

    m = 0;
    posx = posy = -1;
    for(int i=7;i>=0;i--){
      for(int j=7;j>=0;j--){
	if(grid[i][j]=='.')cookie(i,j,'x');
      }
    }
    if(m>0){
      f=true;
      change(posy,posx,'x');
    }

    if(!f)break;
  }

  for(int i=0;i<8;i++)cout << grid[i] << endl;
}

Measured memory_bytes: 0
import math
from decimal import Decimal
from collections import deque
def main():
    a,b,c = tuple([int(t)for t in input().split()])

    a,b,c = Decimal(a),Decimal(b),Decimal(c)
    print("Yes" if a.sqrt()+b.sqrt()<c.sqrt() else "No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 5332
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    string s; cin >> s;
    int n = s.size();
    if (s[n-1] == 's') s += "es";
    else s += "s";
    cout << s << endl;
}

Measured memory_bytes: 3632
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec; 
#define INF LLONG_MAX
 
#define P pair<ll,ll>
 
#define PP pair<int,int>
#define pb push_back
 
#define ff first
#define ss second
 
#define int long long int
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define N 200005
#define MOD 1000000007


signed main()
{
      FAST;
      
      ll n;
      string s;
      ll ans=0;
      
      ll f[10]={0};
      cin>>n>>s;
            
      for(int i=0;i<=999;i++)
      {
            string p=to_string(i);
            while(p.size()!=3)
                  p='0'+p;
            
            ll k=0;
            for(int j=0;j<n;j++)
            {
                  if(s[j]==p[k])
                        k++;
                  if(k==3)
                  {
                        ans++;
                        break;
                  }
            }
      }
      
      cout<<ans<<"\n";
      
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#define MAX_S 3010
#define MAX_T 3010

using namespace std;

int dp[MAX_S][MAX_T];

int main(){
  string s,t,ans="";
  cin >> s >> t;
  for(int i=0;i < MAX_S;i++){
    for(int j=0;j < MAX_T;j++){
      dp[i][j] = 0;
    }
  }
  for(int i=0;i <= s.size();i++){
    for(int j=0;j <= t.size();j++){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      }else{
        dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  int S = (int)s.size(),T = (int)t.size();
  while(S > 0 && T > 0){
    if(dp[S][T] == dp[S-1][T]) S--;
    else if(dp[S][T] == dp[S][T-1]) T--;
    else{
      ans = s[S-1] + ans;
      S--;T--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 39044
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt(), n = scanner.nextInt();
			Set<Integer> set = IntStream.range(0, n).map(i -> scanner.nextInt()).boxed().collect(Collectors.toSet());
			int diff = 0;
			while (true) {
				if (!set.contains(x - diff)) {
					System.out.println(x - diff);
					break;
				}
				if (!set.contains(x + diff)) {
					System.out.println(x + diff);
					break;
				}
				diff++;
			}
		}
	}
}


Measured memory_bytes: 36508
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    int x;
    cin >> x;
    cout << x * x * x << endl;
}


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

#define int long long
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 memo[200010][5][2];
int a[200010];

int dp(int i, int cnt, int num){
	if(num == 0) return 0;
	if(memo[i][cnt][num == 0] != LLONG_MIN) return memo[i][cnt][num == 0];

	int ans = dp(i+2, cnt, num-1) + a[i];
	if(cnt > 0){
		ans = max(ans, dp(i+1, cnt-1, num));
	}

	return memo[i][cnt][num == 0] = ans;
}

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

	for(int i = 0;i < n;i++) cin >> a[i];

	for(int i = 0;i < 200010;i++){
		for(int j = 0;j < 5;j++){
			memo[i][j][0] = memo[i][j][1] = LLONG_MIN;
		}
	}

	if(n % 2 == 0){
		cout << dp(0, 1, n/2) << endl;
	}else{
		cout << dp(0, 2, n/2) << endl;
	}

	return 0;
}


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

#define ll long long int

using namespace std;

int main() {
    ll n, w;
    cin >> n >> w;
    int a;
    ll ks[n + 1][2] = {0};
    for (ll i = 1 ; i <= n ; i++) cin >> ks[i][0] >> ks[i][1];
    ll dp[n + 1][w + 1];
    for (ll i = 0 ; i <= n ; i++) dp[i][0] = 0;
    for (ll i = 1 ; i <= w ; i++) dp[0][i] = 0;
    for (ll i = 1 ; i <= n ; i++) {
        for (ll j = 1 ; j <= w ; j++) {
            if (ks[i][0] > j) {
                dp[i][j] = dp[i-1][j];
                a = 0;
            } else {
                dp[i][j] = max(ks[i][1] + dp[i - 1][j - ks[i][0]], dp[i - 1][j]);
                a = 0;
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;

}

Measured memory_bytes: 79104
T={?M=>0,?A=>1,?R=>2,?C=>3,?H=>4}
a=[0]*5
gets.to_i.times{
	c=gets[0]
	T[c]&&a[T[c]]+=1
}
p a.combination(3).map{|x,y,z|x*y*z}.reduce(:+)

Measured memory_bytes: 1788
import math
INF = 2_000_000_001
L, R = list(map(int, input().split()))
if math.ceil(L / 2019) <= R // 2019:
    print(0)
else:
    res = INF
    for i in range(L % 2019, R % 2019):
        for j in range(L % 2019 + 1, R % 2019 + 1):
            res = min(res, (i * j) % 2019)
    print(res)


Measured memory_bytes: 8896
#include<iostream>
using namespace std;
bool b[1001];
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (int i = 0; i <= n; i++) {
			b[i] = true;
		}
		int a = 1, d = n;
		while (d > 1) {
			int c = 1;
			while (c < m) {
				if (b[a]) {
					c++;
				}
				a++;
				if (a >= n + 1)
					a = 1;
			}
			while (b[a] == false) {
				a++;
				if (a >= n + 1) a = 1;
			}
			b[a] = false;
			d--;
		}
		for (int i = 1; i <= n; i++) {
			if (b[i]) {
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3080
//
//  main.cpp
//  A
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//
//  CF Handle : 2017_Scayre_TBIL_777
//
//  ARSEN TOKSYN ZVER UUUU!!!!
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define ll long long
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf 1e9 + 7;

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp make_pair

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)

#define endl "\n"

#define in(x) insert(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)

#define all(x) x.begin(),x.end()

using namespace std;

ll a,b,c;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
 * 整数同士の割り算は整数に丸められるのでdoubleでキャストする
*/

/* ===== コーナーケースに気をつけろ ===== */

int main()
{
    ll N, K;
    cin >> N >> K;
    if (N < abs(N-K)) {
        cout << N << endl;
    } else {
        if (N % K < abs((N%K) - K)) {
            cout << N % K << endl;
        } else {
            cout << abs((N % K) - K) << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b) \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define debug(x) cout << #x << ": " << x << endl
#define debig_vec(v)                    \
  cout << #v << ":";                    \
  rep(i, v.size()) cout << " " << v[i]; \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  if (A1 + A2 + A3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

  return 0;
}


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


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  int a=0;
  cin>>M>>N;
  for (int i = 0; i < N; i++) {
    int b=0;
    cin >> b;
    a=a+b;
  }
  if(a>M){
    cout << -1 <<endl;
  }else{
    cout << M-a <<endl;
  }
}




Measured memory_bytes: 3648
import sys

S = str(input())
if len(S) == 1:
  print("0")
  sys.exit()
else:
  c1 = 0
  c2 = 0
  for i in range(len(S)):
    if i%2 == 0:
      if S[i] != "1":
        c1 += 1
    else:
      if S[i] != "0":
        c1 += 1
  for i in range(len(S)):
    if i%2 == 0:
      if S[i] != "0":
        c2 += 1
    else:
      if S[i] != "1":
        c2 += 1
print(min(c1,c2))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int A,B;
    cin >> A >> B;
    if(A <= 2 * B)cout << 0 << endl;
    else cout << A - 2*B << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define ll long long 

using namespace std;


int main() {
	ll n;

	cin >> n;

	ll count = 0;

	while(count * (count + 1LL) / 2LL < n) {
		count++;
	}

	ll total = n;

	vector<ll> ans;

	for (ll i = count; i > 0; i--) {
		if (total >= i) {
			total -= i;
			ans.push_back(i);
		}
	}

	for (ll a : ans) {
		cout << a << endl;
	}

	return 0;
}

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

int main() {
  int A, B;
  scanf("%d%d", &A, &B);
  if (A == 1) A = 14;
  if (B == 1) B = 14;

  if (A > B) {
    printf("Alice");
  } else if (A == B) {
    printf("Draw");
  } else {
    printf("Bob");
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (auto& i : H)
        cin >> i;

    double MIN = 99999.0;
    int index;
    for (int i = 0; i < N; i++) {
        const double cur = fabs(1.0 * A - (T - H[i] * 0.006));
        if (MIN > cur) {
            MIN   = cur;
            index = i;
        }
    }

    cout << index + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    colors = [0] * 9
    for aa in a:
        index = -1
        for i in range(8):
            if 400 * i <= aa < 400 * (i + 1):
                index = i
        colors[index] += 1
    answer = 0
    for i in range(8):
        if colors[i] > 0:
            answer += 1
    print(max(answer, 1), answer + colors[-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main() {
  int N;cin >> N;
  vll x(N),y(N);
  int id_xmin=0,id_ymax=0;
  repeat(i,N){
    cin >> x[i] >> y[i];
    if(x[i] > y[i]) swap(x[i],y[i]);
    if(x[id_xmin]>x[i] || ( x[id_xmin]==x[i] && id_xmin==id_ymax )){
      id_xmin = i;
    }
    if(y[id_ymax]<y[i]){
      id_ymax = i;
    }
  }
  ll Rmax = y[id_ymax];
  ll Rmin = y[id_xmin];
  ll Bmax = x[id_ymax];
  ll Bmin = x[id_xmin];
  ll ans=0;
  repeat(i,N){
    if(i==id_xmin || i==id_ymax) continue;
    if(Rmin > y[i]){
      Rmin = y[i];
    }
    if(Bmax < x[i]){
      Bmax = x[i];
    }
  }
  ans = (Rmax-Rmin)*(Bmax-Bmin);
  if(id_xmin != id_ymax){
    Rmax = y[id_ymax];
    Rmin = x[id_xmin];
    Bmax = max(x[id_ymax],y[id_xmin]);
    Bmin = min(x[id_ymax],y[id_xmin]);
    repeat(i,N){
      if(i==id_xmin || i==id_ymax) continue;
      if((Bmin <= x[i] && x[i] <= Bmax)||(Bmin <= y[i] && y[i] <= Bmax)) continue;
      if(Bmax<x[i]) Bmax = x[i];
      else if(y[i]<Bmin) Bmin = y[i];
    }
    vint rest;
    repeat(i,N){
      if(i==id_xmin || i==id_ymax) continue;
      if((Bmin <= x[i] && x[i] <= Bmax)||(Bmin <= y[i] && y[i] <= Bmax)) continue;
      rest.push_back(i);
    }
    if(rest.size()){
      ll restxmin=INF,restymax=0;
      for(int r:rest){
        restxmin = min(restxmin,x[r]);
        restymax = max(restymax,y[r]);
      }
      if(Bmin-restxmin<restymax-Bmax) Bmin = restxmin;
      else Bmax = restymax;
    }
    ans = min(ans,(Rmax-Rmin)*(Bmax-Bmin));
  }
  cout << ans << endl;
  return 0;
}


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

#define Int register int
#define INF 0x3f3f3f3f
#define MAXN 100005

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

int n,val[MAXN],tong[16],f[1 << 16];

int count (int S){//统计S中1的个数
	int sum = 0;
	for (Int i = 0;(1 << i) <= S;++ i) sum += (S >> i & 1); 
	return sum;
}

int Sum (int S){
	int sum = 0;
	for (Int i = 0;(1 << i) <= S;++ i) if (S >> i & 1) sum ^= i;
	return sum;
} 

signed main(){
	read (n);
	for (Int i = 2,u,v,w;i <= n;++ i) read (u,v,w),val[u] ^= w,val[v] ^= w;
	int tot = 0;
	for (Int i = 0;i < n;++ i) tong[val[i]] ++;
	for (Int i = 1;i <= 15;++ i) if (tong[i] & 1) tot += (tong[i] - 1) / 2,tong[i] = 1;else tot += tong[i] / 2,tong[i] = 0;
	int up = 1 << 16;
	for (Int S = 1;S < up;++ S) f[S] = Sum (S) != 0 ? INF : count (S) - 1;
	for (Int S = 1;S < up;++ S)
		for (Int T = (S - 1) & S;T;T = (T - 1) & S)
			f[S] = min (f[S],f[T] + f[S ^ T]);
	int now = 0;
	for (Int i = 1;i <= 15;++ i) if (tong[i]) now |= 1 << i;
	write (f[now] + tot),putchar ('\n');
	return 0;
}

Measured memory_bytes: 4284
#include <iostream>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))

int bestW = 0;
int bestS = 0;

int A, B, C, D, E, F;

int maxS;

void check(int W, int S) {
  if (W * E >= S * 100) {
    if (W + S == 0) return;
    if (W * E < 100 * S) return;
    if (bestS * (W + S) <= S * (bestW + bestS)) {
      bestW = W;
      bestS = S;
    }
  }
}
void op1(int W, int S);

void op4(int W, int S) {
  for (int i = 0;; i++) {
    int nextS = S + D * i;
    if (nextS > maxS) break;
    op1(W, nextS);
  }
}

void op3(int W, int S) {
  for (int i = 0;; i++) {
    int nextS = S + C * i;
    if (nextS > maxS) break;
    op4(W, nextS);
  }
}

void op2(int W, int S) {
  for (int i = 0;; i++) {
    int nextW = W + 100 * B * i;
    if (nextW + S > F) break;
    check(nextW, S);
  }
}

void op1(int W, int S) {
  for (int i = 0;; i++) {
    int nextW = W + 100 * A * i;
    if (nextW + S > F) break;
    op2(nextW, S);
  }
}

int main(int argc, char *argv[]) {
  std::cin >> A >> B >> C >> D >> E >> F;

  maxS = F * E / (100 + E) + 10;

  op3(0, 0);

  std::cout << bestW + bestS << " " << bestS << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void read() {}
template<class T, class... Arg>
void read(T &x, Arg&&... args) {
	cin >> x;
	read(args...);
}
void print_err() {
	cerr << "\n";
}
template <class T, class... Arg>
void print_err(T x, Arg&&... args) {
	cerr << x << " ";
	print_err(args...);
}
template<class T>
void print_container(T &cont) {
	for (auto iter : cont) {
		cerr << iter << " ";
	}
	cerr << "\n";
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#define debug_c(container) print_container(container)
#else
#define debug(...)
#define debug_c(container)
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vl vector<ll>
#define vpll vector<pair<ll,ll>>
#define mll map<ll,ll>
#define mllrev map<ll,ll,greater<int>>
#define ps(x,y) fixed<<setprecision(y)<<x//it will give upto y decimal places
#define w(t) ll t;cin>>t;while(t--)
#define fo(i,n) for(ll i=0;i<n;++i)
#define foab(i,a,b) for(ll i=a;i<b;++i)
#define inp cin>>
#define pr cout<<
#define pqb priority_queue<ll>//max heap
#define pqs priority_queue<ll,vl,greater<int>>//min heap
#define mk(arr,n,type) type *arr=new type[n];
#define all(A) (A).begin(),(A).end()
#define fastio ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
void CP() {
	fastio
#ifdef local
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	return;
}
class Graph {
public:
	list<ll> *adj_list;
	ll v;
	Graph(ll v) {
		this->v = v;
		adj_list = new list<ll>[v];
	}
	void add_edge(ll u, ll v, bool bidirectional = true) {
		adj_list[u].push_back(v);
		if (bidirectional) {
			adj_list[v].push_back(u);
		}
	}
	void print();
	void connected_compo();
	void dfs(vector<vector<ll>> vect, ll k1, ll k2, ll n);
	void bfs(ll v, bool visited[]);
};
const int d4i[4] = { -1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void solve() {
	string str;
	read(str);
	if (str[0] == str[1] and str[0] == str[2] and str[0] == 'R') {
		cout << "3\n";
	} else if (str[0] == str[1] and str[0] == 'R') {
		cout << "2\n";
	} else if (str[2] == str[1] and str[1] == 'R') {
		cout << "2\n";
	} else if (str[0] == 'R' or str[1] == 'R' or str[2] == 'R') {
		cout << "1\n";
	} else {
		cout << "0\n";
	}
	return ;
}
int main() {
	CP();
	// w(t) {
	solve();
	// }
	return 0;
}

Measured memory_bytes: 3580
n = int(input())
h = list(map(int, input().split()))
a = [0,abs(h[1]-h[0])] + [float('inf')]*(n-2)
for i in range(2,n):
    a[i] = min(a[i-2]+abs(h[i]-h[i-2]), a[i-1]+abs(h[i]-h[i-1]))
print(a[n-1])

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

int main(){
	string str;
	cin >> str;
	int a = 0;
	int b = 0;
	for(int i=0;i<str.size();++i){
		if((i%2 == 0) != (str[i] == '0'))++a;
		else ++b;
	}
	cout << min(a, b) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> wyst(26, 0);
    for (int i = 0; i < n; ++i)
    {
        string x;
        cin >> x;
        for (int j = 0; j < m; ++j)
            ++wyst[x[j] - 'a'];
    }
    int il4 = (n / 2) * (m / 2);
    for (int i = 0; i < 26; ++i)
    {
        while (il4 > 0 && wyst[i] >= 4)
        {
            --il4;
            wyst[i] -= 4;
        }
    }
    if (il4 > 0)
    {
        cout << "No";
        return 0;
    }
    bool jed = false;
    if (n % 2 == 1 && m % 2 == 1)
        jed = true;
    int np = 0;
    for (int i = 0; i < 26; ++i)
        if (wyst[i] % 2 == 1)
            ++np;
    if (jed)
    {
        if (np == 1)
            cout << "Yes";
        else
            cout << "No";
    }
    else
    {
        if (np == 0)
            cout << "Yes";
        else
            cout << "No";
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;
    int result = 0;
    if(a + b + 1 < c){
        result = b + a + b + 1;
    }else{
        result = b + c;
    }

    cout << result << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cstdlib>
using namespace std;
int main() {
	int n, m, d;
	cin >> n >> m >> d;
	int space[105][105] = {0};
	for (int i = 0; i < n; i++) {
		for (int j =0 ; j < m; j++) {
			char a;
			cin >> a;
			if (a == '#') {
				space[i][j] = 1;
			}
			if (a == '.') {
				space[i][j] = 2;
			}
			
		}
		
	}
	int hn = 0;
	int cnt = 0;
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < m - d+1; i++) {
			for (int j = 0; j < d; j++) {
				if (space[h][i + j] == 1 || space[h][i+j] == 0) {
					hn = 1;
					break;
				}
			}
			if (hn == 0) {
				cnt++;
				
			}
			hn = 0;
		}
	}
	for (int h = 0; h < m; h++) {
		for (int i = 0; i < n - d+1; i++) {
			for (int j = 0; j < d; j++) {
				if (space[i+j][h] == 1||space[i+j][h]==0) {
					hn = 1;
					break;
				}
			}
			if (hn == 0) {
				cnt++;
				
			}
			hn = 0;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3156
n, m, k = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))

import numpy as np
import bisect

nss = np.array([0] + ns).cumsum()
mss = np.array([0] + ms).cumsum()
mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break
    j = bisect.bisect_right(mss, k - nss[i])
    if j > 0:
        j -= 1
    mx = max(mx, i + j)
print(mx)


Measured memory_bytes: 47308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long a;
    cin >> a;
    long long b;
    cin >> b;
    long long c = a*b;
    long long result;
    if(b == 1){
        cout << 1;
        return 0;
    }
    if(a == 1){
        cout << 1;
        return 0;
    }
    if(c%2 == 0){
        result = c/2;
    }else{
        result = (c/2) + 1;
    }
 
    cout << result;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <functional>
#include <cstdint>

int main() {
  int N;
  scanf("%d", &N);

  std::set<int> set;
  std::vector<int> E;
  for (int i=0; i<N; ++i) {
    int A;
    scanf("%d", &A);
    if (set.count(A)) {
      E.emplace_back(A);
      set.erase(A);
    } else {
      set.insert(A);
    }
  }

  if (E.size() < 2) {
    printf("0\n");
    return 0;
  }

  std::sort(E.begin(), E.end(), std::greater<int>());
  printf("%jd\n", intmax_t(E[0])*E[1]);
  return 0;
}


Measured memory_bytes: 4864
t,a,k = [x for x in list(map(int,input().split()))]
if k>=t:
    if k-t > a:
        t = 0
        a = 0
    else:
        a = a - (k-t)
        t = 0
    print(t,a)
else:
    t = t-k
    print(t,a)
  
  

Measured memory_bytes: 2940
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

ll INF = 1000000000000000 ;

void BFS(vector<vector<pll>> &g,vll &cnt,ll n,queue<ll> &q){
	ll d = cnt.at(n) ;
	for(int i=0;i<g.at(n).size();i++){
		if(cnt.at(g.at(n).at(i).first)>d+g.at(n).at(i).second){
			cnt.at(g.at(n).at(i).first) = d+g.at(n).at(i).second ;
			q.push(g.at(n).at(i).first) ;
		}
	}
	if(q.empty()) return ;
	n = q.front() ; q.pop() ;
	BFS(g,cnt,n,q) ;
}

int main(){
	ll n ; cin >> n ;
	vector<vector<pll>> g(n,vector<pll>(0)) ;
	for(int i=0;i<n-1;i++){
		ll a,b,c ;
		cin >> a >> b >> c ;
		a-- ; b-- ;
		g.at(a).push_back(make_pair(b,c)) ;
		g.at(b).push_back(make_pair(a,c)) ;
	}
	ll Q,k ;
	cin >> Q >> k ;
	k-- ;
	vll cnt(n,INF) ;
	cnt.at(k) = 0 ;
	queue<ll> q ;
	BFS(g,cnt,k,q) ;
	for(int i=0;i<Q;i++){
		ll x,y ;
		cin >> x >> y ;
		x-- ; y-- ;
		cout << cnt.at(x)+cnt.at(y) << endl ;
	}
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 2000;
llong fact[mxN*3+3],finv[mxN*3+3];
llong P,Inv2;
llong f[mxN*3+3][mxN*4+3],g[mxN+3];
int n;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}
llong comb(llong x,llong y) {return x<0||y<0||x<y?0ll:fact[x]*finv[y]%P*finv[x-y]%P;}

void updsum(llong &x,llong y) {x = x+y>=P?x+y-P:x+y;}

int main()
{
	scanf("%d%lld",&n,&P); Inv2 = (P+1)>>1;
	fact[0] = 1ll; for(int i=1; i<=3*mxN; i++) fact[i] = fact[i-1]*i%P;
	finv[3*mxN] = quickpow(fact[3*mxN],P-2); for(int i=3*mxN-1; i>=0; i--) finv[i] = finv[i+1]*(i+1ll)%P;
	g[0] = 1ll; for(int i=1; i<=n; i++) g[i] = g[i-1]*(3*i-1ll)%P*(3*i-2ll)%P;
	f[0][n+1] = 1ll;
	for(int i=0; i<=3*n; i++)
	{
		for(int j=-n; j<=3*n; j++)
		{
			updsum(f[i+1][j+1+(n+1)],f[i][j+(n+1)]);
			updsum(f[i+2][j-1+(n+1)],f[i][j+(n+1)]*(i+1ll)%P);
			updsum(f[i+3][j+(n+1)],f[i][j+(n+1)]*(i+2ll)%P*(i+1ll)%P);
		}
	}
	llong ans = 0ll;
	for(int i=0; i<=n; i++)
	{
		updsum(ans,f[3*n][3*i+(n+1)]%P);
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back()
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

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

    vii coords(n);
    loop(z, coords) cin >> z.F >> z.S;

    double dist = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i == j) continue;
            dist += sqrt(pow((coords[i].F - coords[j].F), 2) + pow((coords[i].S - coords[j].S), 2)); 
        }
    }

    cout << setprecision(11) << dist / n << nl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main()
{
	long n,a[205],check=0,ans=0;
	scanf("%ld",&n);
	for(int i=1; i<=n; i++)
		scanf("%ld",&a[i]);
	while(check!=1){
		for(int i=1; i<=n; i++){
			if(a[i]%2==1) check=1;
			a[i]=a[i]/2;
		}
		ans++;
	}
	printf("%ld\n",ans-1);
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b; cin >> a >> b;
  COUT(a*b%2 ? "Odd" : "Even");

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d", &a,&b);
    if(a==3 || b==3) printf("Possible\n");
    else if(a<3 && b<3)
    {
        c=a+b;
        if(c%3==0) printf("Possible\n");
        else printf("Impossible\n");
    }
    else if(a>3 || b>3)
    {
        if(a%3==0) printf("Possible\n");
        else if(b%3==0) printf("Possible\n");
        else if((a>3 && b<3) || (a<3 && b>3))
        {
            c=(a+b);
            if(c%3==0)printf("Possible\n");
        else printf("Impossible\n");
        }
        else if(a>3 && b>3)
    {
        c=a+b;
        if(c%3==0)
            printf("Possible\n");
        else printf("Impossible\n");
    }
    }

    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(dfs(n, new Integer[n + 1]));
    }

    private static int dfs(int target, Integer[] dp) {
        if (target <= 5) {
            return target;
        }
        if (dp[target] != null) {
            return dp[target];
        }
        int maxNine = 1, maxSix = 1;
        while (maxNine * 9 <= target) {
            maxNine *= 9;
        }
        while (maxSix * 6 <= target) {
            maxSix *= 6;
        }
        return dp[target] = Math.min(1 + dfs(target - maxNine, dp), 1 + dfs(target - maxSix, dp));
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32784
import java.math.*;
import java.util.*;

public class Main {
    static void out(boolean b) {
        if (b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static boolean Loop(String str) {
        int num = str.length();
        boolean tmp = true;
        if (num !=2) {
            for (int i = 0; i < (num - 1) / 2; i++) {
                if (str.charAt(i) != str.charAt(num - i - 1)) {
                    tmp = false;
                    break;
                }
            }
            return tmp;
        }
        else {
            return false;
    }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean isLoop = true;
        isLoop = Loop(s);
        if (isLoop) {
            isLoop = Loop(s.substring(0, (s.length() - 1 / 2 )));
            if (isLoop) {
                isLoop = Loop(s.substring((s.length() + 3 )/ 2 -1 ));
            }
        }
        out(isLoop);
        }
    }

Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if(A==B)
    cout<<"Draw";
else
    if(A==1)
        cout<<"Alice";
    else
        if(B==1)
        cout<<"Bob";

else
    if(A>B)
     cout<<"Alice";

else
if(A<B)
cout<<"Bob";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>k>>n;

    vector<int> ans;

    if(k==1){
        for(int i=0;i<(n+1)/2;i++)ans.push_back(1);
    }
    else if(!(k&1)){
        ans.push_back(k/2);
        for(int i=0;i<n-1;i++)
            ans.push_back(k);
    }
    else {
        a = n>>1;

        for(int i=1;i<=n;i++)ans.push_back((k+1)/2);

        for(int i=0;i<a;i++){
            if(ans.back()==1)ans.pop_back();
            else {
                ans.back()--;
                while(ans.size()<n)ans.push_back(k);
            }
        }

    }

    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";

    return 0;
}


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

int main(){

    int n;
    cin >> n;
    set<int> st;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        st.insert(a);
    }
    
    for(auto it = st.begin(); it != st.end(); ++it){
        if(it != st.begin()){
            cout << " ";
        }
        cout << *it;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 7748
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC081C - Not so Diverse

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();   // 1 <= k <= n <= 200000
        int k = sc.nextInt();

        int[] a = new int[n];   // 1 <= a <= n

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (map.containsKey(a[i])) {
                map.put(a[i], map.get(a[i]) + 1);
            } else {
                map.put(a[i], 1);
            }
        }

        int count = 0;
        if (map.size() > k) {
            for (Object i :map.values().stream().sorted().limit(map.size() - k).toArray()) {
                count += (Integer)i;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 100504
N = gets.chop.to_i

# 同じ色に塗られた任意の頂点について、その距離が偶数である → ある１点を基準にして、そこから距離が偶数のものは0奇数のものは1とすれば良い

# ハッシュの中にもハッシュをつくる
graph = Hash.new{ |h,k| h[k] = {}}

edges = (N-1).times.map{ gets.split.map(&:to_i)}

# 無向グラフなので from, toはどちらも用意する
edges.each do |from, to, len|

  len = len % 2
  graph[from][to] = len
  graph[to][from] = len
end


# queueの要素は頂点とその長さとする
# 初期値は1で長さは0
queue = [[1,0]]

visited = {}
ans = Array.new(N)


# queueがemptyでないときにループする
until queue.empty?
  # 頂点と距離を持ってくる
  v, dist = queue.shift

  ans[v-1] = dist % 2 == 0 ? 0 : 1

  next if visited[v]
  visited[v] = true

  graph[v].each do |n, len|
    queue << [n, (dist+len) % 2]
  end
end

puts ans








Measured memory_bytes: 51196
#include<stdio.h>
int main(){
  char a[100],b[100],T,c[100];
  int i,j,k,I=0,J=0,count=0,t=0;
    
  
  
    while(1){
      scanf("%c",&a[I]);
      if(a[I]=='\n') break;
      I++;
    }
  
   while(1){
      scanf("%c",&b[J]);
      if(b[J]=='\n') break;
      J++;
    }
  
   while(count!=J){
       
     count=0;
   for(i=0;i<J;i++){
     if(a[i]==b[i]) count++;
     else count--;
   }
    
   if(count!=J){
     for(i=0;i<I;i++){
       if(i==0) T=a[0];
         a[i]=a[i+1];
     if(i==I-1)  a[I-1]=T;
     }
       
     t++;
     if(t==100) break;
       
   }
   }
   if(count==J) printf("Yes\n");
   else printf("No\n");
     
  
   return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

int main() {
	int h, w; cin >> h >> w;

	vector<string>s(h);
	rep(i, h)cin >> s[i];

	bool okay = true;
		
	for (int i = 1; i < h - 1; i++) {
		for (int j = 1; j < w - 1; j++) {
			if (s[i][j] == '#') {
				if (s[i + 1][j] == '.' && s[i - 1][j] == '.' && s[i][j + 1] == '.' && s[i][j - 1] == '.') {
					okay = false;
				}
			}
		}
	}
	if (okay) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0556 : Tile **/
int main()
{
	int N, K;
	cin>>N>>K;
	rep(i, K) {
		int x, y;
		cin>>x>>y;
		
		if (x>N/2)
			x = N-x+1;
		if (y>N/2)
			y = N-y+1;
		
		int t = min(x, y)%3;
		cout << (t==0?3:t) << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <string>

using namespace std;

int simulate(string d){
  if(d[0]==d[1] && d[1]==d[2] && d[2]==d[3]) return -1;
  string l, s;
  for(int cnt=0; ; cnt++){
    if(d=="6174") return cnt;
    l = s = d;
    sort(l.begin(), l.end(), greater<char>());
    sort(s.begin(), s.end());
    int x = atoi(l.c_str()) - atoi(s.c_str());
    for(int i=0, p=1000;i<4;i++, p/=10){
      d[i] = '0' + x/p;
      x %= p;
    }
  }
}

int main(){
  string str;
  while(cin>>str && str!="0000"){
    int cnt = simulate(str);
    if(cnt>=0){
      cout<<cnt<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long com(long long N, long long R) {
    if (R < 0 || R > N) return 0;
    if (R == 1) return N;
    else if (R == 2) return N * (N-1) / 2;
    else return N * (N-1) * (N-2) / 6;
}

long long pow(long long N, long long k) {
    long long res = 1;
    for (int i = 0; i < k; ++i) res *= N;
    return res;
}

string S;
int N, K;

long long solve(int i, int k, int smaller) {
    if (i == N) {
        if (k == 0) return 1;
        else return 0;
    }
    if (N - i < k) return 0;
    if (k == 0) return 1;
    
    if (smaller) {
        return com(N-i, k) * pow(9, k);
    }
    else {
        if (S[i] == '0') {
            return solve(i+1, k, false);
        }
        else {
            long long zero = solve(i+1, k, true);
            long long aida = solve(i+1, k-1, true) * (S[i] - '1');
            long long icchi = solve(i+1, k-1, false);
            return zero + aida + icchi;
        }
    }
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    while (cin >> S >> K) {
        N = S.size();
        cout << solve(0, K, false) << endl;
    }
}


















Measured memory_bytes: 512