akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>


int main(){
	long long a, b;
	int ans = 0;
	scanf("%lld %lld", &a, &b);
	while(a<<ans <= b) ans++;
	printf("%d", ans);
	return 0;
	
}


Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T, class S> inline int Digit_L(T n, S b){
  int res = 0;
  while(n){
    res++;
    n /= b;
  }
  return res;
}
template<class T, class S> inline int Digit_L(T n, S res[]){
  int sz = 0;
  while(n){
    res[sz++] = n % 10;
    n /= 10;
  }
  return sz;
}
int N;
int cnt[10][10];
int s;
int d[10];
int main(){
  int i;
  int res = 0;
  rd(N);
  for(i=(1);i<(N+1);i++){
    s =Digit_L(i,d);
    cnt[d[0]][d[s-1]]++;
  }
  for(i=(0);i<(10);i++){
    int j;
    for(j=(0);j<(10);j++){
      res += cnt[i][j] * cnt[j][i];
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200214-1

// --- original code ---
// int N;
// int cnt[10][10];
// int s, d[10];
// {
//   int res = 0;
//   rd(N);
//   rep(i,1,N+1){
//     s = Digit(i,d);
//     cnt[d[0]][d[s-1]]++;
//   }
//   rep(i,10) rep(j,10) res += cnt[i][j] * cnt[j][i];
//   wt(res);
// }


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

bool comp(pair<int,int> &a, pair<int,int> &b) {
    if ( a.first==b.first ) {
        return a.second < b.second;
    }
    return a.first>b.first;
}

int main() {
    int n, h;
    cin >> n >> h;
    vector<pair<int,int>> v(n);
    for ( int i=0; i<n; i++ ) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end(), comp);
    int ans=0;
    vector<int> w;
    for ( int i=1; i<n; i++ ) {
        if ( v[i].second>=v[0].first ) {
            w.push_back(v[i].second);
        } 
    }
    sort(w.rbegin(), w.rend());
    for ( int i:w ) {
        if ( h>0 ) {
            h-=i;
            ans++;
        }
    }

    if ( h>0 && v[0].second>v[0].first ) {
        h-=v[0].second;
        ans++;
    }
    if ( h>0 ) {
        ans+=(h+v[0].first-1)/v[0].first;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1660
void main() {
	auto ip = readAs!(long[]), N = ip[0], K = ip[1];
	auto m = N - (N / K) * K;
	writeln(min(m, abs(m-K)));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

    struct Pair{
        int a;
        int b;
        Pair(int _a, int _b){
            a = _a;
            b = _b;
        }
    };

    bool cmp(const Pair &A, const Pair &B){
        return (A.a < B.a);
    }

    int main(){
        int N,M,_a,_b;
        cin >> N >> M;
        vector<Pair> arr;
        for(int i=0;i<N;i++){
            cin >> _a >> _b;
            arr.push_back(Pair(_a,_b));
        }
        sort(arr.begin(), arr.end(), cmp);
        int i=0,k=0;
        long long sum=0;
        while(k < M){
            if(k+arr[i].b <= M){
                k += arr[i].b;
                sum += (long long)arr[i].a * arr[i].b;
            }else{
                sum += (long long)(M - k) * arr[i].a;
                k = M;
            }
            i++;
        }
        cout << sum;
    }

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(void){
    string str;
    while(true){
        int sum = 0;
        cin >> str;
        if(str=="0") break;
        for(int i = 0 ; i < str.size() ; i++){
            sum += str[i]-'0';
        }
        cout << sum << endl;
    }
}


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

int main(){
	int n;
	int i = 1;
	int x;
	bool flag1 = false; bool flag2 = false;

	cin >> n;

	for (int i=1; i<=n; i++){
		x = i;
		if(x%3==0){cout << " " << i; continue;}

		do{
			if(x%10 == 3){cout << " " << i; break;}
			x /= 10;
		}while(x);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

// struct Edge{
//   int to,color,id;
//   Edge(int to,int id,int color): to(to),id(id),color(color) {}
// };

int main() {
  int N;cin>>N;
  vector<vector<int>> tree(N,vector<int>());
  int K = 0;
  map<P,int> dic;
  rep(i,N-1) {
    int a,b;cin>>a>>b;
    a--;b--;
    dic[P(a,b)] = i;
    dic[P(b,a)] = i;
    tree[a].push_back(b);
    tree[b].push_back(a);
    K = max(K,(int)tree[a].size());
    K = max(K,(int)tree[b].size());
  }
  vector<int> col(N-1,0);
  queue<int> qu;
  qu.push(0);
  vector<bool> done(N,false);
  done[0] = true;
  vector<int> parent(N,-1);
  while(!qu.empty()) {
    int now = qu.front();
    qu.pop();
    int cnt = 1;
    for(auto nxt : tree[now]) {
      if(!done[nxt]) {
	done[nxt] = true;
	parent[nxt] = now;
	if(cnt == col[dic[P(now,parent[now])]]) {
	  cnt++;
	}
	col[dic[P(now,nxt)]] = cnt;
	cnt++;
	qu.push(nxt);
      }
    }
  }
  cout<<K<<endl;
  rep(i,N-1) cout<<col[i]<<endl;
}


Measured memory_bytes: 22068
def main():

    N = int(input())
    cur = [['a', set(['a'])]]
    for _ in range(N-1):
        temp = []
        for s, u in cur:
            for c in 'abcdefghij':
                 if c not in u:
                     temp.append([s + c, u | {c}])
                     break
                 else:
                    temp.append([s + c, u])
        cur = temp
    for s, _ in cur:
        print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 35916
#include <strings.h>
#include <stdio.h>

int main(void) {
    int i, j, k, h, w;
    int m[500][500];
    int area, hmin;
    char str[501];

    while (scanf("%d %d", &h, &w), h + w) {
	area = 0;
	for (i = 0; i < h; i++) {
	    scanf("%s", str);
	    for (j = 0; j < w; j++) {
		int c;
		if (str[j] == '*') c = 0;
		else {
		    if (i == 0) c = 1;
		    else c = m[i-1][j]+1;
		}
		m[i][j] = c;
	    }
	}
	for (i = 0; i < h; i++) {
	    for (j = 0; j < w; j++) {
		hmin = 501;
		for (k = j; k < w && m[i][k] != 0; k++) {
		    if (m[i][k] < hmin) hmin = m[i][k];
		    if (area < hmin * (k-j+1)) area = hmin * (k-j+1);
		}
	    }
	}
	printf("%d\n", area);
    }
    return 0;
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K=1000000007;
ll gcd(ll a, ll b){
    ll c, d, e;
    while(b>0){
        d=a%b;
        e=a/b;
        c=b;
        b=d;
        a=c;
    }
    return a;
}

int main (){
    ll N;
    cin>>N;
    vector<ll> Vec(N);
    int Mainasu=0;
    ll Saishou=1000000000;
    ll Sum=0;
    for(ll i=0; i<N; i++){
        cin>>Vec.at(i);
        if(Vec.at(i)<0){
            Mainasu ++;
        }
        ll ABS=abs(Vec.at(i));
      	Sum += ABS;
        Saishou=min(Saishou, ABS);
    }
  	//無駄な分岐
    if(Saishou==0){
        cout<<Sum;
    }
    else if(Mainasu%2==0){
        cout<<Sum;
    }
    else{
        cout<<Sum-2*Saishou;
    }
    
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(int ac,char **av){
  int AppleBitNum,i;
  scanf("%d %d",&AppleBitNum,&i);
  AppleBitNum = AppleBitNum*3 + i;
  printf("%d\n",(AppleBitNum - AppleBitNum%2)/2);
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll n,x[300000]={},y[300000]={},sum1[300000]={},sum2[300000]={};

int main(){
  scanf("%d",&n);
  rep(i,n){
    int tx,ty;
    scanf("%d %d",&tx,&ty);
    x[i]=tx;
    y[i]=ty;
    sum1[i]=tx+ty;
    sum2[i]=tx-ty;
  }
  
  sort(sum1,sum1+n);
  sort(sum2,sum2+n);
  cout<<max(abs(sum1[n-1]-sum1[0]),abs(sum2[n-1]-sum2[0]));
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  string color ;
  for ( int i = 0 ; i < N ; i++ ){
    cin  >> color ;
    if ( color == "Y") break;
  }
  if ( color == "Y"){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<map>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<list>
#include<string>
#include<climits>
#define ll long long 
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
	int n,k,s;
	cin>>n>>k>>s;
	int l=k;
	while(l--)
	{
		cout<<s<<' ';
	}
	if(s!=1e9)
	{
		for(int i=0;i<n-k;i++)
		cout<<s+1<<' ';
	}
	else
	{
		for(int i=0;i<n-k;i++)
		cout<<s-1<<' ';
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    vector<vector<int> >a(H,vector<int>(W));
    rep(i,H){
        if(i<B){
            rep(j,W){
                if(j<W-A)a[i][j]=1;
                else a[i][j]=0;
            }
        }else{
            rep(j,W){
                if(j<W-A)a[i][j]=0;
                else a[i][j]=1;
            }
        }
    }
    rep(i,H){
        rep(j,W)cout << a[i][j];
        cout<< endl;
    }
    return 0;
}

Measured memory_bytes: 5120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int Q = in.nextInt();
            List<D.Node> nodes = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                D.Node node = new D.Node();
                nodes.add(node);
            }
            for (int i = 0; i < N - 1; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                nodes.get(a - 1).nodes.add(nodes.get(b - 1));
            }
            for (int i = 0; i < Q; i++) {
                int p = in.nextInt();
                int x = in.nextInt();
                nodes.get(p - 1).point += x;
            }
            nodes.get(0).calc();
            StringBuilder sb = new StringBuilder();
            for (D.Node node : nodes) {
                sb.append(node.point).append(' ');
            }
            out.println(sb.substring(0, sb.length() - 1));
        }

        private static class Node {
            int point;
            List<D.Node> nodes = new ArrayList<>();

            public void calc() {
                for (D.Node node : nodes) {
                    node.calc(point);
                }
            }

            public void calc(int p) {
                point += p;
                for (D.Node node : nodes) {
                    node.calc(point);
                }
            }

        }

    }
}



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

int gcd(int p, int q){
  while(p%q!=0){
    int x = p%q;
    p =  q;
    q = x;
  }

  return q;
}



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

  ll ans =0;
for(int a=1; a<= K;a++){
  for(int b=1; b<= K; b++){
    for(int c=1;c<=K; c++){
      int x = gcd(a,b);
      x = gcd(x,c);
      ans += x;
    }
  }
}

cout<<ans;

}


Measured memory_bytes: 3628
fun gcd(a: Int, b: Int): Int {
    var x = a
    var y = b
    while (true) {
        if (y < x) {
            val z = x
            x = y
            y = z
        }
        if (x == 0) break
        y %= x
    }
    return y
}

fun divisors(n: Int): List<Int> {
    if (n == 0) return emptyList()
    if (n == 1) return listOf(n)
    val div = mutableListOf(1)
    for (i in 2..(n shr 1)) {
        if (n % i == 0) div += i
    }
    div += n
    return div
}

fun main(args: Array<String>) {
    val (a, b, k) = readLine()!!.split(' ').map(String::toInt)
    val gcd = gcd(a, b)
    val d = divisors(gcd)
    println(d[d.size - k])
}


Measured memory_bytes: 38168
package main

import "fmt"

func main() {
  var n int
  _, err := fmt.Scanf("%d", &n)
  if err != nil {
    panic("error")
  }

  s := map[string]int{
    "AC":  0,
    "WA":  0,
    "TLE": 0,
    "RE":  0,
  }

  for i := 0; i < n; i++ {
    var cs string
    _, err := fmt.Scanf("%s", &cs)
    if err != nil {
      panic("error2")
    }
    if cs == "AC" {
      s["AC"] = s["AC"] + 1
    } else if cs == "WA" {
      s["WA"] = s["WA"] + 1
    } else if cs == "TLE" {
      s["TLE"] = s["TLE"] + 1
    } else if cs == "RE" {
      s["RE"] = s["RE"] + 1
    }
  }

  fmt.Printf("AC x %d\n", s["AC"])
  fmt.Printf("WA x %d\n", s["WA"])
  fmt.Printf("TLE x %d\n", s["TLE"])
  fmt.Printf("RE x %d", s["RE"])
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string S,T;
  cin >> S >> T;
  
  if(S.size() + 1 == T.size()){
    bool flag = true;
    for(int i = 0 ; i < S.size() ; i++){
      if(S[i] != T[i]){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> cities(n);
    for (size_t i = 0; i < n; ++i) {
        vector<int> c(n, 0);
        cities[i] = c;
    }
    for(size_t i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        ++cities[a - 1][b - 1];
        ++cities[b - 1][a - 1];
    }
    for (size_t i = 0; i < n; ++i) {
        int u = 0;
        for (size_t j = 0; j < n; ++j) {
            u += cities[i][j];
        }
        cout << u << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
using System;

class B
{
	static long[] Read() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	static void Main()
	{
		var av = Read();
		long a = av[0], v = av[1];
		var bw = Read();
		long b = bw[0], w = bw[1];
		var t = long.Parse(Console.ReadLine());

		Console.WriteLine(Math.Abs(a - b) + w * t <= v * t ? "YES" : "NO");
	}
}


Measured memory_bytes: 27444
def divisors(n):
    divs = []
    i = 1
    while i*i <= n:
        if n % i == 0:
            divs.append((i, n//i))
        i += 1
    return divs

def resolve():
    N = int(input())
    factors = divisors(N)
    ans = float("inf")
    for x, y in factors:
        ans = min(ans, (x-1)+(y-1))
    print(ans)
    

    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 64580
#include <iostream>
#include <math.h>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
	int n, x[1000], y[1000];
	int x_y[1000];
	int p1 = 0;
	double p2 = 0, p3 = 0, pMax = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> y[i];
		x_y[i] = abs(x[i] - y[i]);
		p1 += x_y[i];
		p2 += x_y[i] * x_y[i];
		p3 += x_y[i] * x_y[i] * x_y[i];
		if (i == 0)
			pMax = x_y[i];
		else
			pMax = pMax > x_y[i] ? pMax : x_y[i];
	}
	p2 = sqrt(p2);
	p3 = pow(p3, 1.0 / 3.0);
	cout << fixed << setprecision(6) << p1 << endl << p2 << endl << p3 << endl << pMax << endl;
	return 0;
}


Measured memory_bytes: 3452
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/31 20:16:37
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    ll n; cin >> n;
    int ans = 0;
    for (int i = 2; 1ll * i * i <= n; i++) {
        if (n % i == 0) {
            int cnt = 0;
            int tot = 1;
            while (n % i == 0) {
                n /= i;
                ++cnt;  
                if (cnt == tot) {
                    cnt = 0;
                    ++ans;
                    ++tot;  
                } 
            }
        }   
    }
    if (n > 1) ++ans;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=[]
while len(arr)>0:
    chk=False
    maxtmp=0
    for i,j in enumerate(arr):
        #print(i,j,i+1,arr[i])
        if i+1==j:
            maxtmp=j-1
            chk=True
    p=arr.pop(maxtmp)
    ans.append(p)
    if chk==False:
        print(-1)
        exit()
    #print(ans)

k=reversed(ans)
for i,j in enumerate(k):
    print(j)


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

long long n,m=-1,so=0;
long long a[100005];

int main(){
  long long  i,j=0,k=0,ans=0,now=10000000000;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(m<a[i])m=a[i];
  }
  k=m/2;
  if(m%2==1)j=m/2+1;
  else j = k;
  for(i=0;i<n;i++){
    //  if(a[i]==m)so++;
    //   cout << fabs(a[i]-k) <<fabs(a[i]-j)<< endl;
    if((fabs(a[i]-k)<now||fabs(a[i]-j)<now)&&a[i]!=m){
      ans = a[i];
      now = min(fabs(a[i]-k),fabs(a[i]-j));
    }
    if(now==0) break;
  }
  // if(so==n)ans = m;
  cout << m << ' ' << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
	input!(x: isize);
	input!(n: isize);

	if n == 0 {
		println!("{}", x);
		return;
	}

	input!(p: [isize; n]);
	let mut p = p;
	p.sort(); 

	let r = p.binary_search(&x);
	match r {
		Err(_) => {
//			println!("{:?}", r);
			println!("{}", x);
			return;
		},
		_ => (),
	}

	for i in 1..100 {
		let r = p.binary_search(&(x-i));
		match r {
			Err(_) => {
				println!("{}", x-i);
				return;
			},
			_ => (),
		}
		let r = p.binary_search(&(x+i));
		match r {
			Err(_) => {
				println!("{}", x+i);
				return;
			},
			_ => (),
		}
	}
}



Measured memory_bytes: 2180
import java.util.*;

public class Main {

    private static int A;
    private static int B;
    private static int C;
    private static int D;

    private static Map<Long,Long> memo;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        StringBuilder ans = new StringBuilder();
        int T = sc.nextInt();
        while (T-- > 0) {
            long N = sc.nextLong();
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();
           
            memo = new HashMap<>();
            long min = dfs(N);
            ans.append(min).append('\n');
        }

        System.out.print(ans);
    }


    private static long dfs(long n) {

        Long cached = memo.get(n);
        if (cached != null) {
            return cached;
        }

        if (n == 0) return 0;

        if (n == 1) return D;

        long l2 = n/2*2;
        long r2 = (n+1)/2*2;
        long l3 = n/3*3;
        long r3 = (n+2)/3*3;
        long l5 = n/5*5;
        long r5 = (n+4)/5*5;

        long min = 1_000_000_000_000_000_000L;
        if (n < min/D) min = n*D;
        min = Math.min(min, Math.abs(l2-n)*D+A+dfs(l2/2));
        min = Math.min(min, Math.abs(r2-n)*D+A+dfs(r2/2));
        min = Math.min(min, Math.abs(l3-n)*D+B+dfs(l3/3));
        min = Math.min(min, Math.abs(r3-n)*D+B+dfs(r3/3));
        min = Math.min(min, Math.abs(l5-n)*D+C+dfs(l5/5));
        min = Math.min(min, Math.abs(r5-n)*D+C+dfs(r5/5));

        memo.put(n,min);

        return min;
    }
}


Measured memory_bytes: 55204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX/5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int X;
	cin >> X;
	if (X == 0) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 3608
H,W=map(int,input().split())
Coin=[]
for h in range(H):
    Coin.append(list(map(int,input().split())))
def next(h,w):
    if (-1)**h>0:
        if w+1==W:
            w2=w
            h2=h+1
        else:
            w2=w+1
            h2=h
    else:
        if w==0:
            w2=w
            h2=h+1
        else:
            w2=w-1
            h2=h
    return h2,w2
ans=[]
h=0
w=0
while(1):
    if Coin[h][w]%2==0:
        if next(h,w)[0]==H:
            break
        h,w=next(h,w)
    else:
        if next(h,w)[0]==H:
            break
        ans.append([h,w])
        h,w=next(h,w)
        Coin[h][w]+=1
    #print(h,w,Coin[h][w])
print(len(ans))
#print(ans)
for i in range(len(ans)):
    h,w=ans[i]
    h2,w2=next(h,w)
    print(h+1,w+1,h2+1,w2+1)


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

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int win = 15 - s.size() + count(s.begin(), s.end(), 'o');
	if(win >= 8) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0; 
}

Measured memory_bytes: 256
use superslice::Ext;
fn main() {
    proconio::input! {
        n: usize,
        k: usize,
        mut a: [i64;n],
    }
    a.sort_unstable();
    let mut r=10i64.pow(18)+1;
    let mut l=-r;
    while l+1<r {
        let m=(l+r)/2;
        let mut c=0;
        for (i,&v) in a.iter().enumerate() {
            if v==0 {
                if m>=0 {
                    c+=n-i-1;
                }
            }
            else if v>0 {
                if m>=0 {
                    c+=a[i+1..].upper_bound(&(m/v));
                }
                else {
                    c+=a[i+1..].upper_bound(&((m-v+1)/v));
                }
            }
            else {
                if m>=0 {
                    c+=n-i-1-a[i+1..].lower_bound(&(m/v));
                }
                else {
                    c+=n-i-1-a[i+1..].lower_bound(&((m+v+1)/v));
                }
            }
        }
        if c<k {
            l=m;
        }
        else {
            r=m;
        }
    }
    println!("{}",r);
}


Measured memory_bytes: 5416
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
char s[maxn];
int stk[maxn*10],top,ans;
int main() {
    scanf("%s",s);
    for(int i=0;s[i];i++){
        int k = s[i]-'0';
        if(top && stk[top-1] == k^1)
            --top,ans++;
        else
            stk[top++] = k;
    }
    printf("%d\n",ans*2);
    return 0;
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;



int main() {

    int N, M;
    cin >> N >> M;
    // vector<int> a(N);
    // REP(i, N){
    //     cin >> a[i];
    // }
    int ans = 0;
    

    if(N > 1){
        ans += N * (N - 1) / 2;
    }
    if(M > 1){
        ans += M * (M - 1) / 2;
    }

    cout << ans << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

using namespace std;

#define ll long long
#define ar array



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

	// x2+y2+z2+xy+yz+zx=n

	int n;
	cin >> n;
	ll dp[10005];
	memset(dp,0,sizeof(dp));
	for(int x = 1;x <= 101; x++){
		for(int y = 1;y <= 101; y++){
			for(int z = 1;z <= 101; z++){
				ll var = x*x + y*y + z*z + x*y + y*z + z*x;
				if(var <= 10004)	
					dp[var]++; 
			}
		}
	}
	for(int i = 1;i <= n; i++){
		cout << dp[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3712
n = int(input())
A = list(map(int, input().split()))


su = 0
for i in range(n-1):
  if int(A[i]) > int(A[i+1]):
    su += (int(A[i]) - int(A[i+1]))
    A[i+1] = A[i]
  else:
    continue
    
print(su)

Measured memory_bytes: 32064
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
ll n,k,a,b;
vector<int>q[100005];
ll cou[100005];
void dfs(int son,int father)
{
	ll num=0;
	for(int i=0;i<q[son].size();i++)
	{
		int grandson=q[son][i];
		if(grandson==father)
		continue;
		num++;
		if(son==1)
		cou[grandson]=max(0LL,k-num);
		else
		cou[grandson]=max(0LL,k-num-1);
		dfs(grandson,son);
	}
	return;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		cin>>a>>b;
		q[a].push_back(b);
		q[b].push_back(a);
	}
	dfs(1,0);
	ll ans=k;
	for(int i=2;i<=n;i++)
	ans=ans*(cou[i]%mod)%mod;
	cout<<ans<<endl;
}

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

using namespace std;
using namespace __gnu_pbds; // namespace for pb_ds

/* short forms */
#define Accelerate                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mt make_tuple
#define cld(x, y) (((x) / (y)) + ((x) % (y) != 0)) //integer ceil division
#define tc(tt) \
    int tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++) // testcase
#define all(cont) (cont).begin(), (cont).end()
#define sz(cont) (int)(cont).size()
#define endl '\n'
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl //print with precision
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)

/* constants */
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;

/* typedefs */
typedef pair<int,int> pii;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;
typedef priority_queue<int, vector<int> > max_heap;
typedef tree<int,null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> 
    indexed_set; // integer set with indexing / pb_ds

/* main program */


int main() {
    Accelerate;
    int n;
    cin  >> n;
    map<string,int>m;
    for(int i=0;i<n;i++) {
        string s;
        cin >> s;
        sort(all(s));
        if(m.count(s)>0)m[s]++;
        else m[s]=1;
    }
    ll int ans = 0;
    for(auto it:m) {
        ll int cnt = it.ss;
        ans += (cnt*(cnt-1))/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
using namespace std;
int main(void){
	int N,a,b,c,tmp;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>a>>b>>c;
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		if(b>c){
			tmp=b;
			b=c;
			c=tmp;
		}
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		if(((a*a)+(b*b))==(c*c)){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

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

int main() {
  int n; cin>>n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin>>d[i];
  sort(d.begin(), d.end());

  vector<int> v(25, 0);
  v[0] = 1;
  bool pos = true;
  for (int i = 0; i < n; i++) {
    if (pos) ++v[d[i]];
    else ++v[24-d[i]];
    pos = !pos;
  }
  v[0] += v[24];

  int ans = 12, cnt = 12;
  for (int i = 0; i < 24; i++) {
    if (v[i] >= 2) ans = 0;
    else if (v[i] == 1) {
      ans = min(ans, cnt);
      cnt = 1;
    }
    else ++cnt;
  }
  ans = min(ans, cnt);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Main {
    public static PrintWriter out = new PrintWriter(System.out);
    public static FastScanner enter = new FastScanner(System.in);
    public static void main(String[] args) throws IOException {
        solve();
        out.close();
    }

    static long mod=(long)1e9+7;
    static long arr[] = new long[(int)1e6+2];
    private static void solve() throws IOException{
        int x=enter.nextInt(),y=enter.nextInt();
        if(2*x-y<0 || (2*x-y)%3!=0 ||2*y-x<0 || (2*y-x)%3!=0){
            out.println(0);
            return;
        }
        int a=(2*x-y)/3;
        int n=(y+x)/3;
        long n_fact=1;
        arr[1]=1;
        arr[0]=1;
        for(int i=2;i<arr.length;i++){
            arr[i]=arr[i-1]*i;
            arr[i]%=mod;
        }
        long ans=bin_pow(arr[a],mod-2, mod)*bin_pow(arr[n-a],mod-2, mod);
        ans%=mod;
        ans*=arr[n];
        ans%=mod;
        out.println((ans%mod+mod)%mod);
    }

    public static long bin_pow(long a,long b, long mod){//a^b %mod
        long ans=1;
        while(b!=0){
            if((b&1)==1) ans*=a;
            a*=a;
            ans%=mod;
            a%=mod;
            b>>=1;
        }
        return ans%mod;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer stok;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() throws IOException {
            while (stok == null || !stok.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                stok = new StringTokenizer(s);
            }
            return stok.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        char nextChar() throws IOException {
            return (char) (br.read());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }
    }


}


Measured memory_bytes: 31188
Scanf.scanf "%d" (fun n ->
    let l = Array.init (2 * n) (fun _ -> Scanf.scanf " %d" (fun l -> l)) in
    Array.sort compare l;
    let rec loop i acc =
        if i >= (2 * n) then acc else loop (i + 2) (acc + l.(i))
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 3800
#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define pb push_back

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

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


Measured memory_bytes: 3720
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let s = vecchar();
    let mut c = s.len();
    let mut f = s.len();
    for i in 0..s.len() {
        if c == s.len() && s[i] == 'C' {
            c = i;
        }
        if s[i] == 'F' {
            f = i;
        }
    }

    if c == s.len() || f == s.len() {
        println!("No");
        return;
    }

    println!("{}", if c < f { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using tsii = tuple<string,int,int>;

int main() {
  int n; std::cin >> n;
  std::vector<tsii> v(n);
  for (size_t i = 0; i < n; i++) {
    /* code */
    string s; int p;
    std::cin >> s >> p;
    v[i] = make_tuple(s,-p,i+1);
  }
  sort(v.begin(),v.end());
  for (size_t i = 0; i < n; i++) {
    /* code */
    std::cout << get<2>(v[i]) << '\n';
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define INT_MAX 999999999
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
    int n, m;
    cin>>n>>m;
    char a[n][m];
    for(int i =0; i< n; i++)
    {
        for(int j = 0;  j <m ; j++)
        {
            cin>>a[i][j];
        }
    }
    ll dp[n][m];
    dp[0][0] = 1;
    for(int i = 0 ;i < n; i++)
    {
        for(int j = 0; j< m; j++)
        {
            if(i==0&&j==0)
                continue;
            if(i==0)
            {
                if(a[i][j]=='.')
                {
                    dp[i][j] = dp[i][j-1];
                }
                else
                {
                    dp[i][j] = 0;
                }
            }
            else if(j==0)
            {
                if(a[i][j]=='.')
                {
                    dp[i][j] = dp[i-1][j];
                }
                else
                {
                    dp[i][j] = 0;
                }
            }
            else
            {
                if(a[i][j]=='.')
                {
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
                }
                else
                {
                    dp[i][j] = 0;
                }
            }
        }
    }
    cout<<dp[n-1][m-1]%mod<<endl;

}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)
 
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int N;
vector<pii> edges[MAXN];
int ans[MAXN];
int mx;

void dfs(int u, int p, int c) {
    int k = 1;
    for(auto t: edges[u]) {
        int v = t.fi;
        int i = t.se;
        if(v != p) {
            if(k == c) k++;
            ans[i] = k;
            dfs(v,u,k);
            k++;
        }
    }
}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    fori(i,N-1) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        edges[a].pb({b,i});
        edges[b].pb({a,i});
    }

    fori(i,N) mmax(mx, (int)edges[i].size());
    dfs(0,-1,-1);
    cout << mx << '\n';
    fori(i,N-1) cout << ans[i] << '\n';
    return 0;
}



Measured memory_bytes: 9344
import io
import sys
import math

n=int(input())
ans=0
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(n):
  ans+=B[i]
for j in range(n-1):
  if (A[j]+1)==A[j+1]:
    ans+=C[A[j]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
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;
    for(int i = 0; i < N; i++){
        if(a[i]%2 == 0){
            if(a[i]%3 == 0 || a[i]%5 == 0){
                continue;
            }
            else ans = 1;
        }
    }
    if(ans) cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
S=list(input())
S_odd=S[::2]
S_even=S[1::2]
flag=1
for i in S_odd:
    if i != "R" and i != "U" and i != "D":
        print("No")
        exit(0)
    for j in S_even:
        if j != "L" and j != "U" and j != "D":
            print("No")
            exit(0)
print("Yes")

Measured memory_bytes: 9000
from string import ascii_lowercase
alphabets = ascii_lowercase
s = input()
if len(s) < len(alphabets):
    for c in alphabets:
        if c not in s:
            print(s + c)
            exit()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

# 14253 next 143,  54213 next 5423, 35421 next 4, 43521 next 45
# 右端からみてi-1, iを比較して減少(S[i]>S[i-1])してたらi-1を基準に切り替える
# 切り替えるのは勘だけどi-1より右側でi-1より大きい最小のやつ？
for i in range(len(s) - 1, 0, -1):
    if s[i] > s[i - 1]:
        t = "死"
        for j in range(i, len(s)):
            if s[i - 1] < s[j]:
                t = s[j] if s[j] < t else t
        print(s[:i - 1] + t)
        exit()


Measured memory_bytes: 9908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int nm = 2*1e9 + 10;

int main(){
    ll l, r; cin >> l >> r;
    ll m = nm;
    ll ans = 2019;

    ll modl = l%2019;
    ll modr = r%2019;
    if(r/2019 > l/2019) ans = 0;
    else {
        for(int i=modl; i<modr; i++){
            for(int j=i+1; j<=modr; j++){
                ans = min(ans, i*j%(ll)2019);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
c1,1 c1,2 c1,3
c2,1 c2,2 c2,3
c3,1 c3,2 c3,3
*/
/*

    a1+b1=c11
    a2+b2=c22
    a3+b3=c33
a1+b2=c12
a1+b3=c13
    a2+b1=c21
    a2+b3=c23
a3+b1=c31
a3+b2=c32

*/

int main()
{
            /*  c12 +c21 = c11+c22
                c23+c32 = c22 +c33
                c13 +c31= c11+c33*/
    int c[4][4];
    for(int i=1; i <4 ; ++i)
        for(int j=1 ; j<4 ; ++j){
            cin>>c[i][j];
        }
    puts((c[1][2]+c[2][1]== c[1][1]+c[2][2] &&
       c[2][3] + c[3][2] == c[2][2] + c[3][3] &&
        c[1][3] + c[3][1] == c[1][1] +c[3][3]
       )?"Yes" : "No");

}


Measured memory_bytes: 256