akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <complex>
#include <tuple>
#include <vector>
using namespace std;

using vec = complex<double>;
using line = pair<vec,vec>;
using polygon = vector<vec>;
const double eps = 0.0000001;

double inner_product(vec u,vec v){
    return real(u*conj(v));
}
double cross_product(vec u,vec v){
    return imag(conj(u)*v);
}

vec projection(line l,vec p){//p???l???????°???±
    vec s=l.first, t=l.second;
    double k = inner_product(t-s,p-s)/inner_product(t-s,t-s);
    return (1.0-k)*s+k*t;
}

vec reflection(line l,vec p){
    return 2.0*projection(l,p)-p;
}

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = cross_product(ab,ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(inner_product(ab,ac)<0){
        return 2; //C-A-B
    }else{
        if(inner_product(ab,ab)<inner_product(ac,ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

bool isIntersect(line l0, line l1){
    int s = ccw(l0.first,l0.second,l1.first)*ccw(l0.first,l0.second,l1.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    s=ccw(l1.first,l1.second,l0.first)*ccw(l1.first,l1.second,l0.second);
    if(s!=0&&s!=-1&&s!=-4) return false;
    else return true;
}

vec interSection(line l0, line l1){
    vec s0, t0, s1, t1;
    tie(s0,t0)=l0; tie(s1,t1)=l1;
    double k = cross_product(t1-s1,s1-s0)/cross_product(t1-s1,t0-s0);
    return s0+(t0-s0)*k;
}

double segLength(line l){
    return abs(l.first-l.second);
}

double distLine2point(line l, vec p){
    return abs(cross_product(l.second-l.first,p-l.first))/abs(l.second-l.first);
}

double distSeg2Point(line l, vec p){
    vec x = projection(l,p);
    double L = segLength(l);
    if(abs(x-l.first)<L&&abs(x-l.second)<L){
        return abs(x-p);
    }else{
        return min(abs(l.first-p),abs(l.second-p));
    }
}

double distSeg2Seg(line l1, line l2){
    if(isIntersect(l1,l2)) return 0;
    double ret = 1e20;
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    swap(l1,l2);
    ret = min(ret,distSeg2Point(l1,l2.first));
    ret = min(ret,distSeg2Point(l1,l2.second));
    return ret;
}

double area(polygon& g){
    double S=0;
    for(auto i = g.begin()+1; i!=g.end();++i){
        S += cross_product(*(i-1),*i);
    }
    S/=2;
    return S;
}

bool isConvex(polygon& g){
    int n=g.size()-2;
    for(int i=0;i<n;i++){
        if(!~ccw(g[i],g[i+1],g[i+2]))return false;
    }
    return true;
}

//???????????§???????????????

int main(){
    int n;
    cin >> n;
    polygon g;
    while(n--){
        int x,y;
        cin>>x>>y;
        g.emplace_back(x,y);
    }
    g.push_back(g[0]);
    g.push_back(g[1]);
    cout.precision(1);
    cout << fixed;
    cout << (isConvex(g)?1:0) << endl;
    return 0;
}

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


int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> x2 >> y1 >> y2;
    double ans;
    ans=(x1-y1)*(x1-y1)+(x2-y2)*(x2-y2);
    printf("%.10lf\n",sqrt(ans));



}


Measured memory_bytes: 3288
/*  Author : Alpha_The_Coder
    Created on 13/09/2020      */
#include <bits/stdc++.h>
using namespace std;
#define iamalpha ios_base::sync_with_stdio(false);cin.tie(NULL);
#define loop(a,n) for(int i=a;i<n;i++)
#define nloop(a,n) for(int j=a;j<n;j++)
#define lli long long int
lli mod=1000000007;
void solve();


int main()
{
    iamalpha;
    int t=1;
    while(t--)
    {
        solve();
    }
}

void solve()
{
  string s;
  cin>>s;
  int n=s.size();
  if(s[n-1]!='s')
    cout<<s<<'s';
  else
    cout<<s<<"es";




}


// Solely contributed by Subhojeet Sahoo aka Alpha


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, a[200000];
bool cov[1000001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int cnt = 0;
	for(int i = 0; i < n; i++){
		bool val = true;
		for(int j = 1; j * j <= a[i]; j++)
			if(a[i] % j == 0 && (cov[j] || cov[a[i] / j]))
				val = false;
		if(i < n && a[i + 1] == a[i]) val = false;
		cov[a[i]] = true;
		cnt += val;
	}
	cout << cnt << "\n";
	return 0;
}

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

using namespace std;

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

    string weather;
    cin >> weather;
    if (weather == "Sunny") cout << "Cloudy";
    if (weather == "Cloudy") cout << "Rainy";
    if (weather == "Rainy") cout << "Sunny";
    cout << endl;

    return 0;
}

Measured memory_bytes: 892
n, w = gets.chomp.split(" ").map(&:to_i)

v_list = Array.new(4).map{Array.new}
v_sum_list = Array.new(4).map{Array.new}

w1 = 0
n.times do |i|
    a, b = gets.chomp.split(" ").map(&:to_i)
    if i == 0
        w1 = a
    end
    v_list[a-w1] << b
end

v_sum_list[0][0] = 0
v_sum_list[1][0] = 0
v_sum_list[2][0] = 0
v_sum_list[3][0] = 0

v_list.each_with_index do |v, i|
    v.sort!.reverse!
    v.each_with_index do |vv, j|
        v_sum_list[i][j+1] = vv + v_sum_list[i][j]
    end
end


sum = 0
for i in 0..(v_sum_list[0].size-1)
    for j in 0..(v_sum_list[1].size-1)
        for k in 0..(v_sum_list[2].size-1)
            for l in 0..(v_sum_list[3].size-1)
                next if w < (i * w1) + (j * (w1+1)) + (k * (w1+2)) + (l * (w1+3)) 
                tmp = v_sum_list[0][i] + v_sum_list[1][j] + v_sum_list[2][k] + v_sum_list[3][l]
                sum = tmp if sum < tmp
            end
        end
    end
end

puts sum

Measured memory_bytes: 3836
#include <bits/stdc++.h> 
using namespace std; 
  
int main()  
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n,x,t;
    cin>>n>>x>>t;
    int T=(n+x-1)/x;
    cout<<T*t;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    set<char> nums;
    rep(i, n){
        char inp;
        cin >> inp;
        nums.insert(inp);
    }

    if(nums.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int gcd(int a,int b){
    if(a==0||b==0)return max(a,b);
    int mi=min(a,b);int ma=max(a,b);
    int c=ma%mi;
    return gcd(mi,c);
}


int N;
int A[1000005];
bool soinsu[1000005];
bool ispairwise=true;
void PrimeF(int N){
    int M=N;
    for(int i=2;i<sqrt(N)+1&&M!=1;i++){
        int cnt=0;
        while(M%i==0){
            M/=i;
            cnt++;
        }
        if(cnt>0){
            if(soinsu[i]){ispairwise=false;return;}
            soinsu[i]=true;
        }
    }
    if(M!=1){
        if(soinsu[M]){ispairwise=false;return;}
        soinsu[M]=true;
    }
    return;
}

signed main(){
    scanf("%lld",&N);
    int a=1,b=1;
    int maxA=0;
    rep(i,N){
        scanf("%lld\n",&A[i]);
        maxA=max(A[i],maxA);
        b=A[i];
        if(i==0)a=A[i];
        a=gcd(a,b);
    }
    rep(i,maxA+3)soinsu[i]=false;
    rep(i,N){
        PrimeF(A[i]);
    }
    if(ispairwise)printf("pairwise coprime\n");
    else{
        if(a==1)printf("setwise coprime\n");
        else printf("not coprime\n");
    }
}

Measured memory_bytes: 10840
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int h, w;
  char s[101][101];
  char tate[101], yoko[101];
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++)
  {
    scanf("%s", s[i]);
  }

  for (int i = 0; i < h; i++)
  {
    int cnt = 0;
    for (int j = 0; j < w; j++)
    {
      if (s[i][j] == '#')
        cnt++;
    }
    yoko[i] = cnt;
  }

  for (int j = 0; j < w; j++)
  {
    int cnt = 0;
    for (int i = 0; i < h; i++)
    {
      if (s[i][j] == '#')
        cnt++;
    }
    tate[j] = cnt;
  }

  for (int i = 0; i < h; i++)
  {
    if (yoko[i])
    {
      for (int j = 0; j < w; j++)
      {
        if (tate[j])
        {
          putchar(s[i][j]);
        }
      }
      puts("");
    }
  }

  return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        s: chars,
    };
    if s.len() == 1{
        println!("{}", s[0]);
        return;
    }
    let mut ans = 0;
    for i in 0..2u32.pow((s.len()-1) as u32){
        let mut ss = format!("{:0>1$b}", i, s.len()-1).chars().collect::<Vec<_>>();
        ss.reverse();
        let mut stack = vec![];
        stack.push(s[0]);
        for (i, &c) in ss.iter().enumerate(){
            if c == '0'{
                stack.push(s[i+1]);
            } else {
                ans += stack.iter().map(|&c| c).collect::<String>().parse::<i64>().unwrap();
                stack.clear();
                stack.push(s[i+1]);
            }
        }
        if !stack.is_empty(){
                ans += stack.iter().map(|&c| c).collect::<String>().parse::<i64>().unwrap();
        }
    }
    println!("{}", ans );
}


Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let s: String = read();
    match &*s {
	"SUN" => println!("7"),
	"MON" => println!("6"),
	"TUE" => println!("5"),
	"WED" => println!("4"),
	"THU" => println!("3"),
	"FRI" => println!("2"),
	"SAT" => println!("1"),
	_ => println!("error"),
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
int main()
{
	int a[10],i=2,j,x;
	while(i--){for(j=0;j<10;++j)scanf("%d",&a[j]);std::sort(a,a+j);x=a[9]+a[8]+a[7];printf("%d%c",x,i?' ':'\n');}
	return 0;
}

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

int main(){
	int n, m; cin >> n >> m;
	int num[n];
	for(int i = 0; i < n; ++i) num[i] = 1;
	bool red[n] = {1};
	for(int i = 0; i < m; ++i){
		int x, y; cin >> x >> y;
		--x; --y;
		if(num[x] >= 2){
			--num[x];
			++num[y];
			if(red[x]) red[y] = 1;
		}else{
			--num[x];
			++num[y];
			if(red[x]) red[y] = 1;
			red[x] = 0;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i) ans += red[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = ReadLine().Split(' ').Select(value => double.Parse(value)).ToArray();
            var a = firstLine[0];
            var b = firstLine[1];
            var h = firstLine[2];
            var m = firstLine[3];

            var hourX = a * Cos(2 * PI * (h * 60 + m) / (12 * 60));
            var hourY = a * Sin(2 * PI * (h * 60 + m) / (12 * 60));
            var minuteX = b * Cos(2 * PI * m / 60);
            var minuteY = b * Sin(2 * PI * m / 60);

            var x = hourX - minuteX;
            var y = hourY - minuteY;

            WriteLine(Sqrt(x * x + y * y));
        }
    }
}


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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

void vprint(vector<ll> A){
    if(A.size()==0){
        p("");
    }else{
        cout << A[0];
        FOR(i, 1, A.size()){
            cout << " " << A[i];
        }
        cout << endl;
    }
}

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

    // input
    ll N, Q;
    cin >> N >> Q;

    vector<ll> A[N];

    while(Q--){
        ll a;
        cin >> a;

        // push
        if(a==0){
            ll t, x;
            cin >> t >> x;
            A[t].push_back(x);
        }
        // dump
        else if(a==1){
            ll t;
            cin >> t;
            vprint(A[t]);
        }
        // clear
        else{
            ll t;
            cin >> t;
            A[t].clear();
        }
    }
    
    return 0;
}


Measured memory_bytes: 10920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }
    public void run() {
    	FastScanner sc = new FastScanner(System.in);
    	int n = Integer.parseInt(sc.next());
    	int l = Integer.parseInt(sc.next());
    	int t = Integer.parseInt(sc.next());
		PrintWriter out = new PrintWriter(System.out);
		int[] x = new int[n];
		int[] w = new int[n];
		for(int i = 0; i < n; i++)
		{
			x[i] = Integer.parseInt(sc.next());
			w[i] = Integer.parseInt(sc.next());
		}
		int tmp = t % l;
		int[] a = new int[n];
		for(int i = 0; i < n; i++)
		{
			int ans = x[i];
			if(w[i] == 1)
			{
				ans += tmp;
				ans %= l;
			}
			else
			{
				ans -= tmp;
				if(ans < 0)
				{
					ans += l;
				}
			}
			a[i] = ans;
		}

		int count = 0;
		for(int i = 1; i < n; i++)
		{
			if(w[0] != w[i])
			{
				long count_tmp = (long)(t*2)/(long)l;
				count_tmp %= n;
				count += count_tmp;
				count %= n;
				if(w[0] ==1)
				{
					int tx = x[i]-x[0];
					if(tx < 0)
					{
						tx = tx + l;
					}
					if((t*2)%l >= (tx))
					{
						count++;
					}
					if((t*2)%l >= (tx)+(l+1)/2)
					{
						//count++;
					}
				}
				else
				{
					int tx = x[0]-x[i];
					if(tx < 0)
					{
						tx = tx + l;
					}
					if((t*2)%l >= (tx))
					{
						count++;
					}
					if((t%l)*2 >= (tx)+(l+1)/2)
					{
						//count++;
					}
				}
			}
		}
		if(w[0] == 2)
		{
			count = n - count;
		}
		count %= n;
		int pos0 = a[0];
		Arrays.parallelSort(a);
		int p=0;
		int ant0pos = -1;
		while(ant0pos == -1)
		{
			if(a[p] == pos0)
			{
				if(w[0] == 1 && a[(p+1)%n] == a[p])
				{
					ant0pos=p+1;
				}
				else
				{
					ant0pos = p;
				}
			}
			p++;
		}
		for(int i = 0; i < n; i++)
		{
			int ap = (i+ant0pos-count)%n;
			if(ap < 0) {
				ap += n;
			}
			out.printf("%d\n", a[ap]);
		}
		out.flush();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
    }
}

Measured memory_bytes: 75628
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main() {
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int max = 1;
    int min = a[0];

    for (int i = 0; i < n; i++) {
        if (a[i] > max) {
            max = a[i];
        }
        else if (a[i] < min) {
            min = a[i];
        }
    }

    cout << max - min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

ll gcd(ll x,ll y){
    if (x%y==0) return y;
    return gcd(y,x%y); 
}
ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

int main(){
    ll a, b; cin >> a >>b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>
#include <boost/multiprecision/cpp_int.hpp>

#pragma warning(disable:4996)

using namespace std;

int main() {
  boost::multiprecision::cpp_int a, b;
  cin >> a >> b;
  cout << (a > b ? "GREATER" : a < b ? "LESS" : "EQUAL") << endl;
  return 0;
}


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

int main(){
  char a, b, c;
  cin >> a >> b;
  if(a == b){
    c = '=';
  }
  else if(a > b){
    c = '>';
  }
  else{
    c = '<';
  }
  cout << c << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;

    ll ans = 1;
    ll cnt = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (cnt % 2 == 0) {
            if (s[i] == 'W') {
                if (cnt == 0) {
                    ans = 0;
                    break;
                }

                (ans *= cnt) %= MOD;
                cnt--;
            } else {
                cnt++;
            }
        } else {
            if (s[i] == 'W') {
                cnt++;
            } else {
                if (cnt == 0) {
                    ans = 0;
                    break;
                }

                (ans *= cnt) %= MOD;
                cnt--;                
            }
        }
    }

    if (ans == 0 || cnt > 0) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i <= n; i++) {
        (ans *= i) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
const int N = 1e6+100;
int color[N];
bool vis[N];
int depth[N];
int ans;
int used[N];
vector<pair<int,int>> G[N];
int id[N];
void bfs(int s){
  queue<int> q;
  q.push(s);
  while(!q.empty()){
    int u=q.front();q.pop();
    if(vis[u]) continue;
    vis[u]=1;
    int cnt=0;
    // cout<<"u: "<<u<<endl;
    for(auto V:G[u]){
      int v=V.first;
      int id=V.second;
      if(!color[id]){
        ++cnt;
        if(cnt==used[u]) ++cnt;
        color[id]=cnt;
        used[v]=cnt;
      }
      q.push(v);
    }
  }
}
int main(){
  int n,u,v;
  cin>>n;
  for(int i=1;i<=n-1;i++){
    cin>>u>>v;
    G[u].push_back({v,i});
    G[v].push_back({u,i});
    id[u]++;
    id[v]++;
  }
  ans=0;
  for(int i=1;i<=n;i++){
    ans=max(ans,id[i]);
  }
  cout<<ans<<endl;
  bfs(1);
  for(int i=1;i<=n-1;i++) cout<<color[i]<<endl;
  return 0;
}

Measured memory_bytes: 35456
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- main
main :: IO ()
main = march

march :: IO ()
march = do
  n  :: Int <- readLn
  ss :: V.Vector T.Text <- V.replicateM n T.getLine
  let ms = V.filter (\s -> T.head s /= 'M') ss
      m  = V.length ss - V.length ms
      as = V.filter (\s -> T.head s /= 'A') ms
      a  = V.length ms - V.length as
      rs = V.filter (\s -> T.head s /= 'R') as
      r  = V.length as -  V.length rs
      cs = V.filter (\s -> T.head s /= 'C') rs
      c  = V.length rs - V.length cs
      hs = V.filter (\s -> T.head s /= 'H') cs
      h  = V.length cs - V.length hs
      rc = r + c
      ma = m + a
  print $ m * a * (rc + h) + r * c * (ma + h) + h * rc * ma

Measured memory_bytes: 26492
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int> 
#define rep(i,a,n) for(i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int i,int n,vin &a){
    rep(i,0,n){
        cin>>a.at(i);
    } 
} 

signed main() {
    int i;
    vin st(4);
    rep(i,0,4){
        cin>>st.at(i);
    }
    int x=st.at(2)-st.at(0);
    int y=st.at(3)-st.at(1);
    string gox,goy,backx,backy;
    rep(i,0,x){
        gox.push_back('R');
        backx.push_back('L');
    }
    rep(i,0,y){
        goy.push_back('U');
        backy.push_back('D');
    }

    cout<<goy<<gox<<"U"<<backx<<"LD"<<backy<<"R";
    cout<<gox<<goy<<"R"<<backy<<"DL"<<backx<<"U"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

const int INF = 1e9;

struct Edge {
    int s, t, c;
};

using pii = pair<int, int>;

void dijkstra(int v, const vector<vector<Edge>>& e, set<pii>& black_edges) {
    auto dist = vector<int>(e.size(), INF);

    set<pii> grey;

    dist[v] = 0;
    grey.insert({0, v});

    vector<set<int>> black_ein(e.size());

    while (!grey.empty()) {
        auto [du, u] = *grey.begin();
        grey.erase(grey.begin());

        for (auto& edge : e[u]) {
            int t = edge.t, c = edge.c;
            if (dist[t] > du + c) {
                grey.erase({dist[t], t});
                dist[t] = du + c;
                grey.insert({dist[t], t});

                black_ein[t].clear();
                black_ein[t].insert(u);
            } else if (dist[t] == du + c) {
                black_ein[t].insert(u);
            }
        }
    }
    for (int i = 0; i < e.size(); ++i) {
        for (int j : black_ein[i]) {
            black_edges.insert({min(i, j), max(i, j)});
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    vector<vector<Edge>> e(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        e[a].push_back({a, b, c});
        e[b].push_back({b, a, c});
    }
    set<pii> be;
    for (int i = 0; i < n; ++i) {
        dijkstra(i, e, be);
    }
    cout << m - be.size();
}


Measured memory_bytes: 3688
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (ll)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
map<PII,int> ma;
void solve(){
	ll n,best;
	cin>>n;
	vector<VI> gra(n+1);
	vector<PII> num; 
	rep(i,1,n)
	{
		int x,y;
		cin>>x>>y;
		num.pb({x,y});
		gra[x].pb(y);
		gra[y].pb(x);
		best = max({best,sz(gra[x]),sz(gra[y])});
	} 
	VI vis(n+1,0);
	vis[1] = 1;
	queue<PII> q;
	q.push({1,-1});
	while(!q.empty()){
		PII vc = q.front();
		int v = vc.fi;
		int pc = vc.se;
		q.pop();
		int color = 1;
		rep(i,0,sz(gra[v])){
			int u = gra[v][i];
			if(vis[u])continue;
			while(color==pc)color++;
			ma[{u,v}] = color;
			ma[{v,u}] = color;
			q.push({u,color});
			vis[u] = 1;
			color++;
		}
	} 
	cout<<best<<endl;
	rep(i,0,n-1){
		cout<<ma[{num[i]}]<<endl;
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

using namespace std;

int main()
{
	string a, b, c;
	
	cin >> a >> b >> c;
	
	if (a.back() == b.front() && b.back() == c.front()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(auto i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
ll dp[100003][3]; vll input[100003]; ll ans=0; ll n;

ll func(ll day, ll prev)
{
	ll x=0;
	if(day==(n))
	{
		return 0;
	}
	if(dp[day][prev]!=-1 && day>0)return dp[day][prev];
	forA(i,0,3,1)
	{
		if(i==prev)continue;
		else
		{
			x=max(func(day+1,i),x);
		}
	}
	if(day>=0&& prev>=0)dp[day][prev]=input[day][prev]+x;
	//if(dp[day][prev]==-1)dp[day][prev]=x;else dp[day][prev]+=x; 
	return dp[day][prev];
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	ll a,b,c; cin>>n; forA(i,0,n,1){cin>>a>>b>>c; input[i].pb(a); input[i].pb(b); input[i].pb(c);}
	forA(i,1,100003,1)forA(j,0,3,1)dp[i][j]=-1;
	forA(i,0,3,1)dp[0][i]=input[0][i];
	a=func(0,0); a=func(0,1 ); a=func(0,2);
	//forA(i,0,n,1){forA(j,0,3,1)cout<<dp[i][j]<<"\t";cout<<"\n";}
	forA(i,0,3,1)ans=max(ans,dp[0][i]); cout<<ans;
	return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    vector<string> s = {"NO", "YES"};
    lint n;
    cin >> n;
    vector<lint> a(n + 1);
    lint sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    a[n] = a[0];
    // num_op:操作の合計回数
    lint num_op = sum / (n * (n + 1) / 2);
    // op[i]:iが操作で選ばれるべき回数
    vector<lint> op(n, 0);
    for (int i = 0; i < n; i++) {
        int expect = a[i] + num_op;
        if (a[i + 1] > expect || (a[i + 1] - expect) % n != 0) {
            cout << s[0] << endl;
            return 0;
        } else {
            op[i] = (expect - a[i + 1]) / n;
        }
    }
    //必要条件として求めた操作回数でa[0]が実現できるか見る
    lint test = 0;
    for (int i = 1; i <= n; i++) {
        test += op[n - i] * i;
    }
    if (test == a[0]) {
        cout << s[1] << endl;
    } else {
        cout << s[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define pai 3.1415926535


int main(void) {
	int M[2], D[2];
	for (int i = 0; i < 2; i++) {
		scanf("%d%d", &M[i], &D[i]);
	}
	int a = M[0];
	a++;
	if ((M[0] != M[1]) && (D[1] == 1)) {
		printf("%d",1);
	}else{
		printf("%d",0);
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n != 0) {
            int[][] p = new int[9][9];
            boolean[][] m = new boolean[9][9];
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    p[i][j] = sc.nextInt();
                }
            }
            for (int i = 0; i < 9; i++) {
                int c[] = new int[10];
                for (int j = 0; j < 9; j++) {
                    c[p[i][j]]++;
                }
                for (int j = 0; j < 9; j++) {
                    if (c[p[i][j]] > 1) {
                        m[i][j] = true;
                    }
                }
            }

            for (int i = 0; i < 9; i++) {
                int c[] = new int[10];
                for (int j = 0; j < 9; j++) {
                    c[p[j][i]]++;
                }
                for (int j = 0; j < 9; j++) {
                    if (c[p[j][i]] > 1) {
                        m[j][i] = true;
                    }
                }
            }
            for (int l = 0; l < 9; l += 3) {
                for (int i = 0; i < 9; i += 3) {
                    int c[] = new int[10];
                    for (int j = i; j < i + 3; j++) {
                        for (int k = l; k < l + 3; k++) {
                            c[p[j][k]]++;
                        }
                    }
                    for (int j = i; j < i + 3; j++) {
                        for (int k = l; k < l + 3; k++) {
                            if (c[p[j][k]] > 1)
                                m[j][k] = true;
                        }
                    }
                }
            }
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    System.out.print(m[i][j] ? "*" : " ");
                    System.out.print(p[i][j]);
                }
                System.out.println();
            }
            n--;
            if (n != 0)
                System.out.println();
        }
    }
}

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

int main() {
  long long N;
  cin >>N;
  vector<long long> vec(N);
  long long a =1;
  for(int i=0;i < N;i++){
    vec[i] =a;
    a++;
  }
  long long sum =0;
  for(int i =0;i < N;i++){
    if(vec[i] % 3 !=0){
      if(vec[i] % 5 !=0){
      sum += vec[i];
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 11160
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  string str[2];
  for(auto i = 0; 2 > i; ++i){
    cin >> str[i];
  }

  string s_num = str[0] + str[1];
  double d_num = sqrt(stod(s_num));

  if(floor(d_num) == ceil(d_num)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll n, ans;
    ans = 0;
    cin >> n;
    vector<ll> v(n);
    rep(i, n){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ans += v[n - 1]/2;
    rep(i, n - 1){
        ans += v[i];
    }
    cout << ans << endl;
}


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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	if (N % 2 == 1) {
		cout << "No" << endl;
	} else {
		if (S.substr(0, N/2) == S.substr(N/2, N)) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

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

using namespace std;

typedef pair <int, int> data;

const int N = 303;

bitset <N> vis;
priority_queue <data> pq;
int n, m, a[N][N], f[N][N], at[N], cnt[N];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", a[i] + j);
    }
  }
  for (int i = 1; i <= n; ++i) {
    at[i] = 1;
    ++cnt[a[i][1]];
  } 
  int best = n;
  for (int i = 1; i < m; ++i) {
    int maxVal = -1, pos;
    for (int j = 1; j <= m; ++j) {
      if (cnt[j] > maxVal) {
        maxVal = cnt[j];
        pos = j;
      }
    }
    // for (int _i = 1; _i <= m; ++_i) cout << cnt[_i] << " "; cout << endl;
    // cout << maxVal << " " << pos << endl;
    best = min(best, maxVal);
    cnt[pos] = 0, vis[pos] = 1;
    for (int j = 1; j <= n; ++j) {
      if (!vis[a[j][at[j]]]) continue;
      while (at[j] <= m and vis[a[j][at[j]]]) {
        ++at[j];
      }
      if (at[j] <= m) {
        ++cnt[a[j][at[j]]];
      }
    }
  }
  printf("%d\n", best);
  return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    vector<string> subset;
    string s,t;
    int k,count=0;
    cin >> s >> k;
    if(k==1){
        int temp=0;
        vector<int> use(26,0);
        for(int i=0; i<s.length(); i++){
            use[ s[i]-'a' ]++;
        }
        for(int i=0; i<26; i++){
            if(use[i])count++;
            if(count==k){
                char ans='a'+i;
                cout <<  ans << endl;
                return 0;
            }
        }
    }
    for(int i=0; i<s.length(); i++){
        for(int j=1; j<=k; j++){
            if(i+j>s.length())break;
            t=s.substr(i,j);
            subset.push_back(t);
        }
    }
    sort(subset.begin(),subset.end());
    for(int i=0; i<subset.size(); i++){
        if(i==0){
            count++;
            continue;
        }
        if(subset[i-1]==subset[i])continue;
        count++;
        if(count==k){
            cout << subset[i] << endl;
            return 0;
        }
    }
    cout << count << endl;
    return 0;
}

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

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100010;

int g[2][N], dp[2][N];
int n;
int solve (int i, int j) {
	if (j >= n or i > 1) return -INF;
	if (j == n-1 and i == 1) return g[i][j];
	if (dp[i][j] != -1) return dp[i][j];
	return dp[i][j] = max(solve(i, j+1), solve(i+1, j)) + g[i][j];
}
int main (void) {
	cin >> n;
	for (int i = 0; i < 2; i++)
	for (int j = 0; j < n; j++)
		cin >> g[i][j];
	memset (dp, -1, sizeof dp);
	cout << solve(0, 0) << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n,ans=0;
  cin >> n;
  char s[n];
  cin >> s;
  char c[3];
  REP(i,1000) {
    c[0]=i/100+'0';
    c[1]=(i/10)%10+'0';
    c[2]=i%10+'0';
    int cnt=0;
    REP(j,n) {
      if(s[j]==c[cnt]) cnt++;
    }
    if(cnt==3) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] arg){
        Main m = new Main();
        m.run();
    }

    void run(){

        for(;;){
            int d=sc.nextInt();
            int w =sc.nextInt();

            if(d == 0){
                break;
            }

            int map[][] = new int[d][w];
            for(int i =0; i< d; i++){
                for(int j = 0 ; j < w; j++){
                    map[i][j] = sc.nextInt();
                }
            }

            int max = 0;
            for(int i = 0; i < d; i++){
                for(int j = 0 ; j < w; j++){
                    for(int k = i+1; k<d; k++){
                        for(int l = j+1;l < w;l++){

                            int wallsize = wall(map,i,j,k,l);
                            max = Math.max(max, size(map,i,j,k,l,wallsize));
                        }
                    }
                }
            }
            System.out.println(max);

        }
    }
    int wall(int[][] map,int i, int j , int k ,int l){
        int min = map[i][j];
        for(int x = i; x <= k; x++){
            min = Math.min(map[x][j],min);
            min = Math.min(map[x][l], min);
        }
        for(int y= j; y <= l ;y++){
            min = Math.min(map[i][y],min);
            min = Math.min(map[k][y],min);
        }
        return min;
    }

    int size(int[][]map,int i,int j,int k,int l,int w){
        int sum = 0;
        for(int x = i+1 ; x < k; x++){
            for(int y = j+1; y<l ;y++){
                if(map[x][y] >= w){
                    return 0;
                }
                sum += w-map[x][y];
            }
        }
        return sum;
    }
}



Measured memory_bytes: 36348
from collections import defaultdict

N, M = map(int, input().split())
A = [int(x) for x in input().split()]


class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

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


if 2 * (N - M - 1) > N:
    print('Impossible')
elif N - M == 1:
    print(0)
else:
    uf = UnionFind(N)
    for _ in range(M):
        x, y = map(int, input().split())
        uf.union(x, y)

    tree = defaultdict(list)
    for i in range(N):
        tree[uf.find(i)].append(A[i])

    ans = 0
    rest = []
    for v in tree.values():
        x = min(v)
        v.remove(x)
        rest += v
        ans += x

    rest = sorted(rest)
    ans += sum(rest[:N - M - 2])
    print(ans)


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

int N;
ll C;

ll rSum[MAX_N];
ll lSum[MAX_N];
ll lMax[MAX_N];

ll solve(vector< ll > x, vector< ll > v)
{
  // 原点から右方向に進んだ時の、摂取できるカロリーの累積和を求める
  REP(i, N) {
    if (i > 0) rSum[i] = rSum[i - 1] + v[i];
    else rSum[i] = v[i];
  }

  // 原点から左方向に進んだ時の、摂取できるカロリーと消費するカロリーの差の最大値を求める
  // mxは原点から左方向に進んだ時に得られる最大のカロリー
  ll mx = 0ll;
  RREP(i, N) {
    ll cal = (i < N - 1 ? x[i + 1] - x[i] : C - x[i]);
    if (i < N - 1) lSum[i] = lSum[i + 1] + v[i] - cal;
    else lSum[i] = v[i] - cal;
    mx = max(mx, lSum[i]);
    lMax[i] = mx;
  }

  // 右に行く範囲を大きくしていって、最大値を求める
  ll res = 0ll;
  REP(ub, N) {
    ll sum = 0ll;

    // printf("ub = %d\n", ub);
    
    sum -= x[ub];
    // debug(sum);
    sum += rSum[ub];

    // 左に戻らずに出る場合
    res = max(res, sum);

    sum -= x[ub];
    // debug(sum);

    if (ub < N - 1) sum += lMax[ub + 1];

    // printf("sum = %ld\n", sum);
    // printf("res = %ld\n", res);
    res = max(res, sum);
  }
  // cout << endl;

  return res;
}

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

  cin >> N >> C;
  vector< ll > x(N);
  vector< ll > v(N);
  REP(i, N) {
    cin >> x[i] >> v[i];
  }

  ll ans = solve(x, v);

  reverse(ALL(x));
  REP(i, N) {
    x[i] = C - x[i];
  }
  reverse(ALL(v));

  ans = max(ans, solve(x, v));

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



Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
class Dijkstra{
public:
    struct edge{ll to; double cost;};
    typedef pair<double,ll> P;//firstは最短距離、secondは頂点の番号

    int V;//超点数
    vector<vector<edge> > G;//グラフ,G[i]はiから出る辺の集合,G[i][j]はiから出る辺のj番目の辺
    vector<double> d; //最短距離

    //0origin
    Dijkstra(int N){
        V = N;
        G = vector<vector<edge> >(N);
        d = vector<double>(N);
    };

    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P> > que;
        fill(d.begin(),d.end(),INFl);
        d[s] = 0;
        que.push(P(0,s));

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

    }
    /* 頂点fromに頂点toに達するコストcostの辺を貼る */
    void addEdge(int from,int to,double cost){
        edge e{};
        e.to = to;
        e.cost = cost;
        G[from].push_back(e);
    }
};

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

    int xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    int N;
    cin >> N;
    vector<int> x(N+2),y(N+2),r(N+2);
    rep(i,1,N+1){
        cin >> x[i] >> y[i] >> r[i];
    }
    x[0] = xs;
    y[0] = ys;
    x[N+1] = xt;
    y[N+1] = yt;

    Dijkstra dij(N+2);

    rep(i,0,N+2){
        rep(j,0,N+2){
            double cost = sqrt(pow(x[i] - x[j],2) + pow(y[i] - y[j],2)) - r[i] - r[j];
            if(cost < 0) cost = 0.0;
            dij.addEdge(i,j,cost);
        }
    }

    dij.dijkstra(0);
//    cout << dij.d[N+1] << endl;
    printf("%.9lf\n",dij.d[N+1]);

    return 0;
}


Measured memory_bytes: 21104
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	int a[200005];

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

	int ans = 0;
	int j = 1;
	for (int i = 0; i < N; i++) {
		if (a[i] != j) {
			ans++;
		} else {
			j++;
		}
	}
	if (j == 1) {
		ans = -1;
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
// typedef Graph vector<vector<int>>; // グラフ型
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n, ans = 0;
    cin >> n;
    vi d(n);
    rep(i, n)cin >> d[i];
    rep(i, n - 1){
        REP(j, i + 1, n){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256