akhauriyash/Code-Regression huggingface dataset:
using System;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string[] t = s.Split(' ');
        int A = int.Parse(t[0]);
        int B = int.Parse(t[1]);

        string a = Console.ReadLine();
        int[] P = new int[N];

        for (int i = 0; i < N; i++) {
            P[i] = int.Parse(a.Split(' ')[i]);
        }

        for (int i = 0; i < N; i++) {
            //Console.WriteLine(P[i].ToString());
        }

        //一問目～三問目までの回答の候補となる数
        int candidate_1 = 0;
        int candidate_2 = 0;
        int candidate_3 = 0;

        int ans = N;

        //候補の数を調べる
        for (int i = 0; i < N; i++) {
            if (0 <= P[i] && P[i] <= A) {
                candidate_1++;
                //Console.WriteLine("a");
            } else if (A < P[i] && P[i] <= B) {
                candidate_2++;
                //Console.WriteLine("b");
            } else if (B < P[i] && P[i] <= 20) {
                candidate_3++;
                //Console.WriteLine("c");
            }
        }

        //Console.WriteLine(candidate_1);
        //Console.WriteLine(candidate_2);
        //Console.WriteLine(candidate_3);

        //出力
        ans = Math.Min(candidate_1, candidate_2);
        ans = Math.Min(candidate_3, ans);

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include<iostream>
 
int main() {
  int IN;
  int FIRST, LAST;
  int first_mm = 0, last_mm = 0;

  std::cin >> IN;
  FIRST = IN / 100;
  LAST = IN % 100;

  if(FIRST >= 1 && FIRST <= 12) {
    first_mm = 1;
  }
  if(LAST >= 1 && LAST <= 12) {
    last_mm = 1;
  }

  if(first_mm == 1 && last_mm == 1) {
    std::cout << "AMBIGUOUS";
  }
  else if(first_mm == 0 && last_mm == 0) {
    std::cout << "NA";
  }
  else if(first_mm == 1 && last_mm == 0) {
    std::cout << "MMYY";
  }
  else {
    std::cout << "YYMM";
  }
 
  return 0;
}


Measured memory_bytes: 256
#coding: UTF-8

def Watch(S):
    h = int(S/3600)
    m = int((S%3600)/60)
    s = int((S%3600)%60)
    return h,m,s

if __name__=="__main__":
    S = input()
    h,m,s = Watch(int(S))
    print(str(h)+":"+str(m)+":"+str(s))

Measured memory_bytes: 7700
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int M, D;
  cin >> M >> D;
  int cnt = 0;
  for (int m = 1; m <= M; ++m) {
    for (int d = 1; d <= D; ++d) {
        int d1 = d % 10;
	int d10 = d / 10;
	if (d1 >= 2 and d10 >= 2 and d1 * d10 == m) {
	  ++cnt;
	}
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,d,r;
	double f;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	f=1.0*a/b;
	cout<<d<<" "<<r<<" ";
	printf("%.6lf\n", f);
}



Measured memory_bytes: 3228
#include <stdio.h>

int num[1000000];

int main(void)
{
	int n, i, j;
	int count;
	while (scanf("%d", &n) != EOF){
		for (i = 0; i <= n; i++){
			num[i] = 1;
		}
		
		num[0] = 0;
		num[1] = 0;
		
		for (i = 2; i <= n; i++){
			if (num[i] == 1){
				for (j = i + i; j <= n; j += i){
					num[j] = 0;
				}
			}
		}
		
		count = 0;
		for (i = 0; i <= n; i++){
			if (num[i] == 1){
				count++;
			}
		}
		printf("%d\n", count);
	}
	return (0);
}

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

int N, M;
const int MAX_NM = 1.0e5 + 100;
int a[MAX_NM];
const int MOD = 1.0e9 + 7;

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> a[i];

    int dp[N + 1];
    for (int i = 0; i < N+1; i++) dp[i] = 0;
    
    int j = 0;
    for (int i = 1; i <= N; i++) {
        if (a[j] != i) {
            if (i == 1) {
                dp[1] = 1;
            }
            else if (i == 2) {
                dp[2] = dp[1] + 1;
            }
            else {
                dp[i] = (dp[i-1] + dp[i-2]) % MOD;
            }
        }
        else {
            j++;
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        
        int x = Integer.parseInt(str);
        int h = x / 3600;
        int m = x % 3600 / 60;
        int s = x % 3600 % 60;
        
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24284
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define LL long long
#define int LL
const LL inf=0x3f3f3f3f;
using namespace std;
template<typename tp> inline void read(tp &x)
{
	x=0; char c=getchar(); bool f=0;
	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
	if(f) x=-x;
}
int n,m;
signed main()
{
	read(n),read(m);
	printf("%lld\n",n*m-n-m+1);
	return 0;
}

Measured memory_bytes: 256
//O(n^2)
#include<stdio.h>
#include<math.h>

long long n,rui[10000];

long long max( long long x,long long y ){
	if( x > y )
		return x;
	return y;
}

int main()
{
	long long i,j;
	long long ans;
	while( scanf("%lld",&n) != EOF )
	{
		if( n == 0 )break;
		ans = -10000000000;
		for( i = 0;i < n;i++ ){
			scanf("%lld",rui+i );
			if( i )rui[i] += rui[i-1];
		}
		
		for( i = 0;i < n;i++ ){
			for( j = i;j < n;j++ ){
				if( i )
					ans = max( ans, rui[j]-rui[i-1] );
				else
					ans = max( ans,rui[j] );
			}
		}
		
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1056
#include <vector>
#include <iostream>
using namespace std;
//S
struct SieveEratos{
  vector<bool> t;
  SieveEratos(int n):t(n+1,true){
    t[0] = t[1] = false;
    for(int i = 2; n >= i; i++){
      if(t[i]){
        for(int j = i+i; n >= j; j+=i){
          t[j] = false;
        }
      }
    }
  }
  bool operator[](int x){return t[x];}
};
//E
int main(){
  SieveEratos a(100010);
  vector<int> r;
  r.push_back(0);
  for(int i = 1; 100000 >= i; i++)r.push_back(r[r.size()-1]+(a[i] && a[(i+1)/2]));
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    int y,z;cin>>y>>z;
    cout << r[z]-r[y-1] << endl;
  }

}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<28)

double g[13][13];
double dp[1<<13][13];

int main() {
	string str;
	while (getline(cin, str)) {
		istringstream is(str);
		int n = count(str.c_str(), str.c_str() + str.size(), ' ');
		int w, r[12];
		is >> w;
		REP(i, n) is >> r[i];
		
		REP(i, n) {
			g[0][i + 1] = r[i];
			g[i + 1][0] = r[i];
		}
		REP(i, n) REP(j, n) {
			if (i == j) g[i + 1][j + 1] = 0.0;
			else g[i + 1][j + 1] = sqrt(pow(r[i] + r[j], 2) - pow(r[i] - r[j], 2));
		}
		
		n++;
		fill(dp[0], dp[1<<n], INF);
		dp[1][0] = 0;
		
		REP(i, 1<<n) {
			REP(j, n) {
				if (dp[i][j] == INF) continue;
				
				REP(k, n) {
					if ((i >> k) & 1) continue;
					int next = i | (1 << k);
					
					dp[next][k] = min(dp[next][k], dp[i][j] + g[j][k]);
				}
			}
		}
		
		double ans = INF;
		REP(i, n) if (dp[(1 << n) - 1][i] != INF) ans = min(ans, dp[(1 << n) - 1][i] + g[i][0]);
		
		if ((double)w >= ans) puts("OK");
		else puts("NA");
	}
	
	return 0;
}

Measured memory_bytes: 2040
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n / 100 == 9) n -= 800;
        else n += 800;
        if((n%100) / 10 == 9) n -= 80;
        else n += 80;
        if((n%10) / 1 == 9) n -= 8;
        else n += 8;
        System.out.println(n);
        sc.close();

    }

}


Measured memory_bytes: 23892
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// Scan Standard Input
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

type Dice struct {
	one   string
	two   string
	three string
	four  string
	five  string
	six   string
}

func (d *Dice) opN() *Dice {
	tmp := d.one // copy

	d.one = d.two
	d.two = d.six
	d.six = d.five
	d.five = tmp

	return d
}

func (d *Dice) opE() *Dice {
	tmp := d.one // copy

	d.one = d.four
	d.four = d.six
	d.six = d.three
	d.three = tmp

	return d
}

func (d *Dice) opS() *Dice {
	tmp := d.one // copy

	d.one = d.five
	d.five = d.six
	d.six = d.two
	d.two = tmp
	return d
}

func (d *Dice) opW() *Dice {
	tmp := d.one // copy

	d.one = d.three
	d.three = d.six
	d.six = d.four
	d.four = tmp
	return d
}

func (d *Dice) find(num string) int {
	switch num {
	case d.one:
		return 1
	case d.two:
		return 2
	case d.three:
		return 3
	case d.four:
		return 4
	case d.five:
		return 5
	case d.six:
		return 6
	default:
		return -1
	}
}

func main() {
	// Create Dice Constructor
	dice_s := strings.Split(nextLine(), " ")

	q_num, _ := strconv.Atoi(nextLine())

	for i := 0; i < q_num; i++ {
		dice := &Dice{dice_s[0], dice_s[1], dice_s[2], dice_s[3], dice_s[4], dice_s[5]}
		q_s := strings.Split(nextLine(), " ")

		switch q_s[0] {
		case dice.two:
			dice.opN()
		case dice.three:
			dice.opW()
		case dice.four:
			dice.opE()
		case dice.five:
			dice.opS()
		case dice.six:
			{
				dice.opN()
				dice.opN()
			}
		}

		switch q_s[1] {
		case dice.one:
			dice.opS()
		case dice.three:
			{
				dice.opN()
				dice.opW()
				dice.opS()
			}
		case dice.four:
			{
				dice.opN()
				dice.opE()
				dice.opS()
			}

		case dice.five:
			{
				dice.opS()
				dice.opS()
				dice.opE()
				dice.opE()
			}
		case dice.six:
			dice.opN()
		}

		fmt.Println(dice.three)
	}
}



Measured memory_bytes: 1072
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
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 += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

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 << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll t = n;
    ll m = 0;
    while(t){
        m += t % 10;
        t /= 10;
    }
    YES(n % m == 0);
}

Measured memory_bytes: 256
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long  LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans,tot;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

LL f[11];

int main()
{
	//ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,r,ca=0,u=0,v=0,w;
	repu(i,0,2)cin>>f[i];
	sort(f,f+3);
	cout<<(f[0]+f[1]==f[2]?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D;
  cin >> N;
  A = N%10;
  B = (N/10)%10;
  C = (N/100)%10;
  D = (N/1000)%10;
  if((A==B&&B==C) || (B==C&&C==D))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    int a[105];
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    if(sum%10!=0)
    {
        cout<<sum;
        return 0;
    }
    sort(a,a+n);
    int ans;
    for(int i=0;i<n;i++)
    {
        ans=sum-a[i];
        if(ans%10!=0)
            {
                cout<<ans;
                break;
            }
        if(i==n-1)
            cout<<0;
    }
    return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
x, y, h = [], [], []
for _ in range(n):
    xi, yi, hi = map(int, input().split())
    if hi != 0:
        x.append(xi)
        y.append(yi)
        h.append(hi)
candidate_cx = list(range(min(x), max(x) + 1))
candidate_cy = list(range(min(y), max(y) + 1))

for cx, cy in list(itertools.product(candidate_cx, candidate_cy)):
    adapted = True
    ch = h[0] + abs(x[0] - cx) + abs(y[0] - cy)
    for xi, yi, hi in zip(x, y, h):
        if hi != ch - abs(xi - cx) - abs(yi - cy):
            adapted = False
            break
    if adapted == False:
        continue
    print(cx, cy, ch, sep = ' ')
    exit(0)

Measured memory_bytes: 3700
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

const int ComputePrev(const int N, const vector<LLONG> &As, vector<LLONG> &Bs,
    multimap<LLONG, int> &value2IndexMap, LLONG &subtractNum)
{
    auto itr = --value2IndexMap.end();
    const int index = itr->second;
    const int prev = index - 1 < 0 ? N - 1 : index - 1;
    const int next = index + 1 >= N ? 0 : index + 1;
    const LLONG subtract = Bs[prev] + Bs[next];
    subtractNum = max(1LL, (Bs[index] - As[index]) / subtract);
    Bs[index] -= subtract * subtractNum;
    value2IndexMap.erase(itr);
    return index;
}

void Check(const int changedIndex,
    const vector<LLONG> &As, const vector<LLONG> &Bs,
    multimap<LLONG, int> &value2IndexMap, int &flag)
{
    const LLONG goal = As[changedIndex], current = Bs[changedIndex];
    // 目標値の方が下ならば続行
    if (goal < current)
    {
        value2IndexMap.insert({ current, changedIndex });
        flag = 1;
    }
    // 目標値に一致したならばフラグ＝０
    else if (goal == current)
    {
        flag = 0;
    }
    // 目標値を下回ってしまった場合は失敗
    else
    {
        flag = -1;
    }
}

int main()
{
    int N;
    cin >> N;
    vector<LLONG> As(N), Bs(N);
    for (int i = 0; i < N; ++i) cin >> As[i];
    for (int i = 0; i < N; ++i) cin >> Bs[i];

    multimap<LLONG, int> value2IndexMap;
    for (int i = 0; i < N; ++i)
    {
        const LLONG Ai = As[i], Bi = Bs[i];
        if (Ai < Bi)
        {
            value2IndexMap.insert({ Bs[i], i });
        }
        else if (Ai > Bi)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    int flag;
    int remained = static_cast<int>(value2IndexMap.size());
    LLONG count = 0;
    for (;;)
    {
        if (remained == 0)
        {
            cout << count << endl;
            break;
        }
        
        LLONG subtractNum;
        const int changedIndex = ComputePrev(N, As, Bs, value2IndexMap, subtractNum);
        count += subtractNum;
        Check(changedIndex, As, Bs, value2IndexMap, flag);
        if (flag == 0)
        {
            --remained;
        }
        else if (flag < 0)
        {
            cout << -1 << endl;
            break;
        }
    }
}


Measured memory_bytes: 15872
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

class Tree {
    private:
    typedef struct Node {
        int parent;
        int left;
        int right;
        Node() : parent(-1), left(-1), right(-1) {}
    } Node;
    int m_root;
    vector<Node> m_node;
    vector<int> m_depth;
    vector<int> m_height;

    public:
    Tree(int n) : m_root(-1), m_node(n), m_depth(n, 0), m_height(n, 0) {}
    ~Tree(){}

    void SetParent(int node, int parent) {
        m_node[node].parent = parent;
    }

    void SetLeftRight(int node, int left, int right) {
        m_node[node].left = left;
        m_node[node].right = right;
    }

    void SetRoot() {
        for (int i = 0; i < m_node.size(); i++) {
            if (m_node[i].parent == -1) {
                m_root = i;
                return;
            }
        }
    }

    void PreOrder() {
        PreOrderNode(m_root);
    }
    void PreOrderNode(int node) {
        if (node == -1) {
            return;
        }
        printf(" %d", node);
        PreOrderNode(m_node[node].left);
        PreOrderNode(m_node[node].right);
    }

    void InOrder() {
        InOrderNode(m_root);
    }
    void InOrderNode(int node) {
        if (node == -1) {
            return;
        }
        InOrderNode(m_node[node].left);
        printf(" %d", node);
        InOrderNode(m_node[node].right);
    }

    void PostOrder() {
        PostOrderNode(m_root);
    }
    void PostOrderNode(int node) {
        if (node == -1) {
            return;
        }
        PostOrderNode(m_node[node].left);
        PostOrderNode(m_node[node].right);
        printf(" %d", node);
    }

};

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

    Tree tree(n);

    for (int i = 0; i < n; i++) {
        int id, left, right;
        cin >> id >> left >> right;
        tree.SetLeftRight(id, left, right);
        tree.SetParent(left, id);
        tree.SetParent(right, id);
    }

    tree.SetRoot();

    printf("Preorder\n");
    tree.PreOrder();
    printf("\n");

    printf("Inorder\n");
    tree.InOrder();
    printf("\n");

    printf("Postorder\n");
    tree.PostOrder();
    printf("\n");

    return 0;
}



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

typedef pair<int, int> pp;

vector<int> ans;
vector<vector<pp> > adjList;

void dfs(int node, int prev, int flag){
    ans[node] = flag;

    for (auto cur : adjList[node]){
        if (cur.first != prev){
            if (cur.second == 0) dfs(cur.first, node, flag);
            else dfs(cur.first, node, !flag);
        }
    }
    return;
}

int main(){
    //freopen("in.txt", "r", stdin);
    int n, u, v, w;
    cin>>n;

    adjList.resize(n+1);
    ans.resize(n+1);

    while (cin>>u>>v>>w){
        adjList[u].push_back(make_pair(v, w%2));
        adjList[v].push_back(make_pair(u, w%2));
    }

    dfs(1, -1, 1);
    for (int i=1;i<=n;++i) cout<<ans[i]<<endl;

    return 0;
}

Measured memory_bytes: 8192
require "prime"

Q = gets.to_i
primes = Array.new(10 ** 5 + 1, 0)

3.upto(10 ** 5) do |x|
  case x % 2
  when 0
    primes[x] = primes[x-1]
  when 1
    primes[x] = primes[x-2]
    primes[x] += 1 if Prime.prime?(x) && Prime.prime?((x+1)/2)
  end
end

Q.times do
  l, r = gets.split.map(&:to_i)
  puts(primes[r] - primes[l-1])
end


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

#define ll long long
#define all(x) (x).begin(),(x).end()
#define SZ(x) (x).size()
#define fir first
#define sec second

void scan() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], pre[maxn];

int main() {
    //scan();

    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    int ret = 0;
    for (int i = 1; i <= n; i++) cin >> a[i], ret += a[i];
    vector<int> vec;
    for (int i = 1; i * i <= ret; i++) {
        if (ret % i == 0) {
            if (i * i != ret) vec.push_back(ret / i);
            vec.push_back(i);
        }
    }
    sort(all(vec), greater<int>());
    
    for (int x:vec) {

        vector<int> b;
        for (int i = 1; i <= n; i++) b.push_back(a[i] % x);
        sort(all(b));

        pre[0] = 0;
        for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + b[i - 1];


        for (int i = 1; i <= n; i++) {
            if (pre[i] == (n - i) * x - (pre[n] - pre[i])) {
                if (k >= pre[i]) {
                    return cout << x << endl, 0;
                }
            }
        }
    }

    return 0;
}




















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

if min(a) == 0:
  print(0)
else:
  ans = 1
  for _a in a:
    ans *= _a
    if ans > 10 ** 18:
      break
  print(ans if ans <= 10 ** 18 else -1)

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v.at(i);
  sort(v.begin(),v.end());
  double ans=v.at(0);
  for(int i = 1; i < n; i++){
    ans = (ans+v.at(i))/2.0;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >>N;
  vector<int> d(N);
  rep(i,N)cin>>d[i];
  set<int> values;
  rep(i,N){
    values.insert(d[i]);
  }
  cout<<values.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,d,r;
  double f;

  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/b;
  printf("%d %d %.5f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    l = [0] * (N + 1)
    for n in range(N):
        p = int(input())
        l[p] = l[p-1] + 1
    print(N - max(l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 16536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ods;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

void solve(ll t)
{
    // cout<<"Case #"<<t<<":\n";
    ld r;
    cin>>r;
    ld PI=3.14159;
    ld ans=2*PI*r;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    ll tt=1;
    while(t--)
    {
        solve(tt);
        tt++;
    }
}     


Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
template<class Type> class UnionFind
{
    private:
        vector<Type> data;
        int groups;
    public:
        UnionFind(int sz)
        {
            data.assign(sz, -1);
            this->groups = sz;
        }
        bool unite(Type x, Type y)
        {
            x = find(x), y = find(y);
            if (x == y) return (false);
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            groups--;
            return (true);
        }
        Type find(Type k) {
            if (data[k] < 0) return (k);
            return (data[k] = find(data[k]));
        }
        Type size(Type k) { return (-data[find(k)]); }
        int getGroups() { return this->groups; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    UnionFind<int> uf(n);
    for(int i = 0; i < m; i++)
    {
        int x, y, z; cin >> x >> y >> z;
        x--, y--;
        uf.unite(x, y);
    }
    cout << uf.getGroups() << endl;
    return 0;
}



Measured memory_bytes: 640
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for ope_count in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            break
        else:
            dists = templi

    print(*list(dists)[:-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 179680
n,q = gets.chomp.split.map(&:to_i)
s = gets.chomp
t = [0]
n.times do |num|
	if s[num..(num + 1)] == "AC"
		t << t[num] + 1
	else
		t << t[num]
	end
end

q.times do
	str_s,str_e = gets.chomp.split.map{|i| i.to_i - 1}
	puts t[str_e] - t[str_s]

end

Measured memory_bytes: 3452
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

int n,k;
int arr[100001];
int dp[100001][2];
bool v[100001][2];

int s1(int r, bool turn)
{
    if(arr[0]>r)
        return 0;
    if(v[r][turn])
        return dp[r][turn];
    v[r][turn] = 1;
    bool xx = 1;
    rep(i,0,n-1)
    {
        if(arr[i]>r)
            break;
        xx &= s1(r-arr[i],(!turn));
    }
    dp[r][turn] = (!xx);
    return dp[r][turn];
}

void solve()
{
    cin >> n >> k;
    inp(arr,n);
    sort(arr,arr+n);
    if(s1(k,0))
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}

 
int32_t main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 6656
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

map<string, int>mp;
string mol;
int a;

long long int getnum() {
	int num = 0;
	while (isdigit(mol[a])) {
		num = num * 10 + mol[a] - '0';
		a++;
	}
	return num;
}

long long int getatom() {
	string nst;
	if('A'<=mol[a]&&mol[a]<='Z'){
		nst.push_back(mol[a]);
		a++;
	}
	else {
		throw(false);
	}
	
	if (a!=mol.size()&&'a' <= mol[a] && mol[a] <= 'z') {
		nst.push_back(mol[a]);
		a++;
	}
	if (mp.find(nst) == mp.end()) {
		throw(false);
	}
	long long int anum = 1;
	if (a != mol.size() && isdigit(mol[a])) {
		anum = getnum();
	}
	return mp[nst]*anum;
}

long long int getmol() {
	long long int ans = 0;
	while (a!=mol.size()&&mol[a]!=')') {
		long long int anum;
		if (mol[a] == '(') {
			a++;
			long long int num = getmol();
			a++;
			long long int rd = 1;
			if (isdigit(mol[a])) {

				 rd= getnum();
			}
			ans+=num*rd;
		}
		else {

			anum = getatom();

			ans += anum;
		}

	}
	return ans;
	
	
}

long long int solve(const string st) {
	a = 0;
	mol = st;
	return getmol();
}
int main() {
	while (1) {
		string st; cin >> st;
		if (st.size() >= 3)break;
		int n; cin >> n;
		mp[st] = n;
	}
	while (1) {
		string st; cin >> st;
		if (st == "0")break;
		else {
			try {
				long long int ans = solve(st);
				cout << ans << endl;
			}
			catch (...) {
				cout << "UNKNOWN" << endl;
			}
		}
	}
	return 0;
}

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

int main(){
    int n,x,t;
    cin >> n >> x >> t;
     cout << (n + x - 1) / x * t;
    
}

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

using namespace std;
int main(){
    char a = 'H'||'D',b ='H'||'D';  
    cin >> a >> b;
    if(a==b){
        cout << 'H' << endl;
    }
    else{
        cout << 'D' << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>

using namespace std;

int main(){
	int com;
	stack<int> train;
	
	while(cin >> com){
		if(com != 0) train.push(com);
		else{
			cout << train.top() << endl;
			train.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split())
S = input()

S += '2'
l = []
cnt = 1
for i in range(N):
  if S[i] == S[i+1]:
  	cnt += 1
  else:
    l.append(cnt)
    cnt = 1

if S[0] == '0':
  cur = sum(l[:2*K])
  ans = cur
  for j in range(1, len(l), 2):
    cur += -sum(l[max(0, j-2): j]) + sum(l[j+2*K-1:j+2*K+1])
    ans = max(ans, cur)
else:
  cur = sum(l[:2*K+1])
  ans = cur
  for j in range(2, len(l), 2):
    cur += -sum(l[max(0, j-2): j]) + sum(l[j+2*K-1:j+2*K+1])
    ans = max(ans, cur)
print(ans)

Measured memory_bytes: 4596
#include<stdio.h>                                                         
                                                                          
int main(void){                                                           
                                                                          
  int a,b,c,i;                                                            
                                                                          
  scanf("%d %d %d",&a,&b,&c);                                             
                                                                          
  if(b < a) {                                                             
    i = a;                                                                
    a = b;                                                                
    b = i;                                                                
  }                                                                       
                                                                          
  if (c < b) {                                                            
    i = b;                                                                
    b = c;                                                                
    c = i;                                                                
  }                                                                       
                                                                          
  if (b < a) {                                                            
    i = a;                                                                
    a = b;                                                                
    b = i;                                                                
  }                                                                       
                                                                          
  printf("%d %d %d\n",a,b,c);                                               
                                                                          
  return 0;                                                               
                                                                          
}

Measured memory_bytes: 2712
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int H, W;
	cin >> H >> W;

	FOR(i, 0, W+2)
		cout << "#";
	cout << endl;

	FOR(i, 0, H) {
		string s;
		cin >> s;
		cout << "#" << s << "#" << endl;
	}

	FOR(i, 0, W+2)
		cout << "#";
	cout << endl;

	return 0;
}

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

bool T[256];
int P[256];

vector<string> compute(string text, string key){

    vector<string> ans;
    int k = key.size();
    rep(i, 256) P[i] = -1;
    int l = text.size();
    int r = -1;

    rep(i, 256) T[i] = false;
    rep(i, k) T[key[i]] = true;

    rep(i, k){
	rep(j, text.size()){
	    if ( key[i] == text[j] ) { 
		P[key[i]] = j; 
		l = min(l, j);
		r = max(r, j);
		break; 
	    }
	}
    }
    rep(i, k) if ( P[key[i]] == -1 ) return ans;
    for ( int i = l; i <= r; i++ ){
	if ( T[text[i]] ){
	    if ( P[text[i]] < i ) P[text[i]] = i;
	}
    }

    ans.push_back(text.substr(l, r-l+1));

    for ( int i = r+1; i < text.size(); i++ ){
	char ch = text[i];
	if ( T[ch] ){
	    r = i;
	    P[ch] = i;
	    l = r;
	    rep(t, k){
		if ( T[key[t]] ){
		    l = min(l, P[key[t]]);
		}
	    }
	    string c = text.substr(l, r-l+1);
	    if ( ans[0].size() == c.size() ) ans.push_back(c);
	    else if ( ans[0].size() > c.size() ){
		ans.clear();
		ans.push_back(c);
	    }
	}
    }

    return ans;
}

void output(string line){
    rep(i, line.size()){
	if ( i % 72 == 0 && i != 0 ) cout << endl;
	cout << line[i];
    }
    cout << endl;

}

main(){
    string text, line, key;
    while(1){
	text = "";
	while(1){
	    getline(cin, line);
	    if ( line.size() == 0 ) break;
	    text += line;
	}
	if ( text == "" ) break;
	getline(cin, key);
	getline(cin, line);
	vector<string> ans = compute(text, key);
	cout << ans.size() << endl;
	if ( ans.size() > 0 ){
	    cout << endl;
	    output(ans[0]);
	}
	cout << endl;
    }
}

Measured memory_bytes: 1964
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int[] a = new int[100010];
		a[0] = 1;
		for (int i=0; i<n; i++) {
			int s = in.nextInt();
			int t = in.nextInt();
			a[s] += 1;
			a[t+1] -= 1;
		}

		int max = 0;

		for (int i=1; i<a.length; i++) {
			a[i] += a[i-1];
			if (i <= a[i]) max = i;
		}

		out.println(max-1);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 101316
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
	
}

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

using namespace std;

const int maxx = 210;

int n, a[maxx], ans = 0;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n; n *= 2;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for(int i = 0; i < n; i += 2) ans += a[i];
	cout << ans << '\n'; 
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[100010];
map<pair<int, int>, int> mp;
int ans = 0;
void dfs(int v, int p, int x) {
    int k = 0;
    rep(i, G[v].size()) {
        if (G[v][i] == p) continue;
        k++;
        if (k < x){
            mp[{v, G[v][i]}] = k;
            ans = max(ans, k);
            dfs(G[v][i], v, k);
        }
        else {
            mp[{v, G[v][i]}] = k + 1;
            ans = max(ans, k + 1);
            dfs(G[v][i], v, k + 1);
        }
    }
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int s[100010], t[100010];
    rep(i, N - 1) {
        cin >> s[i] >> t[i];
        G[s[i]].push_back(t[i]);
        G[t[i]].push_back(s[i]);
    }
    dfs(1, -1, INF);
    cout << ans << endl;
    rep(i, N - 1) cout << mp[{s[i], t[i]}] << endl;

    return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N, M, V, P;
vector<int> A;

void _main() {
    cin >> N >> M >> V >> P;
    A.resize(N);
    REP (i, N) cin >> A[i];
    sort(A.begin(), A.end());
    vector<int> cum(N + 1, 0);
    REP (i, N) cum[i + 1] = cum[i] + A[i];
    int ans = P;
    FOR (i, max(0LL, V - P), N - P) ans += (A[i] + M >= A[N - P]);
    if (V > P) {
        REP (i, V - P) {
            int ub = min(N - P + 1, (int)(upper_bound(A.begin(), A.end(), A[i] + M) - A.begin()));
            if (ub < N - P + 1) continue;
            ans += (cum[ub] - cum[i + 1] <= (ub - i - 1) * (A[i] + M) - M * (V - P - i));
        }
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 4784
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> ii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "Yes\n";
string no = "No\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
//const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P


int main()
{
    int n;
    set < int > st;
    cin >> n;
    ff(i,1,n) {
        int x;
        cin >> x ;
        if (st.count(x)){
            st.erase(x);
        }else {
            st.insert(x);
        }
    }
    cout << sz(st) << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int C[3][3];

signed main(){
    rep(i,3)rep(j,3)cin>>C[i][j];

    rep(i,2)rep(j,2){
        if(C[i][j]+C[i+1][j+1]!=C[i][j+1]+C[i+1][j]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
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 += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[15][15], b, c[ohara], d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  ans = LINF;
  for (int bit = 0; bit < (1 << n); bit++) {
    cnt = 0;
    ll dp[20] = {};
    int ok = 1;
    rep(i, n) {
      if (bit & (1 << i)) {
        cnt += c[i];
        rep(j, m) dp[j] += a[i][j];
      }
    }
    rep(i, m) {
      if (dp[i] >= x) continue;
      ok = 0;
    }
    if (!ok) continue;
    ans = min(ans, cnt);
  }
  if (ans != LINF)
    Cout(ans);
  else
    Cout(-1);
  return 0;
}

Measured memory_bytes: 3664