akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0;
	int a[1000]={};
	int n;
	cin>>n;
	for (int i=1;i<=n*2;i++)
	    cin>>a[i];
	sort(a+1,a+n*2+1);
	for (int i=1;i<=n;i++)
	    ans+=min(a[i*2-1],a[i*2]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[1000000];
  int b[1000000];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    if(b[i]==a[n-1]){
      cout << a[n-2] << endl;
    } else {
      cout << a[n-1] << endl;
    }
  }
}


Measured memory_bytes: 8064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int c=0,W,H;
vector<string> grid;
string tmp;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0}; 
void dfs(int x, int y){
  c++;
  grid[y][x]='#';
  REP(r,4){
    if(x+dx[r]>=0&&x+dx[r]<W
        &&y+dy[r]>=0&&y+dy[r]<H
        &&grid[y+dy[r]][x+dx[r]]=='.'){
      dfs(x+dx[r],y+dy[r]);
    }
  }
}

int main(void){
  while(cin>>W>>H){
    if(W==0) break;
    grid.clear();
    c = 0;
    REP(y,H){
      cin>>tmp;
      grid.push_back(tmp);
    }
    REP(y,H)REP(x,W){
      if(grid[y][x]=='@'){
        dfs(x,y);
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

#define REP(i, x, n) for(int i = x, i##_len=(n); i < i##_len; i++)
#define rep(i,n) REP(i,0,n)
//#define DEBUG 2

using Weight = int;
using Capacity = int;
struct Edge {
	int src, dst;
	bool check;
	Weight weight;
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w), check(false) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<Weight> dijkstra(const Graph &g, int s) {
	const Weight inf = numeric_limits<Weight>::max() / 4;
	typedef tuple<Weight, int> State;
	priority_queue<State> q;
	vector<Weight> dist(g.size(), inf);
	dist[s] = 0;
	q.emplace(0, s);
	while (q.size()) {
		Weight d;
		int v;
		tie(d, v) = q.top();
		q.pop();
		d *= -1;
		/* if(v == t) return d; */
		if (dist[v] < d) continue;
		for (auto &e : g[v]) {
			if (dist[e.dst] > dist[v] + e.weight) {
				dist[e.dst] = dist[v] + e.weight;
				q.emplace(-dist[e.dst], e.dst);
			}
		}
	}
	return dist;
}

void run() {
	int n, m;
	cin >> n >> m;
	Graph g(n);
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a-1].emplace_back(Edge(a-1, b-1, c));
		g[b-1].emplace_back(Edge(b-1, a-1, c));
	}

	long long int ans = 0;
	rep(i, n) {
		vector<int> dist = dijkstra(g, i);
		for (auto &e : g[i]) {
			if (dist[e.dst] < e.weight) ans++;
		}
	}

	cout << ans/2 << endl;

}

int main() {
#ifdef DEBUG
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	rep(i, DEBUG) {
		cout << "cnt:" << i << " ------------" << endl;
		run();
	}
#else
	run();
#endif
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long[] t=new long[n];
		long r=0;
		long p1=0;
		long p2=0;
		for(int i = 0; i<n; i++){
			long v = sc.nextLong();
			t[i]=v;
			
		}
		Arrays.sort(t);
		double ans1=0;
		long ans2=0;
		for(int i=0; i<n; i++){
			if(i<=a-1){
				ans1+=t[n-1-i];
			}
			if(r==t[n-1-i]){
				p1++;
			}else{
				if(i<=a-1){
					r=t[n-1-i];
					p1=1;
				}else{
					break;
				}
			}
			if(i==a-1){
				p2=p1;
			}
		}
		if(p2!=a){
			if(((ans1-r*p2)/(a-p2))==r){
				for(long i = p2; i<=Math.min(b-a+p2,p1); i++){
					ans2+=c(p1,i);
				}
			}else{
				ans2+=c(p1,p2);
			}
		}else{
			for(long i = p2; i<=Math.min(b-a+p2,p1); i++){
				ans2+=c(p1,i);
			}
		}
		System.out.println(ans1/a);
		System.out.println(ans2);
	}
	public static long c(long o,long l){
		long ans=1;
		for(long i = 1; i<=l; i++){
			ans*=o-i+1;
			ans/=i;
		}
		return ans;
	}
}

Measured memory_bytes: 23380
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

const int NMAX=1010;
using Graph=vector<vector<int>>;

vector<int> daiku(const Graph &G,int a,int b){
    int N=G.size();
    vector<int> dist(N, -1);
    queue<pair<int,vector<int>>> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[b] = 0;
    vector<int> vec;
    que.push(make_pair(b,vec)); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        pair<int,vector<int>> p = que.front();
        int v = p.first; // キューから先頭頂点を取り出す
        vector<int> prev=p.second;
        prev.emplace_back(v);
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (nv==a){
                prev.emplace_back(a);
                return prev;
            }
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(make_pair(nv,prev));
        }
    }

    return {};


}


vector<int> solve(const Graph &G,const vector<pair<int,int>> &E){
    int N = G.size();
    int M = E.size();
    vector<int> ans;
    int vec_size=INF;
    REP(i,M){
        vector<int> prev=daiku(G,E[i].first,E[i].second);
        if(prev.size()>0&&vec_size>prev.size()){
            ans=prev;
            vec_size=prev.size();
        }
    }
    return ans;
}


int main(){
    int N,M;
    cin>>N>>M;

    Graph G(N);
    vector<pair<int,int>> E(M);
    REP(i,M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        E[i]=make_pair(a,b);
        G[a].push_back({b});
    }

    vector<int> ans = solve(G,E);
    if(ans.size()==0){
        cout<<-1<<endl;
    }else{
        cout<<ans.size()<<endl;
        REP(i,ans.size()) cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 3920
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;

struct Item
{
	int v, d, c;
};

Item Q[MAX];
vector<int> g[MAX];
int U[MAX];
int D[MAX];
int C[MAX];
int iter;

void dfs(int v, int d, int curD, int color)
{
	if (d > curD) return;
	if (curD - d <= D[v]) return;
	D[v] = curD - d;
	if (C[v] == 0) C[v] = color;
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, d + 1, curD, color);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int q;
	cin >> q;
	FOR(i, 0, q)
	{
		cin >> Q[i].v >> Q[i].d >> Q[i].c;
		Q[i].v--;
	}

	reverse(Q, Q + q);
	FILL(D, -1);
	FOR(i, 0, q)
	{
		dfs(Q[i].v, 0, Q[i].d, Q[i].c);
	}

	FOR(i, 0, n)
	{
		//cout << i + 1 << ": " << C[i] << "\n";
		cout << C[i] << "\n";

	}
}

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

int main()
{
	int N;
	std::cin >> N;

	int *a = new int[N];
	int *b = new int[N];
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
		b[i] = a[i];
	}

	std::sort(a,a + N);

	int center = N / 2 - 1;
	int c1 = a[center];
	int c2 = a[center + 1];

	for (int i = 0; i < N; i++) {
		if (b[i] <= c1) {
			std::cout << c2 << std::endl;
		} else {
			std::cout << c1 << std::endl;
		}
	}

	delete[] a;
	delete[] b;

	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>

#define ll long long

int main() {
    char ch = fgetc(stdin);
    int l = 0;
    while (ch != '\n') {
        if (l == 0)
            printf("%c", ch);
        l = 1 - l;
        ch = fgetc(stdin);
    }
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp

if s[0] != 'A'
  puts 'WA'
  exit
end
s[0] = ''

sp = s[1..-2].index('C')
if !sp
  puts 'WA'
  exit
end
s[sp+1] = ''

if s.downcase != s
  puts 'WA'
else
  puts 'AC'
end


Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
using namespace std;



int main()
{
    int a,i;
    int maxi=0,mini=101;
    for(i=1;i<=3;i++)
        {scanf("%d",&a);
        if(a<mini)
            mini=a;
        if(a>maxi)
            maxi=a;
        }
        printf("%d\n",maxi-mini);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
  int N,M,C,a, out=0 ,s=0;
  cin >> N >> M >> C;
  int B[M]={};

  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  
  for(int n_i=0; n_i < N; n_i++){
    for(int m_i=0; m_i < M; m_i++){
      cin >> a;
      s = s + a * B[m_i];
    }
    s += C;
    if( s > 0) out += 1;
    s=0;
  }
  cout << out;
}

Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(max);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my %h;
$h{$_}++ for @a;
my @s = sort {$b <=> $a} grep {$h{$_} >= 4} keys %h;
my @t = sort {$b <=> $a} grep {$h{$_} >= 2} keys %h;
my $ans = 0;
$ans = $s[0] * $s[0] if @s > 0;
$ans = max($ans, $t[0] * $t[1]) if @t > 1;
say $ans;

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



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

    ll ans=0;
    int r=0;
    ll sum_xor=0;
    ll sum_plus=0;
    rep(l,N){   
        while(r<N&&((sum_xor^a[r])==(sum_plus+a[r]))){
            sum_xor^=a[r];
            sum_plus+=a[r];
            r++;
        }

        ans+=(r-l);
        if(l==r) r++;
        else{
            sum_xor^=a[l];
            sum_plus-=a[l];
        }
        
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let cs = Array.make n 0
let f i = cs.(i) <- cs.(i) + 1
let _ = Array.iter (fun (a, b) -> f a; f b) ab_s; Array.iter (fun c -> Printf.printf "%d\n" c) cs

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(87);
  a[0]=2;
  a[1]=1;
  for(int i=2;i<87;i++){
    a[i]=a[i-1]+a[i-2];
  }
  
  cout << a[n] << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  int A,B;
  cin>>A>>B;
  rep(i,1001){
    if(i*8/100==A&&i/10==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 3592
// 優先度付きキュー

#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int a[N * 3];

    long before[N + 1];
    long after[N + 1];

    long sum = 0;
    long ans;

    // minpq = <1,2,3,4,9>
    // maxpq = <9,4,3,2,1>
    priority_queue<int, std::vector<int>, std::greater<int>> minpq;
    priority_queue<int> maxpq;

    for (int i = 0; i < 3 * N; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < N; i++)
    {
        sum += a[i];
        minpq.push(a[i]);
    }

    before[0] = sum;

    for (int k = 1; k <= N; k++)
    {
        int addnum = a[N - 1 + k];
        minpq.push(addnum);

        int removenum = minpq.top();
        minpq.pop();

        sum += addnum;
        sum -= removenum;

        before[k] = sum;
    }

    sum = 0;
    for (int i = 2 * N; i < 3 * N; i++)
    {
        sum += a[i];
        maxpq.push(a[i]);
    }

    after[0] = sum;

    for (int k = 1; k <= N; k++)
    {
        int addnum = a[2 * N - k];
        maxpq.push(addnum);

        int removenum = maxpq.top();
        maxpq.pop();

        sum += addnum;
        sum -= removenum;
        after[k] = sum;
    }

    ans = before[0] - after[N];
    for (int i = 0; i <= N; i++)
    {
        long tmp;
        tmp = before[i] - after[N - i];
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4088
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int a,b;
    cin>>a>>b;
    if(max(a,b)>8){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
    return 0;
}


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

int main()
{
	int a, b, c=0;
	string s, t;

	cin >> s;
	for (int i = 0;i < s.length();i++)
	{
		if ((i+1) % 2 == 1)
		{
			if (s[i] == 'L')
			{
				c++;
				break;
			}
		}
		else if ((i+1) % 2 == 0)
		{
			if (s[i] == 'R')
			{
				c++;
				break;
			}
		}
	}
	if (c > 0)
		cout << "No";
	else
		cout << "Yes";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int a, b, n;
    cin >> a >> b >> n;

    int m = max(a, b);
    cout << (n + m - 1)/m << endl;

}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

template<typename T>
class BinaryIndexedTree {
    int N;
    vector<T> data;
public:
    BinaryIndexedTree(int N) : N(N) {
        data.resize(N + 1, 0);
    }

    T sum(int k) {
        T res = 0;
        for (; k > 0; k -= k & -k) {
            res += data[k];
        }
        return res;
    }

    void add(int k, T x) {
        for (; k <= N; k += k & -k) {
            data[k] += x;
        }
    }

    /**
     * v1 + v2 + ⋯ + vx ≧ W となる最小の 𝑥 を求める
     */
    int lowerBound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        int k = 1;
        while (k * 2 <= N) k *= 2;
        for (; k > 0; k /= 2) {
            if (x + k <= N && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

int main(){
    int N;
    cin>>N;
    vector<int> A(N),B(N);
    REP(i,N) cin>>A[i];
    REP(i,N) cin>>B[i];
    int ans=INF;
    REP(bit,1<<N){
        vector<int> C(N);
        vector<pair<int,int>> odd,even,whole;
        bool ok=true;

        REP(j,N){
            int mask=1<<j;
            if(bit&mask){
                C[j]=A[j];
                if(j%2==0){
                    even.push_back(make_pair(C[j],j));
                }else{
                    odd.push_back(make_pair(C[j],j));
                }
            }else{
                C[j]=B[j];
                if(j%2==1){
                    even.push_back(make_pair(C[j],j));
                }else{
                    odd.push_back(make_pair(C[j],j));
                }
            }
        }

        if(!((even.size()==(N+1)/2)&&(odd.size()==N/2))) continue;
        sort(ALL(even));
        sort(ALL(odd));
        REP(j,N){
            if(j%2==0){
                whole.push_back(even[j/2]);
            }else{
                whole.push_back(odd[j/2]);
            }
        }
        bool ng=false;
        REP(j,N-1){
            if(whole[j].first>whole[j+1].first) ng=true;
        }
        if(ng) continue;

        int sum=0;
        REP(j,N-1){
            REP(k,N-j-1){
                if (whole[k].second > whole[k + 1].second) {
                    swap(whole[k], whole[k + 1]);
                    sum++;
                }
            }
        }
        ans=min(ans,sum);
    }

    if(ans==INF) ans=-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll dist[100005];
ll A, B, C;
vector<pair<ll, ll>> adj[100005];
ll col[100005];

void djisktra(int node = 1) {
	set<pair<ll, ll>> S;
	dist[1] = 0;
	S.insert(make_pair(node, dist[node]));
	while(!S.empty()) {
		ll nodeNow = S.begin()->first;
		S.erase(S.begin());
		for(int i = 0; i < adj[nodeNow].size(); i++) {
			ll temp = adj[nodeNow][i].first;
			if(dist[temp] > dist[nodeNow] + adj[nodeNow][i].second) {
				S.erase({temp, dist[temp]});
				dist[temp] = dist[nodeNow] + adj[nodeNow][i].second;
				S.insert({temp, dist[temp]});
			}
		}
	}

}

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N - 1; i++) {
		scanf("%lld %lld %lld", &A, &B, &C);
		adj[A].push_back(make_pair(B, C));
		adj[B].push_back(make_pair(A, C));
	}
	// memset(dist, , sizeof(dist));
	for(int i = 0; i <= N; i++) {
		dist[i] = 1e17;
	}
	djisktra(1);
	col[1] = 0;
	for(int i = 2; i <= N; i++) {
		// cout << i << " " << dist[i] << " \1an";
		if(dist[i] % 2) {
			col[i] = 1;
		}
		else {
			col[i] = 0;
		}
	}
	for(int i = 1; i <= N; i++) {
		printf("%lld\n", col[i]);
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 10868
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
g=[[] for _ in range(n)]
indeg=[0]*n
touch=[0]*n
for _ in range(m):
    l,r,d=map(int,input().split())
    l-=1
    r-=1
    touch[l]=1
    touch[r]=1
    g[l].append((r,d))
    indeg[r]+=1
if m==0:
    print('Yes')
    exit()
entered=False
for i in range(n):
    if indeg[i]==0 and touch[i]==1:
        vis=[False]*n
        entered=True
        dist=[-1]*n
        dist[i]=0
        def dfs(u):
            vis[u]=1
            for v,wt in g[u]:
                if dist[v]==-1:
                    dist[v]=dist[u]+wt
                elif dist[v]!=dist[u]+wt:
                    print('No')
                    exit()
                if vis[v]==False:
                    dfs(v)
        dfs(i)

if entered==False:
    print('No')
else:
    print('Yes')



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

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

    std::string s;
    std::cin >> s;

    int cnt = 1;
    std::string str_now = s.substr(0, 1); 
    for ( int i = 1; i < n; i++ ) {
        if ( str_now != s.substr(i, 1) ) {
            cnt++;
            str_now = s.substr(i, 1);
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string S; cin >> S;
    bool flg_A = false, flg_B = false;
    for (auto s : S) {
        if (s == 'A') flg_A = true;
        else if (s == 'B') flg_B = true;
    }

    if (flg_A and flg_B) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll H , W;
char A[1001][1001];
queue<pair<ll,ll> > nxt;

void check(ll a , ll b){
    if(a < 0 || b < 0) return ;
    if(a > 1000 || b > 1000) return ;
    
    if(A[a][b] == '.') {
        A[a][b] = '#';
        nxt.push(mp(a,b));
    }
    return ;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i, 1000)rep(j, 1000){
        A[i][j] = '#';
    }
    
    cin >> H >> W;
    
    rep(i, H){
        string str;
        cin >> str;
        rep(j, W){
            A[i][j] = str[j];
            if(A[i][j] == '#') nxt.push(mp(i,j));
        }
    }
    
    ll ans = 0 ;
    while(nxt.size() != 0){
        ans ++;
        
        ll siz = nxt.size();
        rep(i, siz){
            pair<ll,ll> xy = nxt.front();
            ll x = xy.first;
            ll y = xy.second;
            
            check(x-1, y);
            check(x+1, y);
            check(x, y-1);
            check(x, y+1);
            nxt.pop();
        }
    }
    
    cout << ans - 1 << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 17588
// include
#include <iostream>
#include <utility>
#include <list>

// typedef

// macro
#define REP(index, num) for (auto index = 0; index < num; index++)

using namespace std;

int CountPaths(int inNode, list<pair<int, int>> &inPairs, list<int> inNodes);
bool IsVisited(int val, list<int> &inNodes);

int main()
{
  int N, M;
  cin >> N >> M;

  list<pair<int, int>> pairs;
  list<int> nodes;

  REP(index, M)
  {
    int a, b;
    cin >> a >> b;
    pairs.push_back(make_pair(a, b));
    nodes.push_back(a);
    nodes.push_back(b);
  }
  nodes.sort();
  nodes.unique();

  cout << CountPaths(1, pairs, nodes) << endl;

}

int CountPaths(int inNode, list<pair<int, int>> &inPairs, list<int> inNodes)
{
  int count = 0;
  inNodes.remove(inNode);

  if (inNodes.size())
  {
    // pairsを探索
    for (auto pItr = inPairs.begin(); pItr != inPairs.end(); ++pItr)
    {
      // pairの要素と一致があれば実行
      if (inNode == (*pItr).first)
      {
        if (!IsVisited((*pItr).second, inNodes))
        {
          count += CountPaths((*pItr).second, inPairs, inNodes);
        }
      }
      else if (inNode == (*pItr).second)
      {
        if (!IsVisited((*pItr).first, inNodes))
        {
          count += CountPaths((*pItr).first, inPairs, inNodes);
        }
      }
    }
  }
  else 
    return 1;

  return count;
}

bool IsVisited(int val, list<int> &inNodes)
{
  // nodesを探索
  for (auto nItr = inNodes.begin(); nItr != inNodes.end(); ++nItr)
  {
    if (val == *nItr)
      return false;
  }
  return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    int ans = 0;
    REP(i,n){
        int x = in();
        if (i % 2 == 0 && x % 2 == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
<?php

fscanf(STDIN, "%d", $n);

$str = '';
while ($n != 0) {
    $r = $n % (-2);
    if ($r < 0) $r += 2;

    $n = intdiv($n - $r, -2);
    $str = $r . $str;
}

echo $str === '' ? 0 : $str, PHP_EOL;


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int x = input.nextInt();
		int a = input.nextInt();
		int b = input.nextInt();
		
		x-=a;
		
		do{
			
			x-=b;
		}while(x>0);
		if(x==0)
			System.out.println(x);
		else
			System.out.println(x+b);

	}

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int B,W,re;
ll mo=1000000007;

ll comb(ll N_, ll C_) {
	const int NUM_=1400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll ret[202020],ret2[202020];

ll E[202020][3];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>B>>W;
	
	for(i=0;i<W;i++) {
		ll pat=modpow(modpow(2,(i+B)))*comb(i+B-1,B-1)%mo;
		E[i+B][0]=pat;
	}
	for(i=0;i<B;i++) {
		ll pat=modpow(modpow(2,(i+W)))*comb(i+W-1,W-1)%mo;
		E[i+W][1]=pat;
		ret2[i+W+1]=pat;
		
	}
	
	ll R[2]={};
	ll pat=1;
	for(i=1;i<=B+W;i++) {
		(E[i][2]=1+(mo-R[0])+(mo-R[1]))%=mo;
		(R[0]+=E[i][0])%=mo;
		(R[1]+=E[i][1])%=mo;
		
		(ret2[i]+=ret2[i-1])%=mo;
		(ret[i]+=modpow(2)*E[i][2]+ret2[i])%=mo;
		cout<<ret[i]<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 42880
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <string>\

using namespace std;

queue<string> nam;
queue<int> tim;

int main(){ 
  int n,q;
  int total=0;
  cin>>n>>q;
  string s;
  int t;
  for(int i=0;i<n;++i){
      cin>>s>>t;
      nam.push(s);
      tim.push(t);
  }
  string pn;
  int pt;
  while(!nam.empty()){
      pn=nam.front();
      nam.pop();
      pt=tim.front();
      tim.pop();
      total+=min(q,pt);
      pt-=q;
      if(pt<0){
          pt=0;
      }
      if(pt>0){
          tim.push(pt);
          nam.push(pn);
      }else{
          cout<<pn<<" "<<total<<endl;
      }
  }

  return 0;

}


Measured memory_bytes: 5736
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== BigInt begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== BigInt ends ======

// ====== PBDS begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== PBDS ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll l, r, d;
    cin >> l >> r >> d;
    cout << (r/d - l/d + (l % d == 0));
}

int main(){
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 3528
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 2e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int L[N], R[N], loga[N], n, P[N], ubac[N], gran[N], k;
stack < int > s;

void add(int x, int y){
	for(x += 10 ; x < N ; x += x & -x)
		loga[x] += y;
}

int get(int x){
	int ret = 0;
	for(x += 10; x ; x -= x & -x)
		ret += loga[x];
	return ret;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 0;i < n;i++)
		scanf("%d", P + i);
	for(int i = 0;i < n;i++){
		while(!s.empty() && P[s.top()] < P[i])
			s.pop();
		if(s.empty())
			gran[i] = -1;
		else
			gran[i] = s.top();
		s.push(i);
	}
	for(;!s.empty();s.pop());
	for(int i = n - 1;i >= 0;i--){
		while(!s.empty() && P[s.top()] > P[i])
			s.pop();
		if(!s.empty())
			ubac[i] = s.top();
		else
			ubac[i] = n;
		s.push(i);
	}
	int res = 0;
	int srt = 0, pos = 0;
	for(int i = 0;i < n;i++){
		if(i)
			srt += P[i - 1] > P[i];
		if(i - k + 1 >= 0){
			if(i - k >= 0)
				srt -= P[i - k] > P[i - k + 1];
			if(srt){
				res++;
				if(i + 1 < n && ubac[i - k + 1] > i && gran[i + 1] < i - k + 2)
					res--;
			}
			else{
				pos++;
			}
		}
	}
	printf("%d\n", res + !!pos);
	return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int minChanges = Integer.MAX_VALUE;
		for(int i = 0 ; i <= S.length() - T.length(); i++) {
			int iter = 0;
			int temp = 0;
			while(iter < T.length()) {
				if(S.charAt(i+iter) != T.charAt(iter)) {
					temp++;
				}
				iter++;
			}
			minChanges = Math.min(temp, minChanges);
		}
		System.out.println(minChanges);
	}
}


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

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pair<i64, i64>> V(N);
  for (int i = 0; i < N; i++) {
    i64 a, b;
    cin >> a >> b;
    V[i] = make_pair(a - b, a + b);
  }
  sort(V.begin(), V.end(),
       [](pair<i64, i64> a, pair<i64, i64> b) { return a.second < b.second; });
  int res = 0;
  i64 cur = -(static_cast<i64>(1) << 60);
  for (int i = 0; i < N; i++) {
    if (cur > V[i].first) continue;
    res++;
    cur = V[i].second;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
{ cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


int main(){
    int x, ans=1;
    R x;
    REP(i, 1, 40){
        REP(j, 2, 10){
            if(pow(i, j) <= x && pow(i, j) > ans) ans = pow(i, j);
        }
    }
    co(ans);
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	int m; cin >> m;

	ULL C = 0, D = 0;
	rep(i, m) {
		ULL c, d; cin >> d >> c;
		C += c;
		D += c * d;
	}

	cout << C - 1 + (D - 1) / 9 << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 256
#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>
#include <bitset>
#include <iomanip>

#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'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
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(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;cin>>H>>W;
  vector<string> S(H);
  repeat(i,H)cin>>S[i];
  repeat(i,H){
    repeat(j,W)if(S[i][j]=='.'){
      S[i][j]='0';
      for(int di=-1;di<=1;di++){
        for(int dj=-1;dj<=1;dj++){
          if(di==0&&dj==0)continue;
          if(i+di<0||H<=i+di||j+dj<0||W<=j+dj)continue;
          if(S[i+di][j+dj]=='#')S[i][j]++;
        }
      }
    }
    cout << S[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();

    long k = sc.nextLong();

    int l = 0;
    int r = 1;
    List<Integer> splits = new ArrayList<>();
    do {
      while (r < s.length() && s.charAt(l) == s.charAt(r)) {
        r++;
      }
      splits.add(r - l);
      l = r;
      r = l + 1;
    } while (r < s.length());
    if (splits.size() == 1) {
      os.println(splits.get(0) * k / 2);
      return;
    }

    long ans = 0;

    long count = 0;
    for (int len : splits) {
      count += len / 2;
    }

    if (s.charAt(0) != s.charAt(s.length() - 1)) {
      ans = count * k;
      os.println(ans);
      return;
    }

    long mCount = 0;
    int last = splits.remove(splits.size() - 1);
    splits.set(0, splits.get(0) + last);
    for (int len : splits) {
      mCount += len / 2;
    }
    ans = count + (k - 1) * mCount;
    os.println(ans);
  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

unordered_map<LL,int> dp;
LL Hash = 1e9;

LL f(LL a,LL c){
    return a * Hash + c;
}

int main(){
    unordered_map<LL,vector<P>> G;
    int n,m;cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a,b,c;cin >> a >> b >> c;
        a--,b--;
        if(dp.find(f(a,c))==dp.end()){
            dp[f(a,c)]=INF;
            G[f(a,c)].pb({a+n,-1});
            G[f(n+a,-1)].pb({a,c});
        }
        G[f(a,c)].pb({b,c});
        if(dp.find(f(b,c))==dp.end()){
            dp[f(b,c)]=INF;
            G[f(b,c)].pb({b+n,-1});
            G[f(n+b,-1)].pb({b,c});
        }
        G[f(b,c)].pb({a,c});
        if(dp.find(f(a+n,-1))==dp.end()){
            dp[f(a+n,-1)]=INF;
        }
        if(dp.find(f(b+n,-1))==dp.end()){
            dp[f(b+n,-1)]=INF;
        }
    }
    priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>>> pq;
    pq.push({0,{-1,n}});
    dp[f(n,-1)]=0;
    while(!pq.empty()){
        int v=pq.top().second.second;
        int r=pq.top().second.first;
        int d=pq.top().first;
        pq.pop();
        int dd=dp[f(v,r)];
        if(dd<d) continue;
        if(r==-1){
            for(auto g:G[f(v,r)]){
                int to=g.first;
                int rr=g.second;
                int xd=dp[f(to,rr)];
                if(xd>d+1){
                    dp[f(to,rr)]=d+1;
                    pq.push({d+1,{rr,to}});
                }
            }
        }
        else{
            for(auto g:G[f(v,r)]){
                int to=g.first;
                int rr=g.second;
                int xd=dp[f(to,rr)];
                if(xd>d){
                    dp[f(to,rr)]=d;
                    pq.push({d,{rr,to}});
                }
            }
        }
    }
    int ans=INF;
    for(auto g:G[f(2*n-1,-1)]){
        ans=min(ans,dp[f(g.first,g.second)]);
    }
    if(ans==INF) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 71400
import sys

n = int(input())
A = list(map(int, input().split()))

for i in range(n):
    if A[i] % 2 == 0:
        if A[i] % 3 != 0 and A[i] % 5 != 0:
            print('DENIED')
            sys.exit()
print('APPROVED')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 n;
int g[205][205];
int color[205]; // 0: unvisited, 1: black, -1: white

bool dfs(int u, int c) {
    color[u] = c;
    rep(v, n) {
        if (g[u][v] == INF || u == v) continue;
        if (color[v] == c) return false;
        if (color[v] == 0 && !dfs(v, -c)) return false;
    }
    return true;
}

int main() {
    cin >> n;
    rep(i, n) rep(j, n) g[i][j] = INF;
    rep(i, n) g[i][i] = 0;
    rep(i, n) {
        string s; cin >> s;
        rep(j, n) {
            if (s[j] == '1') g[i][j] = g[j][i] = 1;
        }
    }

    if (!dfs(0, 1)) {
        cout << -1 << endl;
        return 0;
    }

    rep(k, n) rep(i, n) rep(j, n) {
        chmin(g[i][j], g[i][k] + g[k][j]);
    }

    int maxDist = -1;
    rep(i, n) rep(j, n) chmax(maxDist, g[i][j]);
    cout << maxDist + 1 << endl;
}


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

int main()
{
  int a,b;
  int c,d,e;
  int time,temp;

  cin >> a >> b >> c >> d >> e;

  if(a >0)
    {
      time = b-a;
      
      cout << e*time << endl;
    }
  else
    {
      temp = c*(0-a)+ d + e*b;
      cout << temp << endl;
    }
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<int> p,q,r;
	for(int i =0,j ; i<a; i++)
	{
		cin>>j;
		p.push_back(j);
	}
	for(int i =0,j ; i<b; i++)
	{
		cin>>j;
		q.push_back(j);
	}
	for(int i =0,j ; i<c; i++)
	{
		cin>>j;
		r.push_back(j);
	}
	sort(p.begin(),p.end(),greater<int>());
	sort(q.begin(),q.end(),greater<int>());
	sort(r.begin(),r.end(),greater<int>());
	multiset<int, greater<int> > m;
	for(int i = 0; i<x;i++)
		m.insert(p[i]);
	for(int i=0 ;i<y; i++)
			m.insert(q[i]);
	for(int i =0; i<x+y && i<r.size(); i++)
		m.insert(r[i]);
	ll ans =0; 
	int i=0;
	for(auto it: m)
	{
		if(i>=x+y)
			break;
		i++;	
		ans += it;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14584
use strict;
use warnings;
use utf8;

use feature qw(say);
use Data::Dumper;

my $k = <STDIN>;
chomp $k;
my ($h, $w, $m) = split / /, $k;

my $h_list = [];
my $h_count_mapping = +{};
my $w_count_mapping = +{};
while (my $input = <STDIN>) {
    chomp $input;
    last unless $input;
    my ($h_n, $w_n) = split / /, $input;
    $h_count_mapping->{$h_n} = ($h_count_mapping->{$h_n} || 0) + 1;
    $w_count_mapping->{$w_n} = ($w_count_mapping->{$w_n} || 0) + 1;

    push @$h_list, [ $h_n, $w_n, ];
}

my ($max_h, $max_h_keys) = max_in_mapping($h_count_mapping);
my ($max_w, $max_w_keys) = max_in_mapping($w_count_mapping);

my $max_h_mapping = +{map { $_ => 1 } @$max_h_keys};
my $max_w_mapping = +{map { $_ => 1 } @$max_w_keys};

my $duplicated_count = 0;
for my $one (@$h_list) {
    my $one_h = $one->[0];
    my $one_w = $one->[1];

    if ($max_h_mapping->{$one_h} && $max_w_mapping->{$one_w}) {
        $duplicated_count++;
    }
}
my $candidate_count = scalar @$max_h_keys * scalar @$max_w_keys;
my $has_duplicated = $candidate_count - $duplicated_count > 0 ? 0 : 1;
my $total_count = $max_h + $max_w - $has_duplicated;
say $total_count;


sub max_in_mapping {
    my $mapping = shift;

    my $max = 0;
    my $max_keys;

    for my $key (keys %$mapping) {
        my $count = $mapping->{$key};
        my $diff = $count - $max;
        if ($diff > 0) {
            $max = $count;
            $max_keys = [$key];
        } elsif ($diff == 0) {
            push @$max_keys, $key;
        }
    }
    return ($max, $max_keys);
}


Measured memory_bytes: 234896