akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
// #define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << "\n"
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << "\n"
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
// MOD = 1000000007;
// MOD = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/***** MAIN *****/
signed main() {
  int n; cin >> n;
  mint ans = mint(10).pow(n);
  ans -= mint(9).pow(n) * 2;
  ans += mint(8).pow(n);
  cout << ans << endl;
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 3512
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  while (cin >> N) {
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> B[i];
    }
    vector<bool> fixA(N, false), fixB(N, false);
    fixA[0] = true;
    for (int i = 1; i < N; i++) {
      if (A[i - 1] < A[i]) {
        fixA[i] = true;
      }
    }
    fixB[N - 1] = true;
    for (int i = N - 2; i >= 0; i--) {
      if (B[i] > B[i + 1]) {
        fixB[i] = true;
      }
    }
    ll res = 1;
    for (int i = 0; i < N; i++) {
      if (fixA[i] && fixB[i]) {
        if (A[i] != B[i]) {
          res = 0;
          break;
        }
      } else if (fixA[i]) {
        if (A[i] > B[i]) {
          res = 0;
          break;
        }
      } else if (fixB[i]) {
        if (B[i] > A[i]) {
          res = 0;
          break;
        }
      } else {
        res = res * min(A[i], B[i]) % MOD;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

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

	vector<int> a(n);

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

	int ans = 0;
	int limit = pow(3, n);
	for (int i = 0; i < limit; i++) {
		int tmp = i;

		for (int j = 0; j < n; j++) {
			int b = tmp % 3 - 1;
			if ((a[j] + b) % 2 == 0) {
				ans++;
				break;
			}
			tmp /= 3;
		}

	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char res[10];
int ac, wa, tle, re;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", res);
		if (res[0] == 'A')
			ac++;
		else if (res[0] == 'W')
			wa++;
		else if (res[0] == 'T')
			tle++;
		else
			re++;
	}
	printf("AC x %d\n", ac );
	printf("WA x %d\n", wa );
	printf("TLE x %d\n", tle );
	printf("RE x %d\n", re );



	return 0;
}

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

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

  int num[n];

  for(int i=0;i < n;i++){
    cin >> num[i];
  }
  sort(num,num+n);

  for(int i=1;i <= num[n-1];i++){
    if(n == 3)
      {
	if(num[0] % i == 0 && num[1] % i == 0 && num[2] % i == 0){
	  cout << i << endl;
	}
      }
    else
      {
	if(num[0] % i == 0 && num[1] % i == 0){
	  cout << i << endl;
	}
      }
  }
  return 0;
}


Measured memory_bytes: 3112
import numpy as np

n=int(input())
xy=[]
for i in range(n):
    xy.append(list(map(int,input().split())))

def naiseki(a,b):
    if (a[0]*b[0]+a[1]*b[1])>0.0:
        return True
    else:
        return False
    
ans=0

for i in range(1001):
    xl=np.cos(np.pi*2.0*i/1000.0)
    yl=np.sin(np.pi*2.0*i/1000.0)
    x=0
    y=0
    for j in range(n):
        if naiseki([xl,yl],xy[j]):
            x+=xy[j][0]
            y+=xy[j][1]
    ans=max(ans,np.sqrt(x**2+y**2))
print(ans)


Measured memory_bytes: 12504
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct range
{
    // 0 represents normal one; 1 represents empty one; 2 represents the universal one
    int tp,begin,end;
    range():tp(2),begin(),end(){}
    range(int _tp,int _begin,int _end):tp(_tp),begin(_begin),end(_end){}
    range& operator&=(const range &rhs)
    {
        if (rhs.tp==1)
            tp=1;
        else if (rhs.tp==0)
        {
            if (tp==2)
                *this=rhs;
            else if (tp==0)
            {
                if ((begin&1)!=(rhs.begin&1)||end<rhs.begin||begin>rhs.end)
                    tp=1;
                else
                {
                    begin=max(begin,rhs.begin);
                    end=min(end,rhs.end);
                }
            }
        }
        return *this;
    }
    bool inrange(int val)
    {
        if (tp==1)
            return false;
        if (tp==2)
            return true;
        return (val&1)==(begin&1)&&val>=begin&&val<=end;
    }
};
range dp[100001];
vector<int> mp[100001];
int val[100001],ans[100001];
bool vst[100001],has[100001];
void dfs(int k)
{
    vst[k]=true;
    for (auto adj:mp[k])
    {
        if (has[adj])
            dp[k]&=range(0,val[adj]-1,val[adj]+1);
        else if (!vst[adj])
        {
            dfs(adj);
            dp[k]&=range(dp[adj].tp,dp[adj].begin-1,dp[adj].end+1);
        }
    }
}
void recover(int k,int p)
{
    if (p==-1)
        val[k]=dp[k].tp==2?0:dp[k].begin;
    else
        val[k]=dp[k].inrange(val[p]-1)?val[p]-1:val[p]+1;
    has[k]=true;
    for (auto adj:mp[k])
    {
        if (!has[adj])
            recover(adj,k);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<n;++i)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    int k;
    scanf("%d",&k);
    while (k--)
    {
        int v,p;
        scanf("%d%d",&v,&p);
        val[v]=p;
        has[v]=true;
    }
    for (int i=1;i<=n;++i)
        if (!has[i]&&!vst[i])
        {
            dfs(i);
            if (dp[i].tp==1)
            {
                printf("No\n");
                return 0;
            }
            recover(i,-1);
        }
    for (int i=1;i<=n;++i)
        for (auto adj:mp[i])
            if (abs(val[i]-val[adj])!=1)
            {
                printf("No\n");
                return 0;
            }
    printf("Yes\n");
    for (int i=1;i<=n;++i)
        printf("%d\n",val[i]);
    return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n, m, q_;
  cin >> n >> m >> q_;
  vector<vector<int> > sum(n+1, vector<int>(n+1, 0));
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    sum[l][r]++;
  }
  rep(i,n) rep(j,n) {
    sum[i+1][j+1] += sum[i][j+1] + sum[i+1][j] - sum[i][j];
  }
  rep(i, q_) {
    int p, q;
    cin >> p >> q;
    int ans = sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1];
    cout << ans << "\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderD
{
    private static int[] answers;
    private static int[] counter;
    private static List<int>[] to;

    static void Main()
    {
        int n;
        int q;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            q = int.Parse(words[1]);
        }

        to = new List<int>[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            to[i] = new List<int>();
        }
        for (int i = 1; i < n; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            int a = int.Parse(words[0]);
            int b = int.Parse(words[1]);
            to[a].Add(b);
            to[b].Add(a);
        }

        counter = new int[n + 1];
        for (int i = 0; i < q; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            int p = int.Parse(words[0]);
            int x = int.Parse(words[1]);
            counter[p] += x;
        }

        answers = new int[n];
        for (int i = 0; i < n; i++)
        {
            answers[i] = -1;
        }

        Progress(1);

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

    private static void Progress(int index)
    {
        if (answers[index - 1] != -1)
        {
            return;
        }
        if (index == 1)
        {
            answers[index - 1] = counter[index];
        }
        else
        {
            foreach (int i in to[index])
            {
                if (answers[i - 1] != -1)
                {
                    answers[index - 1] = counter[index] + answers[i - 1];
                }
            }
        }

        foreach (int i in to[index])
        {
            Progress(i);
        }
    }
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	vector<pair<int, int>> p(n);
	vector<long long> a, b, c;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
		a.push_back(p[i].first + p[i].second);
		b.push_back(p[i].first - p[i].second);
		c.push_back(p[i].second - p[i].first);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	cout << max(a.back() - a[0], b.back() + c.back());
}

Measured memory_bytes: 9732
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n  # 各要素の親要素の番号を格納するリスト

    def find(self, x):  # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):  # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):  # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # グループの数を返す
        return len(self.roots())

    def all_group_members(self):  # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m, k = map(int, input().split())
    fg = [[] for _ in range(n)]
    uf = UnionFind(n)
    bg = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        fg[a].append(b)
        fg[b].append(a)
        uf.union(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        bg[c].append(d)
        bg[d].append(c)
    ans = [0] * n
    for i in range(n):
        ans[i] = uf.size(i)-1
        for f in fg[i]:
            if uf.same(f, i):
                ans[i] -= 1
        for b in bg[i]:
            if uf.same(b, i):
                ans[i] -= 1
    print(*ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 55788
# coding: utf-8
import collections

n=int(input())
S=[]
C=[]
alph=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(n):
    S.append(list(input()))
    C.append(collections.Counter(S[i]))

ans=""
# print(S)
# print(C)

for i in range(len(alph)):
    mozi=alph[i]
    minc=1000
    for j in range(n):
        minc=min(minc,C[j][mozi])
    
    for j in range(minc):
        ans+=mozi

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int maxn=2000005;
const int mod = 998244353;
int n, m;
long long fact[maxn],inv[maxn];
long long r(int x, int p)
{
	long long ret=1,w=x;
	while(p)
	{
		if(p&1) 
		  ret=ret*w%mod;
		w=w*w%mod;
		p>>=1;
	}
	return ret;
}
long long b(int x, int y)
{
	return fact[x]*(inv[y]*inv[x-y]%mod)%mod;
}
int f(int n,int odd,int sum)
{
	long long ret=0;
	for(int i=0;i<=odd&&i<=sum&&i<=n;i++)
	{
		if(sum%2==i%2)
		{
			ret+=b((sum-i)/2+n-1,n-1)*b(n,i)%mod;
		}
	}
	return ret%mod;
}
long long g(int n,int sum)
{
	return b(sum+n-1,n-1);
}
int main()
{
	fact[0]=inv[0]=1;
	for(int i=1;i<maxn;i++)
	{
		fact[i]=fact[i-1]*i%mod;
		inv[i]=r(fact[i],mod-2);
	}
	cin>>n>>m;
	long long ret=f(n,m,3*m);
	for(int i=2*m+1;i<=3*m;i++)
	{
		ret+=mod-n*g(n-1,3*m-i)%mod;
	}
	cout<<ret%mod<<endl;
	return 0;
}

Measured memory_bytes: 31616
#include<stdio.h>
#include<limits.h>

int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
    long long int ans1,ans2,ans3,ans4,ans;
    ans1=(long long)a*c;
    ans2=(long long)a*d;
    ans3=(long long)b*c;
    ans4=(long long)b*d;
    ans=LLONG_MIN;
    if(ans1>ans)ans=ans1;
    if(ans2>ans)ans=ans2;
    if(ans3>ans)ans=ans3;
    if(ans4>ans)ans=ans4;

    printf("%lld",ans);



  return 0;
}

Measured memory_bytes: 2148
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

   private static final String INPUT_FILE_PATH = "";

   static void solve(InputReader in, PrintWriter out) {
      String s = in.nextToken();
      String t = in.nextToken();
      int ans = 0;
      for (int i = 0; i < s.length(); i++) {
         if (s.charAt(i) != t.charAt(i)) ans++;
      }
      out.println(ans);
   }

   private static class InputReader {
      private BufferedReader br;
      private StringTokenizer st;

      public InputReader(InputStream inputStream) {
         this.br = new BufferedReader(new InputStreamReader(inputStream), 32768);
         this.st = null;
      }

      public String nextToken() {
         while (st == null || !st.hasMoreTokens()) {
            try {
               st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
               throw new RuntimeException(e);
            }
         }
         return st.nextToken();
      }

      public int nextInt() {
         return Integer.parseInt(nextToken());
      }

      public long nextLong() {
         return Long.parseLong(nextToken());
      }

      public double nextDouble() {
         return Double.parseDouble(nextToken());
      }
   }

   public static void main(String[] args) throws Exception {
      InputStream inputStream = INPUT_FILE_PATH.isEmpty()
         ? System.in
         : new FileInputStream(new File(INPUT_FILE_PATH));
      OutputStream outputStream = System.out;

      InputReader inputReader = new InputReader(inputStream);
      PrintWriter printWriter = new PrintWriter(outputStream);

      solve(inputReader, printWriter);

      printWriter.close();
   }

}


Measured memory_bytes: 37408
#include<bits/stdc++.h> 
using namespace std;
#define se second
#define fr first
#define int long long int
#define pb push_back
#define inf 1e18
#define all(v) v.begin(),v.end()
#define CHAL_BAAP_KO_MT_SIKHA ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
/*
    Damn Fast:TheFuckinMastermind
    while(How to solve the Question?){
                Read the Question Again!!
           }
        do
            Practise
    #Motivation::::0/0  
*/
const int N=2e5;
vector<pair<int,int> > v[N+1];
stack<int> st;
int vis[N+1];
int dist[N+1];
void dfs(int node){
    vis[node]=1;
    for(auto i:v[node]){
        if(vis[i.fr]==0){
            dfs(i.fr);
        }
    }
    st.push(node);
} 
void solve(){
    while(!st.empty()){
        int node=st.top();
        st.pop();
        for(auto i:v[node]){
            if(dist[i.fr]<dist[node]+i.se){
                dist[i.fr]=dist[node]+i.se;
            }
        }
    }
}
signed main()
{  
    CHAL_BAAP_KO_MT_SIKHA
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb({b,1});
    }
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            dfs(i);
        }
    }
    solve();
    int mx=0;
    for(int i=1;i<=n;i++){
        mx=max(mx,dist[i]);
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

const int N = 1e5;

ll dp[101][N + 10];
int weight[N + 10];
ll value[N + 10];

int main()
{
    turbo

    int n, w; cin >> n >> w;

    for(int i = 1; i <= n; i++)
        cin >> weight[i] >> value[i];

    for(int i = 0; i <= 100; i++)
        for(int j = 1; j <= N; j++)
            dp[i][j] = 1e18;

    

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= N; j++)
            if(value[i] <= j)
                dp[i][j] = min(dp[i - 1][j - value[i]] + weight[i], dp[i - 1][j]);
            else
                dp[i][j] = dp[i - 1][j];

    for(int i = N; i > 0; i--)
        if(dp[n][i] <= w && dp[n][i] > 0)
            return cout << i, 0;
}

Measured memory_bytes: 79232
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(seq[int(input()) - 1])

Measured memory_bytes: 3060
import collections
I = [int(_) for _ in open(0).read().split()]
N = I[0]
A, B = I[1::2], I[2::2]
s = collections.defaultdict(set)
for i, ab in enumerate(zip(A, B)):
    a, b = ab
    s[a].add(i)
    s[b].add(i)
c = collections.Counter(A + B)
d = c.most_common()[::-1]
p, k = d.pop()
ans = [None] * (N - 1)
Q = collections.deque([(p, 0)])
while Q:
    p, fr = Q.popleft()
    color = 1
    for i in s[p]:
        if ans[i] is None:
            if color == fr:
                color += 1
            ans[i] = color
            Q += [(A[i] + B[i] - p, color)]
            color += 1
print(k)
print('\n'.join(map(str, ans)))


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

vector<int> C;
template<typename T>
void query_first_left_element_greater_than_itself(const vector<T>& A, vector<int>& B) {
    int n = A.size();
    B.resize(n);
    C.clear();
    for (int i = 0; i < n; i++) {
        while (!C.empty() && A[C.back()] <= A[i])
            C.pop_back();
        if (C.empty())
            B[i] = -1;
        else
            B[i] = C.back();
       C.push_back(i);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    vector<int> A, B;
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];
    query_first_left_element_greater_than_itself(A, B);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (B[i] == -1) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define mod 1000000007
#define ll long long
using namespace std;
ll d[2001],n;
int main()
{
    scanf("%lld",&n);
    d[0]=1;
    for(ll i=1;i<=n;i++)
        for(ll j=0;j<=i-3;j++)
		{
            d[i]+=d[j];
            d[i]%=mod;
        }
    printf("%d",d[n]);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int x;
    cin>>x;
    if (x==3||x==5||x==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
 int n;
 scanf("%d", &n);
 switch (n % 10) {
 case 2:
 
case 4:
 
case 5:
  case 7:
  case 9:
  
printf("hon");
  break;
  case 0:
  case 1:
  case 6:
  case 8:
  printf ("pon");
  break;
  case 3:
  printf("bon");
 break;
 }

 return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <vector>

static const int INF = 1000000007;
using ll = long long;
using namespace std;


int main() {
    string s, t;
    cin >> s >> t;
    if (s == t){
        cout << "EQUAL" << "\n";
        return 0;
    }
    if(s.length() < t.length()){
        cout << "LESS" << "\n";
        return 0;
    }else if (s.length() > t.length()){
        cout << "GREATER" << "\n";
        return 0;
    }else {
        for (int i = 0; i < s.length(); ++i) {
            if(s[i] > t[i]) {
                cout << "GREATER" << "\n";
                return 0;
            } else if (s[i] < t[i]){
                cout << "LESS" << "\n";
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int ans=0;
  int min=X>Y?Y:X;
  if(A+B>C*2){
    ans += C * min*2;

    if(X>Y){
      if(A>C*2){
        ans += C*(X-Y)*2;
      }else{
        ans += A*(X-Y);
      }
    }else{
      if(B>C*2){
        ans += C*(Y-X)*2;
      }else{
        ans += B*(Y-X);
      }
    }

  }else{
    ans += A*X + B*Y;
  }
  
  cout << ans << endl;
  return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main() {
    int A,B;
    cin>>A>>B;
    cout<<(A-1)*(B-1)<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
const ll mod = 1000000007;
const ll M = 1000000000000000000ll;
#define fi first
#define se second
#define pb push_back
inline ll add(ll a,ll b){return ((a%mod+b%mod)%mod);}
inline ll sub(ll a,ll b){return ((a%mod-b%mod+mod)%mod);}
inline ll mult(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
inline ll power(ll n,ll x){ll p=1;while(x!=0){if(x%2==0){n=mult(n,n);x=x/2;}p=mult(p,n);x--;}return p;}
inline ll recurmult(ll a,ll b){ll r = 0;while (b){if (b & 1)r = add(r, a);a = mult(2,a);b >>= 1;}return r%mod;}

int main()
{
    ios::sync_with_stdio(0);   
    cin.tie(0);   
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif 
    ll x;
    cin>>x;
    for(ll i=-1000;i<=1000;i++)
    {
        for(ll j=-1000;j<=1000;j++)
        {
            if(pow(i,5)-pow(j,5)==x)
            {
                cout<<i<<" "<<j<<"\n";
                return 0;
            }
        }
    } 
//    cout<<fixed;
// cout<<setprecision(0);
//len return unsigned long long be aware 
//in case of runtime err use
//(ll)(s.length())-1
}

Measured memory_bytes: 4052
public class Main {
  private static void solve() {
    int n = ni();
    int m = ni();
    boolean[] ved = new boolean[n + 1];
    int[] cnt = new int[n + 1];
    int pen = 0;
    int ret = 0;
    for (int i = 0; i < m; i++) {
      int p = ni();
      String s = next();
      if (ved[p])
        continue;
      if (s.equals("AC")) {
        ved[p] = true;
        ret++;
        pen += cnt[p];
      } else {
        cnt[p]++;
      }
    }
    System.out.println(ret + " " + pen);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main() {
  
  string N;
  
  cin >> N;
  
  if (N.at(1) == N.at(2)) {
    if (N.at(0) == N.at(1) || N.at(1) == N.at(3))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	string N;
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N.length(); i++) {
		sum += N[i] - '0';
	}
	if (stoi(N) % sum == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	ll x,y;
	cin>>x>>y;
	ll cnt = x;
	while(cnt <= y){
		cnt *=2;
		ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
#include<map>
#include<set>
#include<list>
#define int long long
using namespace std;

int b[100];
signed main() {
	int a; cin >> a;
	for (int c = 0; c < a; c++) {
		cin >> b[c];
	}
	int ans = 0;
	for (int i = 0; i < a; i++) {
		int     minj = i;
		for (int j = i; j < a; j++) {
			if (b[j] < b[minj]) {
				minj = j;
			}
			
				 }
		swap(b[i], b[minj]);
		if (i != minj)ans++;
	}
	for (int i = 0; i < a; i++) {
		if (i)cout << " ";
		cout << b[i];
	}
	cout << endl;
	cout << ans << endl;
}

Measured memory_bytes: 3100
m=[]
for i in range(1,10):
  for j in range(i,10):
    m.append(i*j)
 
a=int(input())
ans=-1
for i in range(len(m)):
    if a == m[i]:
      ans = 1
      
if ans == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;cin>>N;cout<<3*N*N<<endl;
}


Measured memory_bytes: 764
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

A = [chr(65+(ord(S[i])-65 + N)%26) for i in range(len(S))]

print(*A, sep="")


Measured memory_bytes: 22248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;

int s[100003];

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int t;
        cin >> t;
        s[t]++;
        s[t + 1]++;
        s[t + 2]++;
    }
    cout << *max_element(s + 2, s + 100000) << endl;
    return 0;
}

Measured memory_bytes: 3820
a=list(map(int,input().split()))

ans='No'
if a[0]==a[1] and a[0]!=a[2]:
  ans='Yes'
elif a[0]==a[2] and a[0]!=a[1]:
  ans='Yes'
elif a[1]==a[2] and a[0]!=a[1]:
  ans='Yes'
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def inv(x):
    return pow(x, MOD-2, MOD)

N = int(input())
x = list(map(int, input().split()))
ans = 0
MOD = 10**9+7

fact = [1]

for i in range(1, N+1):
    fact.append(fact[-1]*i%MOD)

inv_table = [-1]*(N+1)

for i in range(N+1):
    inv_table[i] = inv(i)

inv_acc = [0]

for inv_i in inv_table:
    inv_acc.append(inv_acc[-1]+inv_i)
    
for i in range(N-1):
    ans += (x[i+1]-x[i])*(inv_acc[i+2]-inv_acc[1])
    ans %= MOD

ans *= fact[N-1]
ans %= MOD

print(ans)

Measured memory_bytes: 62616
n=int(input())
d=list(map(int,input().split()))
a1=0
for i,D in enumerate(d):
    if i%2==0:
        a1+=D
    else:
        a1-=D
ans=[a1]
for i in d[:n-1]:
    ans.append(i*2-ans[-1])
print(" ".join(map(str,ans)))

Measured memory_bytes: 19148
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val SAndP = mutableListOf<Triple<Int, String, Int>>()

    (1..N).forEach {
        val scanned = readLine()!!.split(" ")
        val s = scanned[0]
        val p = scanned[1].toInt()
        SAndP.add(Triple(it , s, p))
    }


    SAndP.sortBy { it.second }
    val grouped = SAndP.groupBy {
       it.second
    }

    grouped.entries.forEach {
        it.value.sortedBy { it.third * -1 }.forEach {
            println(it.first)
        }
    }
}

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

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

    vector<string> a(n);
    vector<string> b(n);

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

    for (int i = 0; i < n - m + 1; i++) {
        for (int j = 0; j < n - m + 1; j++) {
            bool ok = true;
            for (int k = 0; k < m; k++) {
                for (int l = 0; l < m; l++) {
                    if (a[k + i][l + j] != b[k][l]) {
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    break;
                }
            }
            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement
X = int(input())

S = [0, 1, 2, 3, 4, 5]
A = X // 100
B = X - (A * 100)
if A > B:
    print(1)
else:
    A_list = list(combinations_with_replacement(S, A))
    for i in A_list:
        if sum(i) == B:
            print(1)
            exit()
    else:
        print(0)

Measured memory_bytes: 11892
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,Y;
int main(){
    cin >> N >> Y;
    rep(a,2001) rep(b,4001) if(9*a + 4*b == Y/1000 - N && N - a - b >= 0){ cout << a << " " << b << " " << N - a - b << '\n'; return 0;}
    cout << "-1 -1 -1" << '\n';
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int N;
V b;

int main() {
    cin >> N;
    b.resize(N);
    VECCIN(b);
    stack<int> s;
    int num = N;
    while(num) {
        bool update = false;
        REPR(i, num - 1) {
            if(b[i] == i + 1) {
                s.push(i + 1);
                b.erase(b.begin() + i);
                num--;
                update = true;
                break;
            }
        }
        if(!update) break;
    }
    if(num) {
        cout << -1 << "\n";
    } else {
        while(!s.empty()) {
            cout << s.top() << "\n";
            s.pop();
        }
    }
    return 0;
}

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

using namespace std;

int main()
{
	int a[10];
	for(int i=0; i<4; i++){
		cin >> a[i];
	}
	sort(a,a+4);
	if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    
    size_t l=s.length();
    string s01="";
    rep(i,l){
        if(i%2==0) s01=s01+string(1,'1');
        else s01=s01+string(1,'0');
    }
    string s10="";
    rep(i,l){
        if(i%2==0) s10=s10+string(1,'0');
        else s10=s10+string(1,'1');
    }

    int cnt01=0;
    int cnt10=0;
    rep(i,l){
        if(s[i]!=s01[i]) cnt01++;
        if(s[i]!=s10[i]) cnt10++;
    }
    cout<<min(cnt01,cnt10)<<"\n";
    return 0;
}

Measured memory_bytes: 4008
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);

  int d1 = a[2] - a[0];
  int d2 = a[2] - a[1];

  long long int ans = 0;
  if (d1 >= 2) {
    ans += (d1 / 2);
    d1 %= 2;
  }

  if (d2 >= 2) {
    ans += (d2 / 2);
    d2 %= 2;
  }

  if (d1 == 0 && d2 == 0) {
    cout << ans << endl;
  } else if (d1 == d2){
    cout << ans + 1 << endl;
  } else {
    cout << ans + 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 3

void swap(int *p, int *q);

int main (void) {
    int a[N];

    for(int i=0;i<N;i++) {
        scanf("%d", &a[i]);
    }

    for(int i=0;i<N-1;i++) {
        for(int j=N-1;j>i;j--) {
            if(a[j-1]>a[j])swap(&a[j-1], &a[j]);
        }
    }

    for(int i=0;i<N;i++) {
        if(i==N-1){
            printf("%d\n", a[i]);
            break;
        }
        printf("%d ", a[i]);
    }

    return 0;
}

void swap(int *p, int *q) {
    int r;
    r = *p;
    *p = *q;
    *q = r;
    return;
}


Measured memory_bytes: 2040
import itertools
import math

n = int(input())
axis = []
for _ in range(n):
    axis.append(list(map(int,input().split())))

ans = 0
kazu_list = list(itertools.permutations(range(n)))
for nums in kazu_list:
    for i,num in enumerate(nums):
        if i < n-1:
            next_num = nums[i+1]
            ans += math.sqrt(pow((axis[num][0]-axis[next_num][0]),2) + pow((axis[num][1]-axis[next_num][1]),2))
print(ans/len(kazu_list))

Measured memory_bytes: 48748
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main() {
    int m,n;
    cin>>m>>n;
    if(m*500>=n){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

struct edge {
	int to, n;
};
vector<edge> G[100010];
int color[100010];
void dfs(int v, int parent, int c) {
	int cnt = 0;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].to == parent) continue;
		cnt++;
		if (cnt == c) cnt++;
		color[G[v][i].n] = cnt;
		dfs(G[v][i].to, v, cnt);
	}
}
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back({ b,i });
		G[b].push_back({ a,i });
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, (int)G[i].size());
	}
	dfs(0, -1, -1);
	cout << ans << endl;
	for (int i = 0; i < N - 1; i++) {
		cout << color[i]<< endl;
	}
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false; 
 }
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1};
ll dy[4]={1,0};
int main(){
  ll h,w;
  cin>>h>>w;
  vvc s(h,vc(w));
  rep(i,h){
    rep(j,w){
      cin>>s[i][j];
    }
  }
  vvll dp(h,vll(w,INF));
  if(s[0][0]=='#'){
    dp[0][0]=1;
  }
  else{
    dp[0][0]=0;
  }
  rep(i,h){
    rep(j,w){
      rep(u,2){
        ll nx=dx[u]+i;
        ll ny=dy[u]+j;
        if(nx<h&&ny<w){
          if(s[i][j]=='.'&&s[nx][ny]=='#'){
            dp[nx][ny]=min(dp[nx][ny],dp[i][j]+1);
          }
          else{
            dp[nx][ny]=min(dp[nx][ny],dp[i][j]);
          }
        }
      }
    }
  }
  COUT(dp[h-1][w-1]);
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){

  int in, math, eng, jap;

  while(1){

    cin >> in;

    if(in == 0) break;

    for(int i = 0; i < in; i++){
      cin >> math >> eng >> jap;

      if(math == 100 || eng == 100 || jap == 100){
	cout << "A";
      }else if((math + eng) / 2 >= 90){
	cout << "A";
      }else if((math + eng + jap) / 3 >= 80){
	cout << "A";
      }else if((math + eng + jap) / 3 >= 70){
	cout << "B";
      }else if((math + eng + jap) / 3 >= 50 && math >= 80){
	cout << "B";
      }else if((math + eng + jap) / 3 >= 50 && eng >= 80){
	cout << "B";
      }else{
	cout << "C";
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

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

    set<ll> s;
    rep(n) {
        ll temp;
        cin >> temp;
        s.insert(temp);
    }

    if (s.size() == n) {
        print("YES");
    } else {
        print("NO");
    }
    return 0;
}

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

struct Node {
	struct Node * plus;
	struct Node * mul;
	int num;
};
int main() {
	int K;
	cin >> K;
	vector<struct Node> N(K);
	for(int i = 0; i < K; i++) {
		N[i].num = i;
		N[i].plus = &N[(i + 1) % K];
		N[i].mul = &N[(i * 10) % K];
	}

	vector<int> C(K, INT_MAX);
	deque<pair<int , int>> d;
	d.push_back(make_pair(1, 0));
	while(true) {
		auto x = d.front();
		if(x.first == 0) {
			cout << x.second + 1 << endl;
			return 0;
		}
		d.pop_front();
		if(C[x.first] <= x.second) continue;
		C[x.first] = x.second;
		d.push_back(make_pair(N[x.first].plus->num, x.second + 1));
		d.push_front(make_pair(N[x.first].mul->num, x.second));
	}
}


Measured memory_bytes: 3840