akhauriyash/Code-Regression huggingface dataset:
/*#include<cstdio>
int main(){
    int n,minx,maxn;
    int num;
    scanf("%d%d%d",n,minx,maxn);
    if(n == 1 && minx != maxn){
        printf("0");
        return 0;
    }
    if(minx > maxn){
        printf("0");
        return 0;
    }
    int k = maxn - minx;
    n = n - 2;
    printf("%lld\n",(long long)(n*k+1));
    return 0;
}
*/

#include<cstdio>
using namespace std;
int main(){
    long long n,min,max;
    scanf("%lld%lld%lld",&n,&min,&max);
    if(min > max){
        printf("0\n");
        return 0;
    }
    if(n ==1 && max!=min){
        printf("0\n");
        return 0;
    }
    if(n == 1&& min == max){
        printf("1\n");
        return 0;
    }
    long long ans = 0;
    long long temp = (n-1)*max+min;
    long long temp2 = (n-1)*min+max;
    ans = temp - temp2 + 1;
    printf("%lld\n",ans);
    return 0;
}

























Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define dbg2(x,y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define dbg3(x,y,z) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl
#define dbg4(x,y,z,q) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<", "<<#q<<" = "<<q<<endl
#define dbg_array(x,sz) for (int i = 0; i < sz; ++i) cout << x[i] << " \n"[i==sz-1]
using namespace std;

const ll N = 1000 + 9, M = 400 - 9, Max_ans = 1LL * (1e16);
int a[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ECLIPSE
	freopen("input.in", "rt", stdin);
	//freopen("output.out", "wt", stdout);
#endif
	int cnt = 0;
	string a, b;
	cin >> a >> b;
	for (int i = 0; i < a.size(); ++i)
		if (a[i] != b[i])
			++cnt;
	printf("%d\n", cnt);
	return 0;
}



Measured memory_bytes: 3868
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int a = 0;
	int b = 0;
	int c = 0;

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

	if (a < b && b < c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;

}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define pb push_back
#define N_MAX 1000
#define INF (1LL << 51)

typedef long long ll;

struct Edge{
  int from, to;
  ll cost;
  Edge(int f, int t, ll c) : from(f), to(t), cost(c) {}
};

int n, m;
vector<Edge> edges;
ll d[N_MAX+1];

bool bellman_ford(){
  rep(i, N_MAX+1) d[i] =-INF;
  d[0] = 0;
  rep(i, 2*n){
    for(auto &edge:edges){
      if(d[edge.from] != INF && d[edge.to] < d[edge.from] + edge.cost){
        d[edge.to] = d[edge.from] + edge.cost;
        if(i > n && edge.to == n-1) return true;
      }
    }
  }
  return false;
}

signed main(){
  int f, t;
  ll c;
  cin >> n >> m;

  rep(i, m){
    cin >> f >> t >> c;
    f--; t--;
    edges.emplace_back(f, t, c);    
  }

  if(bellman_ford()){
    cout << "inf" << endl;
  }else{
    cout << d[n-1] << endl;
  }
}


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

int uf[10101];

void init(int n)
{
  for (int i = 1; i <= n; i++){
    uf[i] = i;
  }
}

int root(int x)
{
  if (uf[x] == x) return x;

  return uf[x] = root(uf[x]);
}

void unite(int x, int y)
{
  int rx = root(x),
      ry = root(y);
  uf[ry] = rx;
}

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

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

  init(n);

  for (int i = 0; i < q; i++){
    int f, x, y;
    cin >> f >> x >> y;

    if (f){
      cout << same(x, y) << endl;
    } else {
      unite(x, y);
    }
  }
}

Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int data = sc.nextInt();;
		for (int i = 1; data != 0; i++) {
			System.out.println("Case " + i + ": " + data);
			
			data = sc.nextInt();
		}
	}
}

Measured memory_bytes: 32984
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,K;cin>>N>>K;
    vector<int> A(N);
    int mx = 0, g = 0;
    REP(i,N){
        cin>>A[i];
        mx = max(mx,A[i]);
        g = gcd(g,A[i]);
    }
    if(K <= mx && K % g == 0){
        cout << "POSSIBLE" << '\n';
    } else {
        cout << "IMPOSSIBLE" << '\n';
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#define PI 3.14159265359
using namespace std;
int main(void){
    int a,b,h,m;
    double k;
    cin >> a >> b >> h >>m;
    k = h*30+(m/12.0*6)-m*6;
    cout << fixed << setprecision(10) << sqrt(a*a+b*b-2*a*b*cos(PI/180*k));
}

Measured memory_bytes: 4196
# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys
import copy

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())
N = int(input())
S, T = map(str, input().split())

ans = ""
for i in range(N) :
  ans += (S[i]+T[i])

print (ans)



Measured memory_bytes: 46444
import sys

import numpy as np

n, t = map(int, input().split())
knapsack = np.zeros(t, dtype=np.int64)
cuisines = [tuple(map(int, line.split())) for line in sys.stdin]
cuisines.sort()
tmp_ans = 0
for a, b in cuisines:
    tmp_ans = max(tmp_ans, knapsack.max() + b)
    knapsack[a:] = np.maximum(knapsack[a:], knapsack[:-a] + b)

print(max(tmp_ans, knapsack.max()))

Measured memory_bytes: 12512
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int m,n,sum=0,maxn;
	cin>>n;
	char a[105];
	scanf("%s",&a);
	int len=strlen(a);
	if(len>n)maxn=n;
	else maxn=len;
	for(int i=0;i<maxn;i++)
	cout<<a[i];
	if(len>n)cout<<"...";
} 

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int n, m, a[120], b[120], p = 1000000007;
int c[32777], d[32777], t[120];
long long f[2][32777], z;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = t[0] = 1; i <= 105; i++) {
		t[i] = t[i - 1] * 2 % p;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 0; j < m; j++) {
			if ((i >> a[j] & 1) & (i >> b[j] & 1)) {
				c[i]++;
			}
			if ((i >> a[j] & 1) | (i >> b[j] & 1)) {
				d[i]++;
			}
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 1 << n; j++) {
			if (~j >> i & 1) {
				continue;
			}
			f[i][j] = t[c[j]];
			for (int k = j; k > 0; k = (k - 1) & j) {
				f[i][j] = (f[i][j] + p - f[i][j - k] * t[c[k]]) % p;
			}
		}
	}
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 0; j < 1 << n; j++) {
			if ((i & j) || c[i] + c[j] != c[i | j]) {
				continue;
			}
			z = (z + f[0][i] * f[1][j] % p * t[m - d[i | j]]) % p;
		}
	}
	printf("%d\n", (t[m] + p - z) % p);
}/////www

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long x;
    cin >> x;
    long long prev=x,ans=x;
    ans+=x;
    long long count=1;
    while(ans!=prev)
    {
        ans+=x;
        count++;
        if(ans>=360)
            ans-=360;
    }
    cout << count<< "\n";
    return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF, -INF] + [int(input()) for i in range(A)] + [INF, INF]
T = [-INF, -INF] + [int(input()) for i in range(B)] + [INF, INF]

# xから見た際、最寄りの寺と神社を1件ずつ訪れる方法は以下のパターンが考えられる
# 1. 神社(正方向)→寺(正方向)
# 2. 神社(負方向)→寺(正方向)
# 3. 神社(正方向)→寺(負方向)
# 4. 神社(負方向)→寺(負方向)
# 5. 寺(正方向)→神社(正方向)
# 6. 寺(負方向)→神社(正方向)
# 7. 寺(正方向)→神社(負方向)
# 8. 寺(負方向)→神社(負方向)

d = [INF] * 8
for q in range(Q):
    x = int(input())
    # S,Tはソート済み
    # 二部探索で最寄りの神社を探す: bisectを用いる
    sp = bisect.bisect_left(S, x) # 正方向最寄神社のindex
    tp = bisect.bisect_left(T, S[sp]) # 正方向最寄寺のindex
    tn = tp - 1 # 負方向最寄寺のindex
    d[0] = abs(S[sp] - x) +  abs(S[sp]-T[tp])
    d[1] = abs(S[sp] - x) +  abs(S[sp]-T[tn])

    sn = sp - 1 # 負方向最寄神社のindex
    tp = bisect.bisect_left(T, S[sn]) # 正方向最寄寺のindex
    tn = tp - 1 # 負方向最寄寺のindex
    d[2] = abs(S[sn] - x) +  abs(S[sn]-T[tp])
    d[3] = abs(S[sn] - x) +  abs(S[sn]-T[tn])

    # 最寄りの寺を探す
    tp = bisect.bisect_left(T, x) # 正方向最寄寺のindex
    sp = bisect.bisect_left(S, T[tp]) # 正方向最寄神社のindex
    sn = sp - 1 # 負方向最寄神社のindex
    d[4] = abs(T[tp] - x) +  abs(T[tp]-S[sp])
    d[5] = abs(T[tp] - x) +  abs(T[tp]-S[sn])

    tn = tp - 1 # 負方向最寄寺のindex
    sp = bisect.bisect_left(S, T[tn]) # 正方向最寄神社のindex
    sn = sp - 1 # 負方向最寄神社のindex
    d[6] = abs(T[tn] - x) +  abs(T[tn]-S[sp])
    d[7] = abs(T[tn] - x) +  abs(T[tn]-S[sn])
    print(min(d))


Measured memory_bytes: 14232
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int step(int n){
    int ans=100000;
    for(int i=0;i<=n;i++){
        int a=0;
        int t=i;
        while(t>0){
            a += t%6;
            t /= 6;
        }
        t=n-i;
        while(t>0){
            a += t%9;
            t /= 9;
        }
        ans = min(ans, a);
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    cout << step(n) << endl;
}

Measured memory_bytes: 256
#![allow(unused_mut, non_snake_case, unused_imports, dead_code)]

use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::swap;
use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn main() {
    let mut checked = vec![false;1000000];
    input!(s:usize);
    let mut n = s as usize;
    let mut cnt = 1;
    while !checked[n]{
        checked[n] = true;
        n = if n%2==0{n/2}else{3*n+1};
        cnt += 1;
    }
    println!("{}",cnt);
}

Measured memory_bytes: 4352
X=int(input())
if(1800<=X):
    print(1)
elif(1600<=X):
    print(2)
elif(1400<=X):
    print(3)
elif(1200<=X):
    print(4)
elif(1000<=X):
    print(5)
elif(800<=X):
    print(6)
elif(600<=X):
    print(7)
elif(400<=X):
    print(8)

Measured memory_bytes: 9184
s = gets.chomp
p (0...(2 ** (s.size - 1))).to_a.map {|i|
  eval(s.chars.zip(i.to_s(2).rjust(s.size - 1, '0').chars.map{|c| c == '1' ? '+' : ' ' }).flatten.join.gsub(/\s/, ''))
}.inject(&:+)

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

#define MAX_SIZE (1 << 17)

struct team
{
    int num, score, time;
    team *self;
    bool operator<(const team& t) const
    {
        if (this->score < t.score) return true;
        if (this->score == t.score && this->num > t.num) return true;
        return false;
    }
};

int n, r, l;
team teams[MAX_SIZE * 2 - 1];

void init()
{
    int n_ = 1;

    while (n_ < n) n_ *= 2;
    for (int i = n; i < n_; i++){
        teams[i + n_ - 1].score = INT_MIN;
    }
    n = n_;
    for (int i = 0; i < n; i++){
        teams[i + n - 1].num = i + 1;
        teams[i + n - 1].self = teams + i + n - 1;
    }
    for (int i = n - 2; i >= 0; i--){
        teams[i] = max(teams[i * 2 + 1], teams[i * 2 + 2]);
    }
#if 0
    int t = 2;
    for (int i = 0; i < n * 2 - 1; i++){
        printf("%d:%d ", teams[i].num, teams[i].score);
        if (i + 2 == t){
            puts("");
            t *= 2;
        }
    }
#endif
}

void update(int d, int t, int x)
{
    static int last;

    teams[0].self->time += t - last;
    last = t;

    d += n - 2;
    teams[d].score += x;
    while (d > 0){
        d = (d - 1) / 2;
        teams[d] = max(teams[d * 2 + 1], teams[d * 2 + 2]);
    }
#if 0
    t = 2;
    for (int i = 0; i < n * 2 - 1; i++){
        printf("%d:%d:%d ", teams[i].num, teams[i].score, teams[i].time);
        if (i + 2 == t){
            puts("");
            t *= 2;
        }
    }
#endif
}

int main()
{
    scanf("%d %d %d", &n, &r, &l);
    init();

    for (int i = 0; i < r; i++){
        int d, t, x;

        scanf("%d %d %d", &d, &t, &x);
        update(d, t, x);
    }
    update(1, l, 0);

    int maxi = 0;
    for (int i = 1; i < n; i++){
        if (teams[maxi + n - 1].time < teams[i + n - 1].time) maxi = i;
    }
    printf("%d\n", maxi + 1);

    return 0;
}

Measured memory_bytes: 7172
def get_jpy oto
  return oto[0] if oto[1] == "JPY"
  return oto[0] * 380000.0
end
num = gets.to_i
otoshidamas = []
otoshidama = []
num.times do
  otoshidamas << gets.split(" ")
end
otoshidamas.each do|hitori|
  otoshidama << [hitori[0].to_f,hitori[1]]
end
puts otoshidama.map{|oto|get_jpy(oto)}.inject(:+)

Measured memory_bytes: 1788
void main(){
	int n, k;
	readf("%d %d\n", &n, &k);
	string st = readln().chomp();
	char[] ans;
	foreach(i, ch; st)ans ~= (i==k-1)? ch.toLower(): ch;
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll X, Y;
    cin >> X >> Y;
    rep(i, X+1){
      if(2 * i + 4 * (X - i) == Y){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=5)
	{
		cout<<0<<endl;
	}
	else if(a<=12)
	{
		cout<<b/2<<endl;
	}
	else
	{
		cout<<b<<endl;
	}
	
	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n+1);
  for(int i=1; i<=n; i++){
    cin >> h[i];
  }
  // 連結リスト
  vector <int > list[n+1];
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    list[a].push_back(b);
    list[b].push_back(a);
  }
  // 同じもの削除
  for(int i=1; i<=n; i++){
    list[i].erase(unique(list[i].begin(), list[i].end()), list[i].end());
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    bool flag=true;
    for(auto c: list[i]){
      if(h[c] >= h[i])flag=false;
    }
    if(flag)ans+=1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8812
import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            ans += k - j - 1
print(ans)


Measured memory_bytes: 3188
s = STDIN.gets.strip
t = STDIN.gets.strip

storable = false

matched = []

(s.size - t.size + 1).times do |offset|
  exact_match = 0
  wildcard_match = 0
  not_match = false
  t.chars.each_with_index do |c, i|
    if (s[offset + i] == c)
      exact_match += 1
    elsif s[offset + i] == '?'
      wildcard_match += 1
    elsif s[offset + i] != '?' && s[offset + i] != c
      not_match = true
      break
    end
  end

  if not_match
    next
  elsif exact_match > 0 || wildcard_match == t.length
    str = if offset > 0
            s[0..offset-1]
          else
            ''
          end
    str = str + t[0..-1] + s[offset+t.length..-1]
    storable = true
    matched << str.gsub(/\?/, 'a')
  end
end

if !storable
  puts 'UNRESTORABLE'
else
  puts matched.sort.first
end


Measured memory_bytes: 1788
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    n, m, x = map(int, input().split())
    c = []
    a = []
    cost_list = []
    for i in range(n):
        tmp = list(map(int, input().split()))
        c.append(tmp[0])
        a.append(tmp[1: m + 1])
    for i in range(1, n + 1):
        sets = list(itertools.combinations(range(1, n+1), i))
        # print(sets)
        for j in sets:
            cost = 0
            a_score = [0]*m
            for k in j:
                cost += c[k - 1]
                for l in range(m):
                    a_score[l] += a[k - 1][l]
            flg = 0
            for k in a_score:
                if k < x:
                    flg = 1
            if flg == 0:
                cost_list.append(cost)

    if len(cost_list) == 0:
        print(-1)
    else:
        print(min(cost_list))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

vector<int> ans, color;
vector<vector<int>> vec;

void bfs() {
    queue<int> q;
    q.push(0);
    ans[0] = 0;
    color[0] = 1;
    while(!q.empty()) {
        int i = q.front(); q.pop();
        for (auto j : vec[i]) {
            if (color[j] == 0) {
                q.push(j);
                ans[j] = i + 1;
                color[j] = 1;
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vec = vector<vector<int>>(N, vector<int>(0));
    ans = vector<int>(N, 0);
    color = vector<int>(N, 0);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        vec[A - 1].push_back(B - 1);
        vec[B - 1].push_back(A - 1);
    }
    bfs();
    bool flag = true;
    rep(i, N - 1) {
        if (ans[i + 1] == 0) flag = false;
    }
    if (flag) {
    cout << "Yes" << endl;
        rep(i, N - 1) {
            cout << ans[i + 1] << endl;
        }
    } else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 10640
using System;
using System.Linq;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] line = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            Array.Sort(line);

            Console.WriteLine(string.Join(" ", line));
        }
    }
}


Measured memory_bytes: 20488
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll n,m;
vvl G(1005);
vvl rG(1005);

bool visit[1005];
bool rvisit[1005];
bool reachable[1005];

void dfs(ll u){
    visit[u] = true;
    for(auto v : G[u]){
        if(visit[v]) continue;
        dfs(v);
    }
}

void rdfs(ll u){
    visit[u] = true;
    for(auto v : rG[u]){
        if(visit[v]) continue;
        rdfs(v);
    }
}

int main(){
    cin >> n >> m;
    vector<tuple<ll,ll,ll>> edges;
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(b);
        rG[b].push_back(a);
        edges.emplace_back(a,b,-c);
    }
    rep(i,n) reachable[i] = true;
    rep(i,n-1){
        rep(j,n) visit[j] = false;
        dfs(i);
        if(!visit[n-1]) reachable[i] = false;
    }
    REP(i,1,n+1){
        rep(j,n) visit[j] = true;
        rdfs(i);
        if(!visit[0]) reachable[i] = false;
    }
    bool upd = true;
    vl d(n,LINF);
    d[0] = 0;
    ll cnt = 0;
    while(upd){
        upd = false;
        rep(i,m){
            ll a,b,c;
            tie(a,b,c) = edges[i];
            if(!reachable[a]) continue;
            if(!reachable[b]) continue;
            rep(i,n){
                ll dis = d[a] + c;
                if(dis < d[b]){
                    d[b] = dis;
                    upd = true;
                }
            }
        }
        cnt++;
        if(cnt > n){
            puts("inf");
            return 0;
        }
    }
    cout << -d[n-1] << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new Scanner(System.in);
		int i=0;
		int x;
		do{
			i++;
			x= scan.nextInt();
			if(x==0) break;
			
			System.out.println("Case "+i+": "+x);
		}while(true);
		

	}

}

Measured memory_bytes: 32960
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll ans, ten[20];
int nodes;
void rec(int keta, int pos, ll d, vi v){
	if(pos * 2 + 1 >= keta){
		if(d != 0) return;
		
		ll tmp = 1;
		if(keta % 2) tmp *= 10;
		
		rep(i, v.size()){
			int cnt = 0;
			rep(j, 10){
				int k = j - v[i];
				if(k < 0 || k > 9 || i == 0 && k == 0) continue;
				cnt++;
			}
			tmp *= cnt;
		}
		ans += tmp;
		return;
	}
	
	ll k = ten[keta - pos - 1] - ten[pos], lim = 0;
	for(int i = pos + 1; i * 2 < keta; i++){
		lim += ten[keta - i - 1] - ten[i];
	}
	assert(k > 9 * lim);
	
	v.pb(0);
	for(int i = -9; i <= 9; i++){
		double rem = d - 1.0 * k * i;
		if(rem < 100 && rem + 9.0 * lim < -100) continue;
		if(rem > -100 && rem - 9.0 * lim > 100) continue;
		v[v.size() - 1] = i;
		rec(keta, pos + 1, d - k * i, v);
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	ten[0] = 1;
	rep(i, 19) ten[i + 1] = ten[i] * 10;
	
	int d; cin >> d;
	for(int keta = 2; keta <= 18; keta++) rec(keta, 0, d, vi(0));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}

ll Max=-1000000000,Min=1e9+1;
       
int main(){
    int x=0,y=0,z=0,n,m,h,k=0,w,sum2=0,ans=0;
    string s,t;
    bool f=true;
    cin >> n;
    set<int> a;
    a.insert(n);
    ans = 1;
    while(1){
        ans++;
        if(n%2==0){
            if(a.find(n/2) != a.end()){
                cout << ans << endl;
                return 0;
            }
            else {
                a.insert(n/2); 
                n/=2;
            }
        }
        else{  
            if(a.find(3*n+1) != a.end()){
                cout << ans << endl;
                return 0;
            }
            else {
                a.insert(3*n+1); 
                n=3*n+1;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
using System;
class Program
{
    static long mod = (long)1e9 + 7;
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int length = Console.ReadLine().Length;
        long[,] dp = new long[N + 1, N + 1];
        dp[0, 0] = 1;
        for (int n = 0; n < N; n++)
        {
            for (int l = 0; l <= n; l++)
            {
                dp[n + 1, Math.Max(l - 1, 0)] += dp[n, l];
                dp[n + 1, Math.Max(l - 1, 0)] %= mod;
                dp[n + 1, l + 1] += (2 * dp[n, l]) % mod;
                dp[n + 1, l + 1] %= mod;
            }
        }
        long ans = dp[N, length];
        long d = Pow(2, mod - 2);
        d = Pow(d, length);
        ans *= d;
        ans %= mod;
        Console.WriteLine(ans);
    }
    static long Pow(long a, long n) //a^nをmodで割ったあまり
    {
        if (n == 0)
            return 1;
        if (n == 1)
            return a % mod;
        long z = Pow(a, n / 2);
        if (n % 2 == 0)
            return z * z % mod;
        return z * z % mod * a % mod;
    }
}

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

ans = '-1 -1'
for i in range(len(s)-2):
    if s[i] == s[i+1]:
        ans = str(i+1) + ' ' + str(i+2)
        break
    elif s[i] == s[i+2]:
        ans = str(i+1) + ' ' + str(i+3)
        break
if len(s) == 2 and s[0] == s[1]:
    ans = '1 2'
print(ans)

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

const int vmax=2010;

int X,Y;
vector<int> graph[vmax];
int match[vmax];
bool used[vmax];

bool dfs(int v){
	used[v]=true;
	for(auto &u:graph[v]){
		int w=match[u];
		if(w < 0 || (!used[w] && dfs(w)) ){
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(){
	int res=0;
	rep(i,vmax) match[i]=-1;
	rep(v,X+Y){
		if(match[v]<0){
			rep(i,vmax) used[i]=0;
			if(dfs(v)) res++;
		}
	}
	return res;
}


int n,m,l;
int dist[110][110];
pair<int,int> info[1010];

int main(void){
	while(cin >> n >> m >> l){
		if(n==0) break;
		rep(i,vmax) graph[i].clear();
		rep(i,n)rep(j,n) dist[i][j]=((i==j)?0:1<<20);
		rep(i,m){
			int u,v,d;
			cin >> u >> v >> d;
			dist[u][v]=min(dist[u][v],d);
			dist[v][u]=min(dist[v][u],d);
		}
		rep(k,n)rep(i,n)rep(j,n) dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

		rep(i,l) cin >> info[i].second >> info[i].first;
		sort(info,info+l);
		X=Y=l-1;
		rep(i,l-1)rep(j,l-1){
			if(i>j) continue;
			int a=i,b=j+1;
			if(dist[info[b].second][info[a].second]>info[b].first-info[a].first) continue;
			b+=X-1;
			graph[a].push_back(b);
			graph[b].push_back(a);
		}
		cout << l-bipartite_matching() << endl;
	}
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x_r = -100;
  int y_l = 100;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    x_r = max(x_r, x);
  }
  for (int i = 0; i < M; ++i) {
    int y;
    cin >> y;
    y_l = min(y_l, y);
  }
  if (y_l <= x_r || Y <= X || Y <= x_r || y_l <= X) cout << "War" << endl;
  else cout << "No War" << endl;
}

Measured memory_bytes: 256
/**
 * C - Minimization
 * https://atcoder.jp/contests/abc101/tasks/arc099_a
 * 
 * ポイント
 * 全てが1になるまでの回数
 **/
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int target;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    cout << ceil((float)(N-1)/(K-1)) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ull unsigned long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007

ll max(ll a,ll b)
{
    if(a>b)
    {
        return a;
    }
    return b;
}

ll min(ll a,ll b)
{
    if(a<b)
    {
        return a;
    }
    return b;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a, b);
}


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

ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

ull bin(ull a, ull b)
{
    ull res = 1;
    while(b)
    {
        if(b&1) res = (res*a)%mod;
        a = ((a%mod)*(a%mod))%mod;
        a %= mod;
        b >>= 1;
    }
    return res%mod;
}

class DSU {
public:
    int n;
    vector<int> parent,size;

    DSU(int a) {
        n = a;
        parent.assign(n,0);
        size.assign(n,0);
        for(int i=0 ; i<n ; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    void makeSets(int k) {
        for(int i=0 ; i<n ; i++) {
            if(find(i) != i) {
                size[i] = 0;
            }
        }
    }

    int find(int a) {
        int root = a;
        while(root != parent[root]) {
            root = parent[root];
        }
        while(root != a) {
            int temp = parent[a];
            parent[a] = root;
            a = temp;
        }
        return root;
    }

    void unionSet(int a, int b) {
        int root_a = find(a);
        int root_b = find(b);
        if(root_a == root_b) return;
        if(size[a] < size[b]) {
            parent[root_a] = root_b;
            size[root_b] += size[root_a];
        }
        else {
            parent[root_b] = root_a;
            size[root_a] += size[root_b];
        }
    }
};

ll sum(ll a[],ll l,ll r)
{
    ll s=0;
    for(int i=l;i<=r;i++)
    {
        s+=a[i];
    }
    return s;
}

int main() {

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


ll x;
cin>>x;
ll ans=0;

ans=(1000)*(x/500);

ll a=x/500;
x-=(500*a);

ans+=(5)*(x/5);

cout<<ans;




    return 0;


}

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

using namespace std;

struct cmp {
  bool operator()(const int &a, const int &b) const {
    return a > b;
  }
};

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

  int n, a;
  cin >> n;
  map<long long, int, cmp> hash;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    hash[a]++;
  }
  int done = 0;
  long long res = 1;
  for (auto &h: hash) {
    if (done > 1) break;
    if (h.second > 3) {
      if (done == 0) res = h.first * h.first;
      else res *= h.first;
      done = 2;
    } else if (h.second > 1) {
      done++;
      res *= h.first;
    }
  }
  cout << (done < 2 ? 0 : res) << endl;

  return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n;
  cin >> n;
  ll ans=0;
  int mi_cnt=0;
  ll mi=INF;
  REP(i,n){
    ll a;
    cin >> a;
    ans+=abs(a);
    if(a<0)mi_cnt++;
    chmin(mi,abs(a));
  }
  if(mi_cnt%2==0){
    cout << ans << endl;
  }else{
    cout << ans - 2*mi << endl;
  }
}



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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

template <class T>
T fac(T n)      // template function to find factorial of a number
{ 
    T res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
}
template<class T>
T lcm(T a, T b)     //template function to find lcm of two numbers 
{
    return (a * b) / __gcd(a,b);
}
template<class T>
T digitsum(T x)
{
    T sum = 0;
    while(x)
    {
        sum += x%10;
        x /= 10;
    }
    return sum;
}
// ternary search
/*double ternary(double l, double r){
    double eps = 1e-9;
    while(r - l > eps){
        double m1 = l + (r - l)/3;
        double m2 = r - (r - l)/3;
        double f1 = f(m1);
        double f2 = f(m2);
        if(f1 < f2)
            l = m1;
        else r = m2;
    }
    return f(l);
}*/
void nPermute(string str, int n)  //function to find nth  lexi string
{ 
    sort(all(str));
    int i = 1; 
    do {
        if (i == n) 
            break; 
  
        i++; 
    } while (next_permutation(str.begin(), str.end())); 
    cout<<str<<endl;
} 
vector<int> factors(int n) 
{ 
    vector<int> f; 
    for(int x = 2; x * x <= n; x++) { 
        while (n % x == 0) { 
            f.push_back(x); 
            n /= x; 
        } 
    } 
    if (n > 1) f.push_back(n); 
    return f; 
}
bool prime(int n) 
{ 
    if (n < 2)
        return false;
    for(int x = 2; x*x <= n; x++) 
        if (n%x == 0) 
            return false; 
    return true; 
}
// binomial coeficient in O(K) 
int ncr(int n, int k){
    int res = 1;
    if(k > n - k)
        k = n - k;
    for(int i = 0; i < k; i++){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
tuple<int, int, int> Gcd(int a, int b)      //extended Euclids Algorithm
{
    if(b == 0)
        return {1, 0, a};
    else{
        int x, y, g;
        tie(x, y, g) = Gcd(b, a%b);
        return {y, x - (a/b)*y, g};
    }
}     // modular Exponentiation x^n mod m = x^(n mod (m - 1)) mod m : if n  is very large;
int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void solve()
{
    int n, sum = 0;
    cin >> n;
    V a(n);
    for(auto & i : a){
        cin >> i;
        if(sum == 0)    sum = i;
        else sum ^= i;
    }
    for(auto i : a)
        cout << (sum ^ i) << " ";
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

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

#define int long long int 
#define endl "\n"
typedef long double ld ;

const int maxn = 1e5 + 5 ;
int Parent[maxn] ;
int Rank[maxn] ;
int Sizex[maxn] ;


int Find(int x)
{
    if(Parent[x] != x ) 
    {
        Parent[x] = Find(Parent[x]);
    }
    return Parent[x] ;
}

void join( int x , int y )
{
    int px = Find(x) ;
    int py = Find(y) ;
    if(Rank[px] > Rank[py])
    {
        Parent[py] = px ;
        Sizex[px] += Sizex[py] ;
        Sizex[py] = 0 ;
    }
    else
    {
       Parent[px] = py ;
       Sizex[py] += Sizex[px] ;
       Sizex[px] = 0 ;
       if( Rank[px] != Rank[py])
       {
         Rank[py]++;
       }
    }
}


int32_t main() 
{
   
  /* #ifndef ONLINE_JUDGE 
   freopen("input.txt","r",stdin) ;
   freopen("output.txt","w",stdout);
   #endif */
   int N , M ;
   cin >> N >> M ;
   int A[M+1],B[M+1] ;
   for(int i = 1;i <= M ; i++ ) 
   {
     cin >> A[i] >> B[i] ;
   }
   vector<int>Ans(M+1);
   Ans[M] = ( N * ( N - 1 ) ) / 2 ;

   for(int i = 1 ; i <= N ; i++ ) 
   {
     Parent[i] = i ;
     Rank[i] = 0 ;
     Sizex[i] = 1 ; 
   }

   for(int i = M ; i > 1 ; i--)
   {
      int x = Find(A[i]);
      int y = Find(B[i]) ;
      int First = Sizex[x] ;
      int Second = Sizex[y] ;
      int sum = First * Second ;
      if(x != y ) 
      {
         join(x,y) ;
         Ans[i-1] = Ans[i] - (sum );
         Ans[i-1] = max(0LL,Ans[i-1]) ;
      }
      else 
      {
         Ans[i-1] = Ans[i] ;
      }
   }
   for(int i = 1; i <= M ; i++ ) 
   {
     cout<<Ans[i]<<endl;
   }
  
}


Measured memory_bytes: 6016
import java.util.*;
import java.util.Map.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int n=s.nextInt(),m=s.nextInt();
		int[]p=new int[m];
		int[]y=new int[m];
		String[]r=new String[m];
		HashMap<Integer,TreeMap<Integer,Integer>>map=new HashMap<>();
		for(int q=0;q<m;++q) {
			p[q]=s.nextInt();
			y[q]=s.nextInt();
			map.computeIfAbsent(p[q],i->new TreeMap<>()).put(y[q],q);
		}
		for(Entry<Integer,TreeMap<Integer,Integer>> e:map.entrySet()) {
			int no=0;
			for(Entry<Integer,Integer>f:e.getValue().entrySet()) {
				r[f.getValue()]=String.format("%06d%06d",e.getKey(),++no);
			}
		}
		Arrays.stream(r).forEach(System.out::println);
	}
}

Measured memory_bytes: 185496
#include <stdio.h>
 
int main()
{
  int N;
  scanf("%d", &N);

  int A[21];
  for (int i=1; i<=N; i++) scanf("%d", A+i);

  int B[21];
  for (int i=1; i<=N; i++) scanf("%d", B+i);

  int C[20];
  for (int i=1; i<N; i++) scanf("%d", C+i);

  int ret = 0;
  for(int i=1; i<=N; i++)
  {
    ret += B[A[i]];
    if (i!=1 && A[i-1] == A[i]-1) ret += C[A[i-1]];
  }
    
  printf("%d\n", ret);
  return 0;  
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using Int = long long;
int N, K;
vector<Int> A, B;

int get(int N) {
    int ret = 0;
    rep(i, 31) if (N >> i & 1) ret = i;
    return ret;
}
Int f(int one) {
    Int ret = 0;
    rep(i, N) {
        if ((A[i] >> one & 1) == 0) {
            if (((K >> one) & (A[i] >> one)) == (A[i] >> one)) {
                ret += B[i];
            }
        }
    }
    // cout << one << endl;
    // cout << "ret = " << ret << endl;
    return ret;
}

int main() {
    cin >> N >> K;
    A.resize(N), B.resize(N);
    rep(i, N) cin >> A[i] >> B[i];

    Int ans = 0;
    Int s = 0;
    rep(i, N) if (get(K) > get(A[i])) s += B[i];
    ans = max(ans, s);
    s = 0;
    rep(i, N) if ((K & A[i]) == A[i]) s += B[i];
    ans = max(ans, s);
    vector<int> ones;
    rep(i, 31) if (K >> i & 1) ones.push_back(i);
    // for (auto one : ones) cout << "one = " << one << endl;
    for (auto one : ones) ans = max(ans, f(one));
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

void f(vector<vector<LL>>& graph,vector<LL>& c,vector<bool>& visited,vector<LL>& res,LL idx,LL& num){
  visited[idx] = true;
  REP(i,graph[idx].size()){
    LL next = graph[idx][i];
    if(!visited[next]){
      f(graph, c, visited, res, next, num);
    }
  }
  res[idx] = c[num];
  num++;
}

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

  LL N;
  cin>>N;
  vector<vector<LL>> graph(N);
  REP(i,N-1){
    LL a, b;
    cin>>a>>b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  vector<LL> c(N);
  REP(i,N){
    cin >> c[i];
  }

  SORT(c);

  vector<bool> visited(N, false);
  vector<LL> ans(N);
  LL num = 0;
  f(graph, c, visited, ans, 0, num);
  LL sum = 0;
  REP(i,graph.size()){
    REP(j,graph[i].size()){
      LL a = i;
      LL b = graph[i][j];
      sum += min(ans[a], ans[b]);
    }
  }
  sum /= 2;
  cout << sum << endl;
  REP(i,ans.size()){
    if(i!=0){
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int N;
VV<int> G;
V<int> biggest;
V<int> vallink;
V<int> red;
V<int> blue;
V<int> childbluesum;
V<int> par;

void dfs(int v,int p,int mx,int addto,bool skipped){
	if(v==0){
		for(int u:G[v]){
			dfs(u,v,0,0,false);
		}
		return;
	}
	if(!skipped){
		par[v] = p;
		if(mx < v){
			biggest[v] = mx;
			vallink[v] = addto;
			for(int u:G[v]) if(u!=p){
				int nv = u;
				int np = v;
				int nmx = v;
				int naddto = u;
				dfs(nv,np,nmx,naddto,false);
			}

			//skip
			{
				for(int u:G[v]) if(u!=p){
					int nv = u;
					int np = v;
					int nmx = mx;
					int naddto = u;
					dfs(nv,np,nmx,naddto,true);
				}
			}
		}else{
			biggest[v] = mx;
			vallink[v] = addto;
			red[addto]++;
			for(int u:G[v]) if(u!=p){
				int nv = u;
				int np = v;
				int nmx = mx;
				int naddto = addto;
				dfs(nv,np,nmx,naddto,false);
			}
		}
	}else{
		if(mx < v){
			return;
		}else{
			blue[addto]++;
			for(int u:G[v]) if(u!=p){
				int nv = u;
				int np = v;
				int nmx = mx;
				int naddto = addto;
				dfs(nv,np,nmx,naddto,true);
			}
		}
	}
}

void dfs2(int v,int p){
	for(int u:G[v]) if(u!=p){
		childbluesum[v] += blue[u];
		dfs2(u,v);
	}
}


//memo;
V<int> memo;

int dfs3(int v){
	if(v==0){
		return 1;
	}
	if(memo[v] != -1) return memo[v];
	if(v > biggest[v]){
		int sum = childbluesum[v] + red[vallink[v]] + 1;
		int res = sum + dfs3(biggest[v]) - blue[vallink[v]];
		return memo[v] = res;
	}else{
		int res = red[vallink[v]] - blue[vallink[v]] + dfs3(biggest[v]);
		return memo[v] = res;
	}
}




int main(){
	cin>>N;
	G.resize(N);
	biggest.resize(N);
	red.resize(N);
	blue.resize(N);
	par.resize(N);
	vallink.resize(N);
	childbluesum.resize(N);
	memo.resize(N);rep(i,N) memo[i] = -1;

	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1,-1,0,false);

	dfs2(0,-1);


	rep1(i,N-1) cout<<dfs3(i)-1<<" ";
	puts("");
}

Measured memory_bytes: 30592
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int a, b;
  cin >> a >> b;
  if (a != 1 && b != 1) cout << 1 << endl;
  else if (a != 2 && b != 2) cout << 2 << endl;
  else cout << 3 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int,string>P;
bool F(P a,P b)
{return a.first>b.first;};
int main()
{
	int n,a,b,c,i,x=0;
	while(scanf("%d",&n),n)
	{
		char s[99];
		pair<int,string>p[10];
		for(i=0;i<n;++i)
			scanf("%s%d%d%d",s,&a,&b,&c),p[i].second=s,p[i].first=3*a+c;
		stable_sort(p,p+n,F);
		printf("%s",(x++?"\n":""));
		for(i=0;i<n;++i)
			printf("%s,%d\n",p[i].second.c_str(),p[i].first);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
  int x,y,z;
  scanf("%d %d %d", &x, &y, &z);
  if(x>=y&&y>=z){
    printf("%d %d %d\n",z,y,x);
  }else if(x>=z&&z>=y){
    printf("%d %d %d\n",y,z,x);
  }else if(y>=x&&x>=z){
    printf("%d %d %d\n",z,x,y);
  }else if(y>=z&&z>=x){
    printf("%d %d %d\n",x,z,y);
  }else if(z>=x&&x>=y){
    printf("%d %d %d\n",y,x,z);
  }else{
    printf("%d %d %d\n",x,y,z);
  }
  return 0;
}


Measured memory_bytes: 2044