akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#include <deque>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();)
#define LL long long
#define int LL
#define inf  (int)(1LL << 50)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lowb lower_bound
#define upb upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#define cx() real()
#define cy() imag()
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define pb(a) push_back(a)
template<class T>void scan(vector<T>& a, int n, istream& cin) { T c; REP(i, n) { cin >> c; a.push_back(c); } }
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>; using psi = pair<string, int>; using vvi = vector<vi>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
 
 
 
signed main()
{
	QUICK_CIN;
	//debug_input;
	string a, b, c;
 
	cin >> a >> b >> c;
 
	std::transform(ALL(a), a.begin(), ::toupper);
	std::transform(ALL(b), b.begin(), ::toupper);
	std::transform(ALL(c), c.begin(), ::toupper);
	cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();

		if(X >= 30 && X <= 40)
		System.out.println("Yes");
		if(X >= -40 && X <= 29)
		System.out.println("No");
	}
}

Measured memory_bytes: 35664
import java.util.Scanner;
public class Main{
    static tree[] wd;
	public static void main(String[] args) {
	    int x,i,j,n,root = 0,hz;
	// TODO Auto-generated method stub
     Scanner sca = new Scanner(System.in);
     n=sca.nextInt();
     wd=new tree[n];
     int[]checkmap=new int[n+1];
    for(j=0;j<n;j++){
    	x=sca.nextInt();
	if(j==0)root=x;
	wd[x]=new tree(x);
	for(i=0;i<2;i++){
	    hz=sca.nextInt();
	    if(i==0){
            wd[x].setleft(hz);
	    }else{
	    wd[x].setright(hz);
	    }
	    if(hz==-1)hz=n;
	checkmap[hz]=1;
	}
    }
    for(j=0;j<n;j++){
	if(checkmap[j]!=1)root=j;
    }
    chain(root,-1);
    System.out.println("Preorder");
    preorder(root);
    System.out.println("\nInorder");
    inorder(root);
    System.out.println("\nPostorder");
    postorder(root);
    System.out.println("");
   }
    public static void preorder(int nd){
	System.out.print(" "+wd[nd].getnode());
	if(wd[nd].getleft()!=-1)preorder(wd[nd].getleft());
	if(wd[nd].getright()!=-1)preorder(wd[nd].getright());
    }
    public static void inorder(int nd){
	if(wd[nd].getleft()!=-1)inorder(wd[nd].getleft());
	System.out.print(" "+wd[nd].getnode());
	if(wd[nd].getright()!=-1)inorder(wd[nd].getright());
    }
    public static void postorder(int nd){
	if(wd[nd].getleft()!=-1)postorder(wd[nd].getleft());
	if(wd[nd].getright()!=-1)postorder(wd[nd].getright());
	System.out.print(" "+wd[nd].getnode());
    }
    public static void chain(int chi,int p){
	int i;
	wd[chi].setpar(p);
	if(wd[chi].getdeg()==0)return;
	if(wd[chi].getleft()!=-1) chain(wd[chi].getleft(),chi);
	if(wd[chi].getright()!=-1)chain(wd[chi].getright(),chi);
	}
}
class tree{
    int node,par,n,i,degree=0;
    int left,right;
    tree(int node){
	this.node=node;
    }
    public int getnode(){
	return node;
    }
    public void setleft(int c){
	left=c;
	if(left!=-1) degree++;
    }
    public int getleft(){
	return left;
    }
    public void setright(int c){
	right=c;
	if(right!=-1) degree++;
    }
    public int getright(){
	return right;
    }
    public void setpar(int p){
	par=p;
    }
    public int getpar(){
	return par;
    }
    public int getdeg(){
	return degree;
    }
    
}




Measured memory_bytes: 26308
n, T = map(int, input().split())
c = [0 for _ in range(n)]
t = [0 for _ in range(n)]
for i in range(n):
    c[i], t[i] = map(int, input().split())

ans = 1001

for i in range(n):
    if t[i] <= T:
        ans = min(ans, c[i])
print(ans if ans != 1001 else "TLE")

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
bool D[10],used[10];
int kei[10],m,an;
void dfs(int x,int sum){
  if(x==m){
    if(sum==0)an++;
    return;
  }
  for(int i=0;i<10;i++){
    if((i==0&&D[x])||used[i])continue;
    used[i]=1;
    dfs(x+1,sum+kei[x]*i);
    used[i]=0;
  }
}

int main(){
  int n;
  while(cin>>n&&n){
    m=0,an=0;
    memset(D,0,sizeof(D));
    string s;
    map<char,int> c;
    vector<char> v;
    for(int i=0;i<n;i++){
      cin>>s;
      int l=1;
      if(i==n-1)l=-1;
      for(int j=s.size()-1,k=1;j>=0;j--,k*=10){
	if(j==0&&s.size()!=1)v.push_back(s[j]);
	if(c.find(s[j])==c.end())c[s[j]]=l*k;
	else c[s[j]]+=l*k;
      }
    }
    map<char,int>::iterator it;
    for(it=c.begin();it!=c.end();it++){
      for(int i=0;i<v.size();i++)
	if((*it).first==v[i])D[m]=1;
      kei[m++]=(*it).second;
    }
    dfs(0,0);
    cout<<an<<endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string s;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	cout << ((s <= "2019/04/30") ? "Heisei\n" : "TBD\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		
		long n = stdIn.nextLong();
		long k = stdIn.nextLong();
		
		long min = Math.min(n%k,k-(n%k));
		System.out.println(min);
		
		
		
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
map<string,int>q;
map<string,int>p;
struct stu{
    char s[15];
};
stu str[200005];
int main()
{
    int n,maxx=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s",str[i].s);

        q[str[i].s]++;

        maxx=max(maxx,q[str[i].s]);
        if(p[str[i].s]==1)
            {i--;n--;}
        else
        {
            p[str[i].s]=1;
        }
    }
    map<string,int>::iterator it;
    for(it=q.begin();it!=q.end();it++)
    {
        if(it->second==maxx)
        cout <<it->first<<endl;
    }



}


Measured memory_bytes: 48640
x=int(input())

def is_prime(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=x**0.5:
        if x%i==0:
            return 0
        i+=2
    return 1
for i in range(x,x+10**5):
    if is_prime(i):
        print(i)
        exit()
        


Measured memory_bytes: 38768
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val l = (0 until n).map{
        readLine()!!.toMutableList().map{ it.toInt() - 'a'.toInt()}
    }
    var mf = IntArray(26, {9999} )
    l.forEach{
        var f = IntArray(26)
        it.forEach{ f[it]++ }
        for(i in 0 until 26){
            mf[i] = Math.min(mf[i], f[i])
        }
    }
    for(i in 0..25){
        repeat(mf[i]){
            print((i+'a'.toInt()).toChar())
        }
    }
    println()

}

Measured memory_bytes: 33648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;

int main()
{
	int a,b,c,d,e,n;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(a>0&&c>0)
	{
		a-=d;
		c-=b;
	}
	if(c<=0)printf("Yes\n");
	else printf("No\n");
	
}



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

int main() {
  int N;
  string S;
  string T;
  cin >> N >> S;

  T = S.substr(0,N/2);

  if (T+T == S) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    cin >> s;
    int a, b;
    rep(i, s.size()) {
        if(s[i] =='A') {
            a = i;
            break;
        }
    }
    for(int i = s.size(); i >= 0; i--) {
        if(s[i] == 'Z') {
            b = i + 1;
            break;
        }
    }
    cout << b - a << endl;

    return 0;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int N, K;
  cin >> N >> K;
  cout << N - K + 1 << endl;
  return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename V> typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
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 (a > b) { a = b; return 1; } return 0; }

template<typename T>
struct SegmentTree {
private:
	ll n;
	vector<T> node;
	T ex;
	T(*f)(T,T);

public:
	SegmentTree() {}
	//初期化
	SegmentTree(int size, T(*_f)(T,T), T _ex) {
		n = 1;
		while (n < size)n *= 2;
		f = _f;
		ex = _ex;
		node.resize(2 * n - 1, ex);
		//最下段に順番に値を入れる。
		REP(i, size)node[i + n - 1] = ex;
		//親に伝えていく
		REPR(i, size - 1)node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
	}

	//k番目(0-indexed)をa加算
	void update(ll k, T a) {
		//最下段のインデックスを取得
		k += n - 1;
		//値を代入
		node[k] += a;

		//上りながら更新
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}

	//[a,b)の範囲のcalcの結果を求める
	//kは接点番号、l,rはそれが[l,r)に対応づいていることを表す。
	//外からは(a,b)で呼び出し。
	ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {

		//初回呼び出し時探索範囲を[0,n)に設定。
		if (r < 0)r = n;
		//[a,b)と[l.r)が交差しない。
		if (r <= a || b <= l) {
			return ex;
		}
		//[a,b)が[l,r)を完全に含む。
		if (a <= l && r <= b)return node[k];
		else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Q;
	cin >> N >> Q;
	SegmentTree<ll> st(N, [](auto a, auto b) {return a + b;}, 0);
	REP(i, Q) {
		int c, x, y;
		cin >> c >> x >> y;
		x--;
		if (c == 0) {
			st.update(x, y);
		}
		else {
			y--;
			cout << st.query(x, y+1) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4860
#include <iostream>
using namespace std;
int main(void){
    int x;
    for(int a=1; a<=10000; a++){
        cin>>x;
        if (x !=0){
            cout<<"Case "<< a<<": "<<x<<endl;
        }
        else {
             break;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int a[200005] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;
    for(i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;

    for(i=n ; i>=1 ; i-=2){
        printf("%d",a[i]) ;
        if(n!=1) printf(" ") ;
    }
    if(n%2) i = 2 ;
    else i = 1 ;

    for( ; i<=n ; i+=2)
    {
        printf("%d",a[i]) ;
        if( i+2 <= n ) printf(" ") ;
    }

    printf("\n") ;
    return 0 ;
}


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

int main()
{
  int x, y;
  int N;
  cin >> N;
  
  x = 0;
  y = N;
  while (y != 0)
  {
    x += y % 10;
    y /= 10;
  }
  if (N % x == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import deque

s = input()

s = deque(s)

ans = 0
while len(s) > 0:
    if s[0] == s[-1]:
        if len(s) == 1:
            s.popleft()
        else:
            s.popleft()
            s.pop()

    elif s[0] == "x":
        s.popleft()
        ans += 1
    elif s[-1] == "x":
        s.pop()
        ans += 1
    else:
        print(-1)
        exit(0)

print(ans)


Measured memory_bytes: 46832
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int n=0;bool b=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')b=1;c=getchar();}
	while(c>='0'&&c<='9')n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return b?-n:n;
}

struct edge{int to,nxt;}e[400100];

int n,m,now,fir[100100],flg[100100],ans;

queue<int>q;

void add(int x,int y)
{
	e[++now]={y,fir[x]};
	fir[x]=now;
}

void bfs()
{
	q.push(1);
	while(!q.empty())
	{
		int tt=q.front();q.pop();++ans;
//		cout<<tt<<"    "<<flg[tt]<<endl;
		for(int i=fir[tt];i;i=e[i].nxt)
		{
			int y=e[i].to;
			if(!flg[y])flg[y]=tt,q.push(y);
		}
	}
}

main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int t1=read(),t2=read();
		add(t1,t2);add(t2,t1);
	}
	flg[1]=1;
	bfs();
//	cout<<ans;
	if(ans!=n)
		puts("No");
	else
	{
		puts("Yes");
		for(int i=2;i<=n;++i)printf("%d\n",flg[i]);
	}
	return 0;
}


Measured memory_bytes: 7660
#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(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	int cnt[10][10] {};
	FOR(i, 1, N + 1) {
		string s = to_string(i);
		++cnt[s[0]-'0'][s.back()-'0'];
	}
	
	ll ans = 0;
	FOR(i, 1, 10) FOR(j, 1, 10) ans += (ll)cnt[i][j] * cnt[j][i];
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;


int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    string s;
    unordered_map<string, int> m;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());
        if(m[s]==0)
        {
            m[s] = 1;
        }
        else
        {
            ans += m[s];
            m[s]++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
void output(const vector<vector<bool>>& ans) {
    cout << ans.size() << " " << ans[0].size() << endl;
    each(a, ans) {
        each(f, a) {
            if (f) cout << "#";
            else cout << ".";
        }
        cout << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    const ll w = 100, h = 100;
    ll n, m; cin >> n >> m; --n, --m;
    vector<vector<bool>> ans(h, vector<bool>(w, false));
    rep(y, h/2, h) rep(x, w) {
        ans[y][x] = true;
    }
    rep(y, h/2-1) rep(x, w) {
        if (x % 2 == 0 && y % 2 == 0 && m > 0) {
            ans[y][x] = true;
            --m;
        }
    }
    rep(y, h/2+1, h) rep(x, w) {
        if (x % 2 == 0 && y % 2 == 0 && n > 0) {
            ans[y][x] = false;
            --n;
        }
    }
    output(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
int N,K,j,d[110],A[110][110],p[110],x=0;
cin >> N >> K;
for(int i=0;i<K;i++){
    cin >> d[i];
    for(int k=0;k<d[i];k++){
        cin >> A[i][k];
        for(int j=1;j<=N;j++){
            if(A[i][k]==j){p[j]=j;}
        }
    }
}

for(int j=1;j<=N;j++){
    if(p[j]==j)x++;
    
}

cout << N-x << endl;
return 0;
}


Measured memory_bytes: 3656
# -*- coding:utf-8 -*-
import math
N, D = map(int, input().split())
s = []
for i in range(N):
    s += [list(map(int, input().split()))]
count = 0
for i in range(N):
    for j in range(i + 1, N):
        x = 0.0
        for a in range(D):
            x += abs((s[i][a]- s[j][a])**2)
        b = math.sqrt(x)
        if (b.is_integer()):
            count+=1
print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

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

	// ll t;	cin>>t;
	// while(t--)
	// {
		
	// }
	string s;	cin>>s;
	ll sum = 0;
	for(char a : s)
	{
		sum += (a-'0');
	}
	if(sum%9 == 0)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

Measured memory_bytes: 3768
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        final String[] sl = s.split(" ");
        long N = Long.parseLong(sl[0]);
        long M = Long.parseLong(sl[1]);

        if (N != 1) N -= 2;
        if (M != 1) M -= 2;

        out.println(N * M);

        out.flush();
    }
}


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

vector<int> w; 

//積載量Pだった時にk台以下のトラックならtrue, 不可能ならfalseを返す
bool possi(int P, int k){
    int cnt = 1; //必要なトラックの台数
    int wsum = 0; 
    for(int i = 0; i < w.size(); i++){
        if(w[i] > P) return false; //そもそも積み込めない
        wsum += w[i];
        if(wsum > P){ //w[i]を積んだら容量オーバー
            cnt++;
            wsum = w[i]; //新しいトラックにw[i]を積む
        }
    }
    if(cnt <= k) return true;
    else return false;
}

int main(){
    int n, k; cin >> n >> k;
    w.resize(n);
    int sum = 0; //積むべき荷物の総重量
    for(int i = 0; i < n; i++){
        cin >> w[i];
        sum += w[i];
    }
    int ok = sum, ng = 0;
    //最大積載量の最小値を2分探索して求める
    while(ok - ng > 1){
        int mid = (ok + ng)/2;
        if(possi(mid, k)) ok = mid; //k台以下で積み込めるならそこを上限の最小値と仮定する
        else ng = mid; //k台より多く必要なのでngをここに持ってくる
    }
    cout << ok << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  ll sum=0;
  rep(i,N) sum+=A[i];
  ll M=N*(N+1)/2;
  if(sum%M!=0){
      cout<<"NO"<<endl;
      return 0;
  }

  ll X=sum/M;
  vector<ll> diff(N,0);
  for(int i=0;i<N;i++){
      if(A[i]<X){
          cout<<"NO"<<endl;
          return 0;
      }
      diff[i]=(A[(i+1)%N]-A[i]);
  }
  rep(i,N) diff[i]-=X;

  ll ans=0;
  for(int i=0;i<N;i++){
      if(diff[i]>0||diff[i]%N!=0){
          cout<<"NO"<<endl;
          return 0;
      }
      ans+=abs(diff[i])/N;
  }
  if(ans==X) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


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

int main()
{
    int X,A,B;
    scanf("%d %d %d",&X,&A,&B);
    if(B<=A){
        printf("delicious\n");
    }else if(B<=A+X){
        printf("safe\n");
    }else{
        printf("dangerous\n");
    }
    return 0;
}

Measured memory_bytes: 888
n,k = map(int,input().split())

mx = ((n-1)*(n-2))//2

if k>mx:
    print("-1")
    exit(0)

cnt = mx - k
print(n-1+cnt)
print(1,2)
for i in range(n-2):
    print(2,i+3)
for i in range(3,n+1):
    for j in range(i+1,n+1):
        if cnt>0:
            print(i,j)
            cnt -= 1
for j in range(3,n+1):
    if cnt>0:
        print(1,j)
        cnt -= 1


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

int main(){
  int n;
  int a;
  
  
  cin >> n;
  
  a = n % 1000;
  if(a != 0){
    cout << 1000 - (n % 1000) << endl;
  }else{
    cout << a << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] node = new int[num];
        int[] dp = new int[num];
        for (int i = 0; i < num; i++){
            node[i] = sc.nextInt();
        }
        for (int i = 0; i < num; i++){
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 1; i < num; i++){
            int a = dp[i - 1] + Math.abs(node[i] - node[i - 1]);
            if (dp[i] > a)
                dp[i] = a;
            if (i > 1){
                int b = dp[i - 2] + Math.abs(node[i] - node[i - 2]);
                if (dp[i] > b)
                    dp[i] = b;
            }
        }
        System.out.println(dp[num - 1]);
 
    }
}

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

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

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

int main() {
  int k; cin >> k;
  if (k == 1 || k == 7) {
    cout << 1;
    return 0;
  }
  if (k == 2 || k == 5) {
    cout << -1;
    return 0;
  }
  int l = k % 7 == 0 ? 9 * k / 7 : 9 * k;
  int c = 10 % l;
  for(int i = 2; i <= k; i++) {
    c = (c * 10) % l;
    if (c == 1) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}


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

int main() {
  int N, A;
  cin >> N;
  double ret = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    ret += 1. / A;
  }
  cout << setprecision(10) << 1. / ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
T ModPow(T n, T r, T mod) {
	if( r == 0 ) return 1;
	
	T res = 1;
	while( r ) {
		if( r & 1 ) { 	
			res *= n;
			res %= mod;
		}
		
		n *= n;
		n %= mod;
		r >>= 1;
	}
	
	return res;
}

template<typename T>
T Combination(T n, T r, T mod) {
	if( n < 0 || r < 0 ) return 0;
	if( n < r ) return 0;
	if( n < 2 * r ) r = n - r;
	
	T res = 1;
	for(T i = 1; i <= r; ++i) {
		res *= n - i + 1;
		res %= mod;
		res *= ModPow(i, mod - 2, mod);
		res %= mod;
	}
	
	return res; 
}

int main(void) {
	ll n, k;
	cin >> n >> k;
	
	for(ll i = 1; i <= k; ++i) {
		ll c1 = Combination(n - k + 1, i, MOD_LL);
		ll c2 = Combination(k - 1, i - 1, MOD_LL);
		ll ans = (c1 * c2) % MOD_LL;
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            // スペース、ハート、クラブ、ダイヤの順番で出力する。
            // 絵柄が同じ場合は、ランクが小さい順に出力する。

            var allList = new List<Card>();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 1; j <= 13; j++)
                {
                    allList.Add(new Card((Suit)i, j));
                }
            }

            var list = new List<Card>();
            for (int i = 0; i < n; i++)
            {
                var card = Console.ReadLine().Split(' ').ToList();
                list.Add(new Card(card[0], int.Parse(card[1])));
            }

            list = list.OrderBy(x => x.Suit).ThenBy(y => y.Number).ToList();

            for (int i = allList.Count - 1; i >= 0; i--)
            {
                if (list.Any(x => x.Suit == allList[i].Suit && x.Number == allList[i].Number))
                {
                    allList.RemoveAt(i);
                }
            }

            foreach (var card in allList)
            {
                Console.WriteLine(card);
            }
        }
    }

    class Card
    {
        public Suit Suit { get; set; }

        public int Number { get; set; }

        public Card(string suitStr, int number)
        {
            this.Number = number;

            switch (suitStr)
            {
                case "S":
                    this.Suit = Suit.Spade;
                    break;
                case "H":
                    this.Suit = Suit.Heart;
                    break;
                case "C":
                    this.Suit = Suit.Club;
                    break;
                case "D":
                    this.Suit = Suit.Diamond;
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }

        public Card(Suit suit, int number)
        {
            this.Number = number;
            this.Suit = suit;
        }

        public override string ToString()
        {
            switch (this.Suit)
            {
                case Suit.Spade:
                    return $"S {this.Number}";
                case Suit.Heart:
                    return $"H {this.Number}";
                case Suit.Club:
                    return $"C {this.Number}";
                case Suit.Diamond:
                    return $"D {this.Number}";
                default:
                    throw new InvalidOperationException();
            }
        }
    }

    enum Suit
    {
        Spade,
        Heart,
        Club,
        Diamond,
    }
}



Measured memory_bytes: 18384
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if n == 1:
    print(0)
else:
    ans = 0
    for p, e in factorization(n):
        i = 1
        while e >= i:
            e -= i
            i += 1
            ans += 1

    print(ans)





Measured memory_bytes: 9480
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);
    string ans = "";
    if(S[0]=='A') ans = "T";
    if(S[0]=='T') ans = "A";
    if(S[0]=='G') ans = "C";
    if(S[0]=='C') ans = "G";
    cout << ans << nn;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 200000
#define SE 2000000000
 
int L[MAX/2+2],R[MAX/2+2];
long v1,v2,v3;
 
long merge(int *A,int n,int left,int right,int mid){
  int i,j,k=0;
  long cnt=0;
 
  int n1=mid-left;
  int n2=right-mid;
 
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=R[n2]=SE;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
      cnt+=n1-i;
    }
  }
  return cnt;
}
 
long mergeSort(int *A,int n,int right,int left){
  int mid;
  long v1,v2,v3; 
 
  if(left+1<right){
    mid=(left+right)/2;
    v1=mergeSort(A,n,mid,left);
    v2=mergeSort(A,n,right,mid);
    v3=merge(A,n,left,right,mid);
    return v1+v2+v3;
  }
  else return 0;
}
 
int main(){
  int A[MAX],n,i;
  long ans=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
 
  ans=mergeSort(A,n,n,0);
  printf("%ld\n",ans);
 
  return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> rmq(n,
			   [](int a,int b){return min(a,b);},
			   [](int a,int b){return b;},
			   INT_MAX);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}
/*
  verified on 2017/10/15
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
 */

Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for( int i = 0; i < N; i++ ){
    cin >> H.at(i);
  }
  
  int ans = 0;
  int num = 0;
  for( int i = 0; i < N; i++ ){
    if( num >= H.at(i) ){
      num = H.at(i);
    }else{
      ans = ans + H.at(i) - num;
      num = H.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[] b = new int[a];
		int c = Integer.MAX_VALUE;
		int d = Integer.MIN_VALUE;
		long e = 0;
		for (int i = 0; i < a; i++) {
			int f = scanner.nextInt();
			c = Math.min(c, f);
			d = Math.max(d, f);
			e += f;
		}
		System.out.println(String.format("%d %d %d", c, d, e));

	}
}

Measured memory_bytes: 31792
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector <vector <int>> poslovi(100001);
  for (int i = 0; i < n; i++){
    int tr, cj;
    cin >> tr >> cj;
    poslovi[tr].push_back(cj);
  }
  int zar = 0;
  priority_queue<int> dospos;
  for (int i = 1; i <= m; i++){
    for (int j = 0; j < poslovi[i].size(); j++) dospos.push(poslovi[i][j]);
    if (!dospos.empty()){
      zar += dospos.top();
      dospos.pop();
    }
  }
  cout << zar;
}

Measured memory_bytes: 5632
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K, d, tmp;
    cin >> N >> K;
    vector<bool> have(N, false);
    rep(ti, K)
    {
        cin >> d;
        rep(di, d)
        {
            cin >> tmp;
            have[tmp-1] = true;
        }
    }
    ll cnt = 0;
    rep(i, have.size())
    {
        cnt += !have[i];
    }
    printf("%lld",cnt);
}

Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int[n];
		int i;
		
		for (i = 0; i < n; i++)
			a[i] =stdIn.nextInt();
		
		int count = BubbleSort(a, n);
		
		System.out.print(a[0]);
		for(i = 1; i < n; i++)
			System.out.print(" " + a[i]);
		System.out.println();
		System.out.println(count);
	}
	
	public static int BubbleSort(int[] a, int n) {
		int flag = 1, count = 0, i, t;
		while (flag != 0) {
			flag = 0;
			for (i = n - 1; i > 0; i--) {
				if (a[i] < a[i-1]) {
					t = a[i];
					a[i] = a[i-1];
					a[i-1] = t;
					count++;
					flag = 1;
				}
			}
		}
		return count;
	}
}

Measured memory_bytes: 26368
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	bool prime[10001] = {}; prime[0] = prime[1] = true;
	for(int i=2;i<=10000;i++){
		if(prime[i]) continue;
		for(int j=2;i*j<=10000;j++){
			prime[i*j] = true;
		}
	}
	int N;
	while(cin>>N,N){
		int ans = 0;
		for(int i=2;i<=N;i++){
			if(!prime[i] && !prime[i-2]) ans = max(ans,i);
		}
		printf("%d %d\n",ans-2,ans);
	}
	return 0;
}

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

int main() {
  int N,A,B,C,D;
  cin >>N>>A>>B>>C>>D;
  string S;
  cin>>S;
  bool x=true;
  for (int i = A-1; i <C-1; i++) {
    if(S.at(i)=='#'&&S.at(i+1)=='#'){
      x=false;
      break;
    }
  }
    for (int i = B-1; i <D-1; i++) {
    if(S.at(i)=='#'&&S.at(i+1)=='#'){
      x=false;
      break;
    }
  }
  if(D<C &&x){
    bool y=false;
    for (int i = B-2; i < D-1; i++) {
      if(S.at(i)=='.'&&S.at(i+1)=='.'&&S.at(i+2)=='.'){
        y=true;
        break;
      }
    }
    x=y;
  }
  if(x){
    printf("Yes");
  }else{
    printf("No");
  }
    
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
struct Edge{
 int to,id;
};
vector<vector<Edge>>g;
vector<int>ans;
void dfs(int v, int c=-1,int parent=-1){
	int k=1;
	rep(i,g[v].size()){
		int next=g[v][i].to, identity=g[v][i].id;
		if(next==parent)continue;
		if(k==c)++k;
		ans[identity]=k; k++;
		dfs(next,ans[identity],v);
	}
}
void solve()
{
		
	int n;
	cin>>n;
	g.resize(n);
	ans.resize(n-1);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back((Edge){b,i});
		g[b].push_back((Edge){a,i});
	}
	dfs(0);
	int mx=0;
	rep(i,n)mx=max(mx,(int)g[i].size());
	cout<<mx<<endl;
	rep(i,n-1)cout<<ans[i]<<endl;
	

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] cs = s.toCharArray();

        if (cs[2] == cs[3] && cs[4] == cs[5]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    ll A, B; cin >> A >> B;
    ll ans = 0LL;
    REP(i, ceil(log2(B))+1){
        ll p = 1LL << i;
        ll a_q = A / p;
        ll a_r = A % p;
        ll b_q = B / p;
        ll b_r = B % p;
        
        ll zero_cnt = 0;
        ll one_cnt = 0;

        if (a_r != 0){
            if (a_q % 2 == 0){
                zero_cnt += p - a_r;
            }else{
                one_cnt += p - a_r;
            }
            a_q += 1;
        }
        if (b_r != p - 1){
            if (b_q % 2 == 0){
                zero_cnt += b_r + 1;
            }else{
                one_cnt += b_r + 1;
            }
            b_q -= 1;
        }

        ll even_cnt = floor(b_q / 2.0) - ceil(a_q / 2.0) + 1;
        ll odd_cnt = (b_q - a_q + 1) - even_cnt;
        zero_cnt += p * even_cnt;
        one_cnt += p * odd_cnt;

        if (one_cnt % 2 == 1){
            ans += p;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int h,w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];
    VV x(h,V(w,0)), y(h,V(w,0));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '.'){
                if(j==0) x[i][j] = 1;
                else x[i][j] = x[i][j-1]+1;
            }
            else x[i][j] = 0;
        }
        int tmp = x[i][w-1];
        for(int j=w-1; j>=0; j--){
            if(s[i][j] == '.'){
                if(tmp == 0) tmp = x[i][j];
                x[i][j] = tmp;
            }
            else tmp = 0;
        }
    }
    for(int j=0; j<w; j++){
        for(int i=0; i<h; i++){
            if(s[i][j] == '.'){
                if(i==0) y[i][j] = 1;
                else y[i][j] = y[i-1][j] + 1;
            }
            else y[i][j] = 0;
        }
        int tmp = y[h-1][j];
        for(int i=h-1; i>=0; i--){
            if(s[i][j] == '.'){
                if(tmp == 0) tmp = y[i][j];
                y[i][j] = tmp;
            }
            else tmp = 0;
        }
    }
    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='.')
                ans = max(ans, x[i][j]+y[i][j]-1);
        }
    }
    OUT(ans);
}

Measured memory_bytes: 35712
import java.util.*;

class Main{
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		
		int x=sc.nextInt(),y=sc.nextInt();
		boolean ju=false;

		
		for(int i=0;i<x+1;i++){
			if((i*2)+((x-i)*4)==y){
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 35804
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ll dp[c][d]={};
    dp[a-1][b-1]=1;
    for(int i=a;i<c;++i){
        dp[i][b-1]=(dp[i-1][b-1]*b)%mod;
    }
    for(int j=b;j<d;++j){
        dp[a-1][j]=(dp[a-1][j-1]*a)%mod;
    }
    for(int i=a;i<c;++i){
        for(int j=b;j<d;++j){
            dp[i][j]=(dp[i-1][j]*(j+1)+dp[i][j-1]*(i+1)-dp[i-1][j-1]*i*j)%mod;
        }
    }
    ll ans=(dp[c-1][d-1]+mod)%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 73836
A, B = map(int, input().split())

G = [["."] * 100 for i in range(50)] + [["#"] * 100 for i in range(50)]

A, B = A - 1, B - 1

for h in range(0, 50, 2):
    for w in range(0, 100, 2):
        if B != 0:
            G[h][w] = "#"
            B -= 1

for h in range(51, 100, 2):
    for w in range(0, 100, 2):
        if A != 0:
            G[h][w] = "."
            A -= 1

print(100, 100)
for g in G:
    print("".join(g))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:1
*Problem:Ears
*Date:2019-2-10
*Algorithm:My DP
*Stats:Unknown*/

bool debug=false;

const int NUML=0;
const int NUMJ1=1;
const int NUMO=2;
const int NUMJ2=3;
const int NUMR=4;

int dp[200005][6];

int a[200005];
int n;

inline int getJ(int x){
	if(x%2==1) return 1;
	if(x==0) return 2;
	return 0;
}

inline int getM(int mode,int value){
	if(mode==NUML || mode==NUMR){
		return value;
	}
	if(mode==NUMJ1 || mode==NUMJ2){
		return getJ(value);
	}
	if(mode==NUMO){
		return 1-value%2;
	}
	
	throw 1;
}

int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	memset(dp,0x3f3f3f,sizeof(dp));
	
	for(int i=NUML;i<=NUMR;i++){
		dp[0][i]=getM(i,a[0]);
	}
	
	
	for(int i=1;i<n;i++){
		for(int j=NUML;j<=NUMR;j++){
			for(int k=NUML;k<=j;k++){
				dp[i][j]=min(dp[i][j],dp[i-1][j-k]);	
			}
			dp[i][j]+=getM(j,a[i]);
		}
	}
	
	int mn=1e9+7;
	for(int i=NUML;i<=NUMR;i++){
		mn=min(mn,dp[n-1][i]);
	}
	
	cout<<mn<<endl;
	return 0;
}



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

int main() {

	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	
	int occ[n+1];
	occ[0] = 0;
	occ[1] = 0;
	for (int i=2; i<=n; i++) {
		int i1 = i-2;
		int i2 = i-1;
		if (s[i1] == 'A' && s[i2] == 'C') occ[i] = occ[i-1] + 1;
		else occ[i] = occ[i-1]; 
	}
	
	for (int i=0; i<q; i++) {
		int l, r;
		cin >> l >> r;
		cout << occ[r] - occ[l] << endl;
	}
	
	
	
}


Measured memory_bytes: 1408