akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

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

    int N = sc.nextInt();

    String[][] A = new String[N][2];
    for (int i = 0; i < N; i++) {
      A[i] = sc.next().split("");
    }

    String[][] bubbledA = bubbleSort(A, N);
    String[][] selectedA = selectionSort(A, N);

    printArray(bubbledA);
    printIsStable(isStable(A, bubbledA));
    printArray(selectedA);
    printIsStable(isStable(A, selectedA));
  }

  private static Map<String, String> cardMap(String[][] a) {
    Map<String, String> cardMap = new HashMap<>();
    for (int i = 0; i < a.length; i++) {
      String key = String.valueOf(a[i][1]);
      if (!cardMap.containsKey(key)) {
        cardMap.put(key, "");
      }
      cardMap.put(key, cardMap.get(key) + a[i][0]);
    }
    return cardMap;
  }
  private static boolean isStable(String[][] in, String[][] out) {
    Map<String, String> inMap = cardMap(in);
    Map<String, String> outMap = cardMap(out);

    for (String key : inMap.keySet()) {
      if (!inMap.get(key).equals(outMap.get(key))) {
        return false;
      }
    }

    return true;
  }

  private static String[][] bubbleSort(String[][] a, int n) {
    String[][] copy = copy(a);

    for (int i = 0; i < n; i++) {
      for (int j = n-1; j > i; j--) {
        if (Integer.parseInt(copy[j][1]) < Integer.parseInt(copy[j-1][1])) {
          swap(copy, j, j-1);
        }
      }
    }

    return copy;
  }

  private static String[][] selectionSort(String[][] a, int n) {
    String[][] copy = copy(a);

    for (int i = 0; i < n; i++) {
      int minj = i;
      for (int j = i; j < n; j++) {
        if (Integer.parseInt(copy[j][1]) < Integer.parseInt(copy[minj][1])) {
          minj = j;
        }
      }
      if (i != minj) {
        swap(copy, i, minj);
      }
    }

    return copy;
  }

  private static String[][] copy(String[][] a) {
    String[][] copy = new String[a.length][2];
    for (int i = 0; i < a.length; i++) {
      for (int j = 0; j < 2; j++) {
        copy[i][j] = a[i][j];
      }
    }
    return copy;
  }

  private static void printArray(String[][] a) {
    String joined = Arrays.stream(a).map(e -> e[0] + e[1]).collect(Collectors.joining(" "));
    System.out.println(joined);
  }

  private static void printIsStable(boolean stable) {
    System.out.println(stable ? "Stable" : "Not stable");
  }

  private static void swap(Object[] a, int n, int m) {
    Object tmp = a[n];
    a[n] = a[m];
    a[m] = tmp;
  }
}


Measured memory_bytes: 32584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const int sz = 100002;
int n, k;
vector<int>a;
int main() {
	io
	string s, t;
	cin>>s>>t;
	if(t.size() != s.size()+1) cout<<"No"<<endl;
	else {
		bool x = true;
		for(int  i = 0; i<s.size(); i++) {
			if(s[i]!=t[i]) x = false;
		}
		if(x) cout<<"Yes";
		else cout<<"No";
	}
}




Measured memory_bytes: 3644
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#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
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const ll inf = 1e18 + 7;

void solve(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<vector<long long>> dp (n + 1 , vector<long long> (n + 1 , -inf));
  for (int i = n - 1; i >= 0; i--){
    for (int j = i; j < n; j++){
      if (i == j) dp[i][j] = a[i];
      else{
        assert (j >= i + 1);
        dp[i][j] = max (dp[i][j] , a[i] - dp[i + 1][j]);
        dp[i][j] = max (dp[i][j] , a[j] - dp[i][j - 1]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



Measured memory_bytes: 73668
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int num=(int)1e6+1;

void go()
{
    string s,t;
    cin>>s;
    cin>>t;
    string temp=t.substr(0,(int)t.size()-1);
    if(s == temp )
    {
        cout<<"Yes";
        return;
    }
    else
    {
        cout<<"No";
        return;
    }
}
int main()
{
    FIO;
    go();
    return 0;
}



Measured memory_bytes: 3636
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,1);
  var set = new Set();
  set.add(1);
  for(var i = 2; i <= Math.sqrt(input); i++){
    var tmp = i;
    while(tmp <= input){
       set.add(tmp);
      tmp *= i;
    }
  }
  while(true){
     if(set.has(input)){
        myout(input);
       return;
     }else{
       input--;
     }
  }
  
}
Main(myin());

Measured memory_bytes: 7500
#include <iostream>
#include <string>

using namespace std;

int N;
string S;

int c[30];

long long int MOD = 1000000007;

int main(void) {

	cin >> N;
	cin >> S;

	for (int i = 0; i < N; i++) {
		c[S[i] - 'a']++;
	}

	long long int ans = 1;

	for (int i = 0; i < 26; i++) {
		ans *= c[i] + 1;
		ans %= MOD;
	}

	ans--;

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
int main() {
	int x;
	while (cin >> x, x) {
		ll cnt = 0; 
		for (int i = 2; i <= x; i++) {
			if (2 * i <= x && prime(i) && prime(x - i)) cnt++;
		}
		cout << cnt << endl;
	}
}





Measured memory_bytes: 3000
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> x >> y;
	cout<<min(n*x,y);
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


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

int main(){
  int N;
  long long sum=0;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum += A[i];
  }
  
  long long ss=0,m=sum;
  int index=0;
  for(int i=0;i<N;i++){
    m=min(m,abs(sum-2*ss));
    ss += A[i];
  }
  cout << m << endl;
}






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

int main(){
  string s; cin >> s;
  vector<int> v;
  for (int i = 0; i < s.size(); i++) {
    v.push_back(s[i]-'0');
  }
  long long ans = 0;
  for (int i = 0; i < (1 << s.size() - 1); i++) {
    long long t = v[0];
    for (int k = 0; k < s.size()-1; k++) {
      if ((i >> k) & 1){
        ans += t;
        t = v[k+1];
      } else {
        t *= 10;
        t += v[k+1];
      }
    }
    if (t >= 0) ans += t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int n;
	long int res;
	/*****処理部*****/
	cin >> n;
	res = 1;
	if(n != 0){
		for(int i=2;i<=n;i++){
			res = res * i;
		}
	}
	cout << res << endl;
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b,c,p,q,r,count=0,f=0;
    cin>>a>>b>>c;
    

    while(a%2==0&&b%2==0&&c%2==0&&a>=0&&b>=0&&c>=0)
    {   
        if(a==b&&b==c)
        {
            f=1;
            break;
        }
        count++;
        p=a/2,q=b/2,r=c/2;
        a=(q+r),b=(p+r),c=(p+q);
        //cerr<<a<<" "<<b<<" "<<c<<endl;
    }
    if(!f&&(a&1||b&1||c&1))
        cout<<count<<endl;

    else
    {
        cout<<-1<<endl;
    }
}
return 0;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // height: index
        Map<Integer, Integer> hs = new HashMap<>();
        int n = scan.nextInt();
        boolean[] hasNei = new boolean[n];
        Arrays.fill(hasNei, false);
        boolean[] isBad = new boolean[n];
        Arrays.fill(isBad, false);
        int nEdge = scan.nextInt();
        for (int i = 0; i < n; i++) {
            hs.put(i, scan.nextInt());
        }
        for (int i = 0; i < nEdge; i++) {
            int l = scan.nextInt();
            int r = scan.nextInt();
            hasNei[l - 1] = true;
            hasNei[r - 1] = true;
            if (hs.get(l - 1) >= hs.get(r - 1)) {
                isBad[r - 1] = true;
            }
            if (hs.get(l - 1) <= hs.get(r - 1)) {
                isBad[l - 1] = true;
            }

        }
        scan.close();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (!hasNei[i]) { cnt ++; continue;}

            if (!isBad[i]) { cnt ++;}
        }

        System.out.println(cnt);
    }
}





Measured memory_bytes: 69372
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

//#define MOD (int)(1e5 + 7)
#define MOD (100007)

static inline void done(const char *s)
{
	puts(s);
	exit(0);
}

#define yes() done("Yes");
#define no() done("No");
#define invalid() done("-1");

static int comp(const void *a, const void *b)
{
	int *pa = (int *)a;
	int *pb = (int *)b;
	return *pa < *pb;
}

static inline int *readNint(int n)
{
	int *a = calloc(sizeof(int), n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	return a;
}

static inline long *readNlong(int n)
{
	long *a = calloc(sizeof(long), n);
	for (int i = 0; i < n; i++)
		scanf("%ld", &a[i]);
	return a;
}

int main(int argc, char **argv)
{
	int N;
	char S[3];
	scanf("%s", S);
	char f = S[0];
	for (int i = 1; i < 3; i++) {
		if (S[i] != f) {
			yes();
		}
	}
	no();
	return 0;
}


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

int main()
{
	string str;
	cin >> str;
	
	if ( str.find("9") != string::npos )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}

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

using ll = long long;
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
#define swap(x, y)    \
  {                   \
    auto ___temp = x; \
    x = y;            \
    y = ___temp;      \
  }

const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int x[2] = {};
  repi(n) x[s[i] - '0']++;
  cout << min(x[0], x[1]) * 2 << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){

int H,W,i,j;

    for(;;){
        scanf("%d %d\n",&H,&W);
        if(H==0&&W==0)break;
        for(j=1;j<=H;j++){
            for(i=1;i<=W;i++){
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
    
    return 0;
    
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    if (s.size() % 2) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < s.size(); i += 2) {
        if (s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>()
#define VLL vector<long long>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

#define MAX_V 100000          //最大頂点数を置き換えること
#define P pair<int , int>
struct edge { int to, cost; };
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int mark[MAX_V];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>	que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

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

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int M;  cin >> V >> M;
    REP(i, MAX_V)  mark[i] = -1;
    REP(i, M){
      int a, b;  cin >> a >> b;
      G[a-1].push_back(edge{b-1, 1});
      G[b-1].push_back(edge{a-1, 1});
    }

    dijkstra(0);
    for(int i = 1 ; i < V ; i++)
      if(mark[i] == -1){  cout << "No" << endl;  return 0;  }
    
    cout << "Yes" << endl;
    for(int i = 1; i < V; i++)
      cout << mark[i] + 1 << endl;
    return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;

int main() {
	int N, M; cin >> N >> M;
	N *= 2;
	vi a(N); rep(i, N) cin >> a[i];
	sort(ALL(a));

	int l = 0, r = N;
	bool f1 = 1;
	rep(i, N) {
		if (a[i] + a[N-1-i] < M) {
			f1 = 0;
		}
	}
	if (f1) r = 0;

	while (r - l > 1) {
		int m = (l + r) / 2;
		bool f = 1;

		for (int i = m; i < N; ++i) {
			if (a[i] + a[N+m-1-i] < M) {
				f = 0;
			}
		}
		if (f) {
			r = m;
		} else {
			l = m;
		}
	}

	if ((N*2-r) % 2 != 0) {
		++r;
	}

	int u = 0;
	for (int i = 0; i < r; ++i) {
		u = max(u, a[i] + a[r-1-i]);
	}

	for (int i = r; i < N; ++i) {
		u = max(u, (a[i] + a[N+r-1-i]) % M);
	}

	cout << u << endl;

	return 0;
}

Measured memory_bytes: 1024
N, D = map(int,input().split())
import math
X = [input().split() for i in range(N)]



ans = 0
a = 0

for i in range(N):
    for j in range(N):
        if i != j:
            for k in range(D):
                a += (int(X[i][k]) - int(X[j][k])) ** 2
            a = math.sqrt(a)
            if int(a) == a:
                ans += 1            
            a  = 0
print(ans // 2)

Measured memory_bytes: 9164
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
  long num=0;
  long M=0;
  long x=0;
  long a[2];
  long b[2];
  long c[10000];
  long n;
  int i,j;
    for(i=0;i<1;i++){
    scanf("%ld",a+i);
  }
  for(i=0;i<2;i++){
    scanf("%ld",b+i);
  }
  for(i=0;i<a[0];i++){
    scanf("%ld",c+i);
  }
  for(i=0;i<a[0];i++){
    if(fabs(b[1]-(b[0]-c[x]*0.006))>fabs(b[1]-(b[0]-c[i]*0.006))){
      x=i;
    }
  }
  printf("%ld",x+1);
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int T = cin.nextInt();

        int[] A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextInt();
        }

        int[] back_max = new int[N - 1];
        int max = -1;

        for(int i = N-2;i>=0;i--)
        {
            max = Math.Max(max, A[i + 1]);
            back_max[i] = max;
        }

        //profits[i] := 地点iでりんごを買った時の最大利益
        int[] profits = new int[N - 1];
        for(int i = 0;i<N-1;i++)
        {
            profits[i] = back_max[i] - A[i];
        }

        int max_profit = profits.Max();
        int max_cnt = profits.Count(x => x == max_profit);

        Console.WriteLine(max_cnt);
        Console.Read();     
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 21472
H,W = list(map(int, input().split()))
N = int(input())
A = list(map(int, input().split()))

ar = []
i = 0
for a in A:
    i += 1
    for _ in range(a):
        ar.append(i)
#print(ar)

ls =  [[0 for i in range(W)] for j in range(H)]

for h in range(H):
    for w in range(W):
        if h%2==0:
            ls[h][w] = ar.pop()
        else:
            ls[h][W-1-w] = ar.pop()

for h in range(H):
    for w in range(W):
         print('{} '.format(ls[h][w]),end="")
    print()

Measured memory_bytes: 3956
#include <stdio.h>

int* alphaCount(char* str, int start, int end) {
  int* board = new int[300];
  for(int i=0;i<300;i++) {
    board[i] = 0;
  }

  for(int i=start;i<end;i++) {
    board[str[i]]++;
  }

  return board;
}

int alphaUnion(int* board1, int* board2) {
  int res = 0;
  for(int i=0;i<300;i++) {
    if(board1[i] > 0 && board2[i] > 0) {
      res++;
    }
  }

  return res;
}

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

  char* str = new char[N + 1];
  scanf("%s", str);

  int res = 0;
  int tmp;
  int *brd1, *brd2;
  for(int i=0;i<N;i++) {
    brd1 = alphaCount(str, 0, i);
    brd2 = alphaCount(str, i, N);
    tmp = alphaUnion(brd1, brd2);
    if(tmp > res) {
      res = tmp;
    }
    delete[] brd1;
    delete[] brd2;
  }

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

  return 0;
}


Measured memory_bytes: 256
import time
import copy

start_time = time.time()

#input
D = int(input())
c_list = list(map(int, input().split()))

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

def calculate_score(d,t,last):
    score = s_grid[d][t]
    last[t] = -1
    for i in range(26):
        score -= c_list[i]*(last[i]+1)
    return score

t_list = [] #task_list
last_list = [0 for _ in range(26)]

total_score = 0
for k in range(0,D):
    X = -1  # k-日目に変える番号を探す
    p = 0
    last = copy.deepcopy(last_list)
    for i in range(26):  # 26通り試す
        tmp = calculate_score(k,i,last)
        if tmp > p:
            X = i
            p = tmp

    #最大のXを投入
    total_score += p
    t_list.append(X)
    last_list = [i+1 for i in last_list]
    last_list[X] = 0

    #if time.time() - start_time > 1.9:
    #    break

for j in range(len(t_list)):
    print(int(t_list[j]) + 1)

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

int main() {
  long long m = 1000000007;
  
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  
  long long ans = 0;
  long long sum = 0;
  
  for(int i=0; i<n; i++){
    sum += a[i]%m;
    sum %= m;
  }
  
  for(int i=0; i<n-1; i++){
    sum -= a[i]%m;
    if(sum < 0) sum += m;
    
    ans += ((a[i]%m) * sum)%m;
    ans %= m;
  }
  
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4840
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.size = [1 for _ in range(size)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y]+=self.size[x]
        else:
            self.parent[y] = x
            self.size[x]+=self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
      
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]



N = int(input())
U = UnionFind(N)
xyi = []
xy = []
for i in range(N):
    x, y = map(int, input().split())
    xyi.append((x, y, i))
    xy.append((x, y))
xyi.sort()
for j in range(N-1):
    x0, y0, i0 = xyi[j]
    x1, y1, i1 = xyi[j+1]
    if x0 == x1:
        U.unite(i0, i1)
xyi.sort(key = lambda x:x[1])
for j in range(N-1):
    x0, y0, i0 = xyi[j]
    x1, y1, i1 = xyi[j+1]
    if y0 == y1:
        U.unite(i0, i1)
equiv = [[set(), set()] for _ in range(N)]
for i in range(N):
    p = U.find(i)
    equiv[p][0].add(xy[i][0])
    equiv[p][1].add(xy[i][1])
ans = 0
for i in range(N):
    ans+=len(equiv[i][0])*len(equiv[i][1])
ans-=N
print(ans)







Measured memory_bytes: 133424
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
map<string,int> mp;
int n;
string s;
int main()
{
    cin>>n;
    while(n--)
        cin>>s,mp[s]++;
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
typedef long long ll;

ll combination(ll n)
{
    return n * (n - 1) / 2;
}

int main(void)
{
    ll n, a[200000], cnt[200001] = {0}, all;
    scanf("%lld", &n);

    int max = -1;
    rep(i, n)
    {
        scanf("%lld", &a[i]);
        cnt[a[i]]++;
        max = max(max, a[i]);
    }

    rep(i, max + 1)
        if (cnt[i] > 1)
            all += combination(cnt[i]);

    rep(i, n)
    {
        ll sub = 0, add = 0;
        if (cnt[a[i]] > 1)
            sub = combination(cnt[a[i]]);
        if (cnt[a[i]] - 1 > 1)
            add = combination(cnt[a[i]] - 1);
        printf("%lld\n", all - sub + add);
    }
    return 0;
}

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

namespace ABC147
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int[] a = Console.ReadLine().Split(' ').Select( b => int.Parse(b)).ToArray();
            int sum = a[0] + a[1] + a[2];
            if(sum >= 22)
            { Console.WriteLine("bust"); }
            else
            { Console.WriteLine("win"); }
        }
    }
}


Measured memory_bytes: 13268
from collections import deque
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

keys = sorted(list(num_map.keys()), reverse=True)

q = deque()
for i in keys:
    if num_map[i] >= 2:
        q.append([i, num_map[i]])
res = 1
counter = 0
while len(q) != 0:
    key, value = q.popleft()
    res *= key
    if value - 2 >= 2:
        q.appendleft([key, value - 2])
    counter += 1
    if counter == 2:
        print(res)
        break
else:
    print(0)


Measured memory_bytes: 22180
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
vector<int>e[200000];
int dp[200000];
bool b[200000];
int solve(int x) {
	b[x] = 1;
	int sum = 1;
	if (e[x].size() > k) sum = 0;
	int res = k - min(x, 1ll) - 1;
	for (int i = 0; i < e[x].size(); i++) {
		if (!b[e[x][i]]) {
			sum = sum * res % Mod;
			sum = sum * solve(e[x][i]) % Mod;
			res--;
		}
	}
	return sum;
}
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		e[u - 1].push_back(v - 1);
		e[v - 1].push_back(u - 1);
	}
	cout << solve(0) * k % Mod << endl;
}

Measured memory_bytes: 12800
// https://atcoder.jp/contests/abc170/tasks/abc170_f

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 
#define ll long long
#define pld pair<ld, ld>
#define pii pair<int, int>
#define fi first
#define se second

const vector<pii> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
ll H, W, K;
ll up(ll a, ll k = K) {
    if(a % k == 0) return a;
    return a+k - (a%k);
}

struct State {
    ll c;
    int x, y;
    int dir;

    State(ll cc, int xx, int yy, int dirr) {
        c = cc;
        x = xx;
        y = yy;
        dir = dirr;
    }
};

struct Compare {
    bool operator()(State l, State r) {
        return l.c > r.c;
    }
};

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

    cin >> H >> W >> K;

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    char a[H+5][W+5];
    vector<vector<vector<ll> > > cost (4,vector<vector<ll> >(H+3,vector <ll>(W+3,LLONG_MAX-500)));

    for(int i = 0; i < H+3; i++) {
        for(int j = 0; j < W+3; j++) {
            a[i][j] = '@';
        }
    }

    for(int i = 1; i <= H; i++) {
        string s;
        cin >> s;

        for(ll j = 0; j < s.size(); j++) {
            a[i][j+1] = s[j];
        }
    }

    priority_queue<State, vector<State>, Compare> pq;
    for(int d = 0; d < 4; d++) {
        cost[d][x1][y1] = 0;
        pq.push(State(0, x1, y1, d));
    }

    while(!pq.empty()) {
        State S = pq.top();
        pq.pop();

        int x = S.x;
        int y = S.y;
        ll c = S.c;
        int d = S.dir;

        if(c != cost[d][x][y]) continue;
        if((cost[d][x+dirs[d].fi][y+dirs[d].se] > c+1) and (a[x+dirs[d].fi][y+dirs[d].se] != '@')) {
            cost[d][x+dirs[d].fi][y+dirs[d].se] = c+1;
            pq.push(State(c+1, x+dirs[d].fi, y+dirs[d].se, d));
        }

        for(int di = 0; di < 4; di++) {
            ll ne = up(c);
            if(cost[di][x][y] > ne) {
                cost[di][x][y] = ne;
                pq.push(State(ne, x, y, di));
            }
        }
    }

    ll mi = LLONG_MAX-500;
    for(int d = 0; d < 4; d++) {
        mi = min(mi, up(cost[d][x2][y2]));
    }

    if(mi == LLONG_MAX-500) {
        cout << -1 << endl;   
    } else {
        cout << mi/K << endl;
    }
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n;
    MSG(n * (n + 1) / 2)
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i;
    for(i=0;i<s.size();i++){
        if(s[i]=='C'){
            break;
        }
    }
    for(;i<s.size();i++){
        if(s[i]=='F'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];
		//Ae2+Be2=Ce2
		
		int N=sc.nextInt();
		int K=sc.nextInt();
		
		int R=sc.nextInt();
		int S=sc.nextInt();
		int P=sc.nextInt();
		
		String T=sc.next();
		char x[]=T.toCharArray();
		
		//r 114 || //p 112 || //s 115 || 
		int f=N;
		for(int i=N-1;i!=0;i--) {
			if(x[i]==0)continue;
			if(i-K>=0&&x[i]==x[i-K]) {
				x[i-K]=0;
			}
		}
		long ans=0;
		for(int i=0;i<N;i++) {
			if(x[i]==0)continue;
			else if(x[i]==114)ans+=P;
			else if(x[i]==112)ans+=S;
			else if(x[i]==115)ans+=R;
		}
		
		p(ans);
		
		}
		
		
	
	
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 26196
def main():
    import sys
    sys.setrecursionlimit(10**5)
    N = int(input())
    G = [[] for _ in range(N)]
    edge = [-1] * (N-1)
    for i in range(N-1):
        a, b = (int(i)-1 for i in input().split())
        G[a].append((b, i))
        G[b].append((a, i))

    max_deg = max(len(G[i]) for i in range(N))

    def dfs(s, c=-1, p=-1):
        # 行きがけ順処理
        cur_color = 1
        for (v, i) in G[s]:
            if v == p:
                continue
            if c == cur_color:
                cur_color += 1
            edge[i] = cur_color
            dfs(v, edge[i], s)
            cur_color += 1
        # 帰りがけ順処理

    dfs(0)

    print(max_deg)
    for i in range(N-1):
        print(edge[i])


if __name__ == '__main__':
    main()


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

using namespace std;

const int MAXN = 100000 + 10;

int n;
int a[MAXN], b[MAXN];

string solve() {
    cin >> n;
    long long suma = 0;
    long long x = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        suma += a[i];
        x += i;
    }
    if (suma % x != 0) return "NO";
    int k = suma / x;
    for(int i = 1; i <= n; ++i) {
        int j = i + 1;
        if (j > n) j = 1;
        long long v = (a[i] + k - a[j]);
        if (v % n != 0) return "NO";
        if (v < 0) return "NO";
        b[i] = v / n;
    }
    return "YES";
}

int main() {
    int ntests = 1;
    //cin >> ntests;
    for(int tc = 1; tc <= ntests; ++tc) {
        cout << solve() << "\n";
    }
}

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

using namespace std;
typedef long long ll;
char arr[10][10];
int rows[10] , cols[10] ;
int n , m , k ;
int dp[10][10][40];
string s;
vector<string>strs;
int z;
void rec(string s )
{
    if(s.size()==z)
    {
        strs.push_back(s);
        return;
    }
    rec(s+'1');
    rec(s+'0');
}
int main()
{

    cin >> n >> m >> k ;
    z=n+m;
    rec("");
    int cntr=0;
    for(int i = 1 ; i <=n ;i++)
    {
        for(int j = 1 ; j <=m ;j++)
        {
            cin >> arr[i][j];
            if(arr[i][j]=='#')
            {
                rows[i]++;
                cols[j]++;
                cntr++;
            }
        }
    }
    int need =cntr-k;
    int ns=0;
    for(int i = 0 ; i < strs.size() ;i++)
    {
        int f=0;
        for(int j = 1; j<=n;j++)
        {
            for(int k=1; k<=m;k++)
            {
                if(strs[i][j-1]=='0'&&strs[i][n+k-1]=='0')
                {
                    if(arr[j][k]=='#')
                        f++;
                }
            }
        }
        if(f==k)
            ns++;
    }
    cout << ns;
    return 0;
}


Measured memory_bytes: 3712
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

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

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
int a[5];


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

int b[N];

int Asum;


int sum_mask(int mask) {
	int res = 0, last = -1;
	rep(i, 0, 26) {
		if (mask & (1 << i)) res += i - last, last = i;
	}
	return res;
}

int sz;
pair <int, int> bits[30];

int mem[1 << 17];
int good(int mask) {
	if (~mem[mask]) return mem[mask];
	int last = -1, sve = mask;
	vector <int> bts;
	rep(i, 0, 26) {
		if (mask & (1 << i)) {
			bts.pb(i - last);
			last = i;
		}
	}
	int id = 1, sum = 0;
	while (sz(bts)) {
		sum += bts.back();
		bts.pp();
		if (sum > a[id]) return mem[sve] = -1;
		if (sum == a[id]) sum = 0, id++;
	}
	return mem[sve] = id;
}

int mem2[1 << 17];
void fix(int &mask) {
	mask &= (1 << 17) - 1;
	if (~mem2[mask]) {
		mask = mem2[mask];
		return;
	}


	int last = -1, sum = 0, sve = mask;
	sz = 0;
	rep(i, 0, 16) {
		if (mask & (1 << i)) {
			bits[++sz] = {i, i - last};
			sum += i - last;
			last = i;
		}
	}
	//reverse(bits + 1, bits + 1 + sz);
	while (good(mask) == -1 && sz > 0) {
		sum -= bits[sz].s;
		mask ^= (1 << bits[sz].f); 
		--sz;
	}
	mem2[sve] = mask;
	return;
	int now = mask;
	while (sum_mask(mask) > Asum) {
		per(i, 26, 0) {
			if (mask & (1 << i)) {
				mask ^= (1 << i);
				break;
			}
		}
	}
}

int dp[41][1 << 17];
int pw[41];
inline int calc(int v = 1, int mask = 0) {
	fix(mask);
	if (good(mask) == 4) return pw[n - v + 1];
	if (v > n) return 0;
	if (~dp[v][mask]) return dp[v][mask];
	int res = 0;
	rep(i, 1, 10) {
		int nmask = (mask << i) ^ (1 << (i - 1));
		if (i > 7) nmask = 0;
		res += calc(v + 1, nmask);
		if (res >= mod) res -= mod;
	}
	return dp[v][mask] = res;
}
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
		freopen ("E.out", "w", stdout);
	#endif
	Kazakhstan
	cin >> n;
	rep(i, 1, 3) cin >> a[i], Asum += a[i];
	a[4] = a[0] = inf;
	memset(dp, -1, sizeof(dp));
	memset(mem, -1, sizeof(mem));
	memset(mem2, -1, sizeof(mem2));
	pw[0] = 1;
	rep(i, 1, n) {
		pw[i] = pw[i - 1] * 1ll * 10 % mod;
	}
	int ans = calc();
	cout << ans << nl;
	cerr << ans << nl;
	//cout << (calc(1, 0, 0, 0) + calc(1, 1, 10, 0)) % mod;
	ioi
}


Measured memory_bytes: 22784
import java.io.*;
class Main {
  static boolean base_1=false,base_2=false,base_3=false;
  static int outCount=0,scoreCount=0,dataset;
  public static void main(String[] args){
    try{
      String command;
      BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
      dataset=Integer.parseInt(b.readLine());
      for(int i=0;i<dataset;i++){
        while(outCount<3){
          command=b.readLine();
          if(command.equals("HOMERUN")){
            if(base_1){base_1=false;scoreCount++;}
            if(base_2){base_2=false;scoreCount++;}
            if(base_3){base_3=false;scoreCount++;}
            scoreCount++;
          }
          if(command.equals("HIT")){
            if(base_3){scoreCount++;base_3=false;}
            base_3=base_2;
            base_2=base_1;
            base_1=true;
          }
          if(command.equals("OUT")){
            outCount++;
          }
        }
        System.out.println(scoreCount);
        outCount=0;scoreCount=0;base_1=false;base_2=false;base_3=false;
      }
    }catch(IOException e){}
  }
}

Measured memory_bytes: 9372
#include <iostream>
#include <map>
typedef long long ll;
using namespace std;
int mod = 1e9+7;

int main(){
	map<ll, ll> C;
	ll N, M;
	cin >> N >> M;

	C[0] = 1;
	C[1] = 1;
	C[2] = 2;
	for (int i = 3; i <= N; i++) {
		C[i] = (C[i-1] + C[i-2]) % mod;
	}

	ll tmp;
	ll zendan = 0;
	ll ans = 1;
	for (int i = 0; i < M; i++) {
		cin >> tmp;
		if (zendan == tmp) {
			ans = 0;
			break;
		}
		ll sa = tmp - zendan - 1;
		ans = (ans * C[sa]) % mod;
		zendan = tmp + 1;
	}

	ll sa = N - zendan;
	ans = (ans * C[sa]) % mod;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6528
n = gets.to_i
s = gets.chomp
alp = [*'A'..'Z']
ary = []
i = 0
s.length.times do
  if alp.index(s[i]) + n >= 26
    ary << alp[alp.index(s[i]) + n - 26]
  else
  	ary << alp[alp.index(s[i]) + n]
  end
  i += 1
end


ans = ary.inject(:+)
puts ans

Measured memory_bytes: 28284