akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int X,t;

int main(){
    cin>>X>>t;
    out(max(X-t,0));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, req = 0;
    cin >> n;
    if(n%111 == 0) cout << n << endl;
    else{
        n /= 111;
        req = (n+1)*111;
        cout << req << endl;
    }
return 0;
}


Measured memory_bytes: 256
<?php
$input = trim(fgets(STDIN));
$s = str_split((string) $input);
$results = [];
$before = '';
$stack = '';
foreach ($s as $i => $char) {
    $stack .= $char;
    if ($before != $stack) {
        $results[] = $stack;
        $before = $stack;
        $stack = '';
    }
}
echo count($results) . "\n";

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int k,s;cin>>k>>s;
  int ans=0;
  for (int i=0; i<=k; i++) {
    for (int j=0; j<=k; j++) {
      int t = s-i-j;
      if (0<=t&&t<=k) ans++;
    }
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

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

  vi a(N + 1);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        ll n = x * x + y * y + z * z + x * y + y * z + z * x;
        if (n <= N) a[n]++;
      }
    }
  }

  for (int i = 1; i <= N; i++) {
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
import math
N, H = map(int, input().split())
A = []
B = []
AB = []

for n in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    AB.append((a,b))

#A.sort()
#B.sort()
amax = max(A)
bmax = max(B)

B.sort(reverse=True)
i = 1
cnt = 1
H -= bmax

while H > 0:
    #print(i, B[i], N, H)
    if i < N and B[i] > amax:
        cnt += 1
        H -= B[i]
        i += 1
    else:
        cnt += math.ceil(H/amax)
        #print(H,amax, math.ceil(H/amax), math.ceil(H/amax) * amax)
        H -= math.ceil(H/amax) * amax
        #print(H)

print(cnt)


Measured memory_bytes: 18480
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  string jud[] = {"AC", "WA", "TLE", "RE"};
  int n_jud[] = {0, 0, 0, 0};
  for (int i = 0; i < N; i ++) {
    string S;
    cin >> S;
    for (int j = 0; j < 4; j ++) {
      if (jud[j] == S) {
        n_jud[j] ++;
      }
    }
  }
  for (int i = 0; i < 4; i ++) {
    cout << jud[i] << " x " << n_jud[i] << endl;
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<string, int>P;

vector<P>E[40];
vector<int>G[40];
string d[40][280];
bool b[40];

void dfs(int v) {
	b[v] = true;
	for (int u : G[v]) {
		if (!b[u])dfs(u);
	}
}
int main() {
	string INF(1000, 'z');
	int n, a, s, g;
	while (scanf("%d%d%d%d", &n, &a, &s, &g), n) {
		rep(i, n) {
			E[i].clear(); G[i].clear();
		}
		rep(i, a) {
			int x, y; string c; cin >> x >> y >> c;
			E[x].push_back(P(c, y)); G[y].push_back(x);
		}
		memset(b, 0, sizeof(b)); dfs(g);
		priority_queue<P, vector<P>, greater<P>>que;
		fill(d[0], d[n], INF);
		d[s][0] = ""; que.push(P("", s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (d[p.second][p.first.size()] != p.first)continue;
			if (!b[p.second])continue;
			if (p.second == g) {
				cout << p.first << endl; goto y;
			}
			if (p.first.size() > n * 6) {
				puts("NO"); goto y;
			}
			for (P u : E[p.second]) {
				int t = u.first.size() + p.first.size();
				if (d[u.second][t] > p.first + u.first) {
					d[u.second][t] = p.first + u.first;
					que.push(P(d[u.second][t], u.second));
				}
			}
		}
		puts("NO"); y:;
	}
}

Measured memory_bytes: 4712
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n = reads()[0];

    let ak: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let t = reads();
            (t[0], t[1])
        })
        .collect();

    let g = ak.iter().map(|&(a, k)| g(a, k)).fold(0, |x, y| x ^ y);

    println!("{}", if g == 0 { "Aoki" } else { "Takahashi" });
}

fn g(a: i64, k: i64) -> i64 {
    let mut a = a;

    while a > k && a % k > 0 {
        let d = a / k + 1;
        let n = (a % k + d - 1) / d;
        a -= n * d;
    }

    a / k
}


Measured memory_bytes: 4352
from math import *
while True:
    n = input()
    if n == -1:
        break
    step = 1.0
    x,y,theta = step,0,pi
    for i in xrange(n-1):
        theta -= pi/2
        x += step*cos(theta)
        y += step*sin(theta)
        if x >= 0:
            theta = atan(y/x) - pi
        else:
            theta = atan(y/x)
    print round(x,2),round(y,2)

Measured memory_bytes: 4500
// Created by sz
#include <bits/stdc++.h>
using namespace std;

long long  N,K, height[100005], dp[100005];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    for(int i = 1; i <= N; i++){
        cin>>height[i];
        dp[i] = 1e9;
    }
    
    
    
    dp[1] = 0;
    for(int i = 2; i<= N; i++){
        for(int j = 1; j<=K&&j<i; j++){
            dp[i] = min(dp[i], dp[i-j] + abs(height[i] - height[i - j]));
        }
    }
    cout<<dp[N]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll M,N;
  cin>>M>>N;
  bool checker=false,oneprime=false;
  ll n=N,memo=0,count=0,sqrtN=sqrt(N);
  vector<ll> vec(sqrtN);
  for(ll i=1;i*i<=n;i++){
    ll rock=N;
    while(N%i==0 && N>1 && prime(i)==1){
      N/=i;
      checker=true;
      vec.at(i-1)++;
      if(rock==n && N==1){oneprime=true;}
      if(N==1){break;}
    }
    if(n%i==0 && prime(n/i)==1 && N%(n/i)==0){
      while(N%(n/i)==0 && N>1){
        N/=(n/i);
        checker=true;
        count++;
        memo=n/i;
        break;
      }
    }
  }
  ll ans=1;
  for(ll i=0;i<(ll)(sqrtN);i++){
    if(vec.at(i)>=M){
      for(ll j=0;j<(vec.at(i)/M);j++){
        ans*=(i+1);
      }
    }
  }
  if(count>=M){
    ans*=memo;
  }
  cout<<ans<<endl;
}

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

long long calc(long long s1, long long s2, long long s3) {
  if (s1 > s2 && s1 > s3) {
    return s1 - min(s2, s3);
  } else if (s2 > s1 && s2 > s3) {
    return s2 - min(s1, s3);
  } else {
    return s3 - min(s1, s2);
  }
}
int main() {
  long long h, w;
  cin>>h>>w;
  long long ans = h * w;
  for (long long i=1; i<w; i++) {
    long long s1 = h * i;
    if (i < w - 1) {
      ans = min(calc(s1, (w - i) / 2 * h, (w - i +1) / 2 * h), ans);
    }
    ans = min(calc(s1, h / 2 * (w - i), (h + 1) / 2 * (w - i)), ans);
  }
  for (long long i=1; i<h; i++) {
    long long s1 = w * i;
    if (i < h - 1) {
      ans = min(calc(s1, (h - i) / 2 * w, (h - i +1) / 2 * w), ans);
    }
    ans = min(calc(s1, w / 2 * (h - i), (w + 1) / 2 * (h - i)), ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int N,K,ans=1;
    cin >> N>>K;

    for(int i=0;i<N;i++){
        if(ans<=K){
            ans*=2;
        }else{
            ans += K;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
def f(a, b, c, x, y):
    Min = np.inf
    for use_c in range(max(x, y) * 2 + 1):
        price = use_c * c + max(0, x - use_c // 2) * a + max(0, y - use_c // 2) * b
        if price < Min:
            Min = price
    print(Min)

a, b, c, x, y = map(int, input().split())
f(a, b, c, x, y)


Measured memory_bytes: 12504
N,M = map(int,(input().split()))
H = list(map(int,(input().split())))
line = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int,(input().split()))
    line[a-1].append(b-1)
    line[b-1].append(a-1)

for i in range(N):
    line[i] = set(line[i])

ans = 0
for i in range(N):
    if line[i] == set():
        ans += 1
    else:
        for tower in line[i]:
            if H[i] <= H[tower]:
                break
        else:
            ans += 1

print(ans)

Measured memory_bytes: 116340
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        BitSearch bs = new BitSearch(3);
        
        do {
            long y = s[0] - '0';
            string str = s[0].ToString();

            for(int i=1; i<4; i++) {
                var v = s[i] - '0';
                if(bs[i - 1]) {
                    y += v;
                    str += "+" + v;
                } else {
                    y -= v;
                    str += "-" + v;
                }
            }
            if(y == 7) {
                return str + "=7";
            }
        } while (bs.Next());

        return 0;
    }

    class BitSearch
    {
        private int max;
        private int x;
        public int Length { get; }

        //0~n-1
        public bool this[int i] {
            get {
                var si = Length - i - 1;
                return ((x >> si) & 0x01) == 1;
            }
        }

        public BitSearch(int n) {
            this.Length = n;
            this.max = (int)Math.Pow(2, n) - 1;
            this.x = 0;
        }
        public bool Next() {
            if (x >= max) {
                return false;
            }
            x += 1;
            return true;
        }
        public void Reset() {
            x = 0;
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11092
#include <iostream>


using namespace std;


int main()
{
	int x, y;

	while(1){
		cin >> x >> y;

		if(x == 0 && y == 0)
			break;

		for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++)
				cout << "#";
			cout << endl;
		}
		cout << endl;

	}

	return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end(),greater<int>());
    int ans = 2000000000;
    for(int i = 0; i < n-k+1; i++){
        ans = min(ans,h[i]-h[i+k-1]);
    }
    cout << ans << endl;
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
//ll a[maxn];

//check T

//obs : at most 10
// abcdefghij max

//3628800 = 10!

/*
int myints[] = {1,1,3};

std::sort (myints,myints+3);

std::cout << "The 3! possible permutations with 3 elements:\n";
do {
	std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
} while ( std::next_permutation(myints,myints+3) );

std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
*/

//dfs
int n;

void dfs(vector<char> s, char m)
{
	if(s.size() == n)
	{
		rep(i, 0, n) printf("%c", s[i]);
		printf("\n");
		return;
	}
	for(char c = 'a'; c <= m+1; c++)
	{
		char nxtm = max(m, c);
		s.pb(c);
		dfs(s, nxtm);
		s.pop_back();
	}
}

void solve()
{
	scanf("%d", &n);
	vector<char> s; s.pb('a');
	dfs(s, 'a'); //
  return;
}


signed main()
{
  //fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
 
using namespace std;
 
int main (void)
{
  int n;
  
  cin >> n;
  
  int stairs[100000];

  for (int i = 0; i < n; i++) cin >> stairs[i];

  for (int i = n-2; i >= 0; i--) {
    if (stairs[i] > stairs[i+1]) stairs[i] -= 1;
    if (stairs[i] > stairs[i+1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}
  

Measured memory_bytes: 640
while True:
    n = int(input())
    if n == 0:
        break
    else:
        s = list(map(int, input().split()))
        m = 0
        for i in range(n):
            m += s[i]
        m = m/n

        a2 = 0
        for j in range(n):
            a2 += (s[j]-m)**2
        a2 = a2/n

        print(a2**0.5)


Measured memory_bytes: 5668
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    while(true){
        int n=sc.nextInt();
        if(n==0) break;
        int i;
        int[] scores=new int[n];
        for(i=0;i<n;i++){
            scores[i]=sc.nextInt();
        }
        Arrays.sort(scores);
        int sum=0;
        int ave;
        for(i=1;i<n-1;i++){
            sum+=scores[i];
        }
        ave=sum/(n-2);
        System.out.printf("%d\n",ave);
    }
}
}


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

int main(){
	int n , m , ans = 0;
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++){
		int t = 0 ;
		for(int j = 0 ; j < m ; j++){
			int a;
			cin >> a;
			t += a;
		}
		ans = max(ans,t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    vector<int> cnt(N);
    for(int i = N;i >= 1;i--){
        int sum = 0;
        rep(j,1,N+1){
            int x = i * j - 1;
            if(x >= N)break;
            sum += cnt[x];
        }
        if(sum % 2 == V[i-1])continue;
        cnt[i-1]++;
    }
    //rep(i,0,N)cout << cnt[i] << " ";cout << endl;
    int sum = 0;
    rep(i,0,N)sum += cnt[i];
    cout << sum << endl;
    rep(i,0,N){
        rep(j,0,cnt[i])cout << i+1 << " ";
    }cout << endl;
}

Measured memory_bytes: 2432
//abc158_a.cpp
//Sat Mar  7 20:43:06 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	if (s=="AAA" || s=="BBB"){
		cout << "No" << endl;
	}else {
		cout << "Yes" << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

void fnMaximumProfit(const vector<int>& cnrvnValue, int& rnMinval, int& rnMaxProfit)
{
  for (int i = 1; i < cnrvnValue.size(); i++)
  {
    rnMinval = min(rnMinval, cnrvnValue[i - 1]);
    int nMaxPft = cnrvnValue[i] - rnMinval; 
    rnMaxProfit = max(rnMaxProfit, nMaxPft);
  }
}

int main()
{
  vector<int> vnVal;
  int nMaxSiz;
  
  cin >> nMaxSiz;
  for (int i = 0; i < nMaxSiz; i++)
  {
    int nVal;
    cin >> nVal;
    vnVal.push_back(nVal);
  }

  int nMinVal = vnVal[0];
  int nMaxPft = -1000000000;
  fnMaximumProfit(vnVal, nMinVal, nMaxPft);
  cout << nMaxPft << endl;

  return 0;
}

Measured memory_bytes: 3872
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
const int maxn=1e5+5;
vector<ll>adj[maxn];
bool visited[maxn];
ll indegree[maxn];
ll dist[maxn];
void dfs(ll x)
{
	visited[x]=true;
	for(auto u:adj[x])
	{
		indegree[u]--;
		dist[u]=max(dist[u],dist[x]+1);
		if(indegree[u]==0)
		dfs(u);
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		adj[x].pb(y);
		indegree[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(!visited[i] && !indegree[i])
		dfs(i);
	}
	ll res=0;
	for(int i=1;i<=n;i++)
	res=max(res,dist[i]);
	cout<<res;

}


Measured memory_bytes: 10624
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
vector<int>adj[100005];
bool vis[100005][2];
int dp[100005][2];
int solve(int s,int p,int par)
{
	if(dp[s][p]!=-1)
		return dp[s][p];
	vis[s][p]=true;
	int ans=1;
	for(int i=0;i<adj[s].size();i++)
	{
		int x=adj[s][i];
		if(x==par)
			continue;
			if(p==0)
				ans=(ans*(solve(x,0,s)+solve(x,1,s)))%mod;
			else
				ans=(ans*solve(x,0,s))%mod;
		
	}
	dp[s][p]=ans;
	return ans;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   int n;
   cin>>n;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n-1;i++)
   {
   	int a,b;
   	cin>>a>>b;
   	adj[a-1].pb(b-1);
   	adj[b-1].pb(a-1);
   }
   int ans=(solve(0,0,0)+solve(0,1,0))%mod;
   cout<<ans<<endl;
}        


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  int a[100001];
  cin >> n;
  int mx = 0;
  rep(i, 0, n) {
    cin >> a[i];
    mx = max(a[i], mx);
  }

  sort(a, a + n);
  int s = 1145141919;
  int si = 0;
  rep(i, 0, n) {
    if(a[i] == mx) continue;
    if(s >= abs(a[i] - mx / 2)) {
      s = abs(a[i] - mx / 2);
      si = i;
    }
  }

  cout << mx << " " << a[si] << endl;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < n; i++)

typedef long long ll;

int main() {
    string s,t;
    cin>>s>>t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

ll numct[210000];
ll k[210000];
ll cnb[210000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin>>n;

	cout<<n/2+n%2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for(int i=0; i<H; i++) cin >> s[i];

    vector<bool> r(H, false);
    vector<bool> c(W, false);
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(s[i][j]=='#') {
                r[i]=true;
                c[j]=true;
            } 
        }
    }

    for(int i=0; i<H; i++) {
        if(r[i]) {
            for(int j=0; j<W; j++) if(c[j]) cout << s[i][j];
            cout << endl;
        }
    }

    return 0;
}

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

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String word = input.readLine();
        int start = -1, end = -1;
        for (int i = 0; i < word.length(); i++) {
            if (word.charAt(i) == 'A'){
                start = i;
                break;
            }
        }

        for (int i = word.length() - 1; i > 0; i--) {
            if (word.charAt(i) == 'Z'){
                end = i;
                break;
            }
        }

        System.out.println(end - start + 1);
    }
}


Measured memory_bytes: 27476
#include<stdio.h>
#include<math.h>
#define MAX 100000

int main()
{
        int N;
        int a[MAX];
        int i;
        int cnt_4;//4の倍数の数
        int cnt_2;//2の倍数の数（ただし、４の倍数は含まない）
        int thresh;

        scanf("%d", &N);

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

        cnt_4 = 0;
        cnt_2 = 0;
        for(i=0; i<N; i++)
        {
                if(a[i]%4==0)
                {
                        cnt_4++;
                }
                else if(a[i]%2==0)
                {
                        cnt_2++;
                }
        }

        thresh = floor(N/2);

        if(cnt_4 >= thresh)
        {
                printf("Yes\n");
        }
        else if(cnt_2/2+cnt_4 >= thresh)
        {
                printf("Yes\n");
        }
        else
        {
                printf("No\n");
        }

        //printf("thresh: %d\ncnt_4: %d\ncnt_2: %d\n", thresh, cnt_4, cnt_2);

        return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

long long int MOD = 1e9+7;

int main(){
  
  // read problem
  std::string K_string;
  long long int D, digits;
  std::cin >> K_string >> D;
  digits = K_string.length();
  
  std::vector<long long int> K;
  for(long long int i = 0; i < digits; i++){
    K.push_back(K_string[i] - '0');
  }
  
  std::cerr << "K:" << std::endl;
  for(long long int i = 0; i < digits; i++){
    std::cerr << K[i] << " ";
  }std::cerr << std::endl;
  
  // solve problem
  std::vector<std::vector<long long int> > dp_table(digits);
  for(long long int i = 0; i < digits; i++){
    for(long long int j = 0; j < D+1; j++){
      dp_table[i].push_back(0);
    }
  }
  
  // initialize dp_table
  for(long long int i = 0; i < K[0]; i++){
    dp_table[0][(i+D)%D]++;
  }
  dp_table[0][D] = (K[0]+D)%D;
  
  // fill dp_table
  for(long long int i = 1; i < digits; i++){
    // normal cases
    for(long long int j = 0; j < D; j++){
      for(long long int k = 0; k < 10; k++){
        dp_table[i][j] += dp_table[i-1][(j-k+10*D)%D];
        dp_table[i][j] = (dp_table[i][j]+MOD)%MOD;
      }
    }
    // exception cases
    dp_table[i][D] = (dp_table[i-1][D] + K[i]+D)%D;
    for(long long int j = 0; j < K[i]; j++){
      dp_table[i][(dp_table[i-1][D]+j+D)%D]++;
      dp_table[i][(dp_table[i-1][D]+j+D)%D] %= MOD;
    }
  }
  
  /*std::cerr << "dp_table:" << std::endl;
  for(long long int i = 0; i < digits; i++){
    for(long long int j = 0; j <= D; j++){
      std::cerr << dp_table[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  long long int ans = dp_table[digits-1][0]-1;
  if(dp_table[digits-1][D]==0){
    ans++;
  }
  ans = (ans+MOD)%MOD;
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 10752
N = int(input())
for ai in range(N//4,3500):
    for bi in range(N//4,3500):
        try:
            ci = N*ai*bi/(4*ai*bi-N*ai-N*bi)
        except:
            continue
        if ci == int(ci) and ci > 0:
            print(ai,bi,int(ci))
            exit()


Measured memory_bytes: 9120
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
  long a[200001],i,n,k,sum=0,sma=0,lar=0,ans=0;
  scanf("%ld",&n);
  for(i=0; i<n; i++){
    scanf("%ld",&a[i]);
    sum+=a[i];
  }
  for(i=0; i<n; i++){
    lar+=a[i];
    k=a[i];
    if(lar>sum-lar){
      sma=lar-k;
      break;
    }
  }
  sma=labs(sum-sma*2);
  lar=labs(sum-lar*2);
  if(sma>lar){
    ans=lar;
  }
  else{
    ans=sma;
  }
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 1664
n = int(input())
numList=[i+1 for i in range(n)]
strList=[]
pointList=[]
for i in range(n):
  s,p = input().split()
  strList.append(s)
  pointList.append(-int(p))
lists = zip(strList,pointList,numList)
q=sorted(lists)
c,a,b = zip(*q)
for x in b:
  print(int(x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL long long

const int N = 2e5 + 5;
const int M = 2e5 + 5;

int n, cnt, first[N], dep[N] = { -1 }, ans[N], tot[2];

std::queue <int> q[3];

struct EDGE {
	int to, _next;
} e[M << 1];

void Add_Edge(int u, int v) {
	e[cnt].to = v;
	e[cnt]._next = first[u];
	first[u] = cnt++;
}

void dfs(int x, int p) {
	dep[x] = dep[p] + 1;
	for (int i = first[x], y = e[i].to; ~i; i = e[i]._next, y = e[i].to)
		if (y != p) dfs(y, x);
}

int main() {
	std::cin >> n;
	memset(first, -1, sizeof(first));
	for (int i = 1; i <= n - 1; ++i) {
		int u, v;
		std::cin >> u >> v;
		Add_Edge(u, v);
		Add_Edge(v, u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++i)
		q[i % 3].push(i), ++tot[dep[i] % 2];
	if (std::min(tot[0], tot[1]) <= n / 3) {
		int k = tot[0] > tot[1];
		for (int i = 1; i <= n; ++i)
			if (dep[i] % 2 == k) {
				ans[i] = q[0].front();
				q[0].pop();
				continue;
			}
		for (int i = 1; i <= n; ++i)
			if (dep[i] % 2 != k) {
				if (!q[0].empty()) {
					ans[i] = q[0].front();
					q[0].pop();
					continue;
				}
				if (!q[1].empty()) {
					ans[i] = q[1].front();
					q[1].pop();
					continue;
				}
				if (!q[2].empty()) {
					ans[i] = q[2].front();
					q[2].pop();
					continue;
				}
			}
	} else
		for (int i = 1; i <= n; ++i) {
			if(dep[i] % 2 == 1) {
				if(q[2].empty()) {
					ans[i] = q[0].front();
					q[0].pop();
				}
				else {
					ans[i] = q[2].front();
					q[2].pop();
				}
			}
			else {
				if(q[1].empty()) {
					ans[i] = q[0].front();
					q[0].pop();
				}
				else {
					ans[i] = q[1].front();
					q[1].pop();
				}
			}
		}
	for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
	return 0;
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    //cout << sum << endl;
    int cnt=0;
    for(int i=0; i<n; i++){
        //cout << (double)a[i]/sum << (double)1/(4*m) << endl;
        if((double)a[i]/sum >= (double)1/(4*m)){
            cnt++;
        }
    }
    //cout << cnt << endl;
    if(cnt >= m ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
typedef pair<ll,ll>LLP;
const int MAXN=2e5+20;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double RATE=0.995;
const double eps=1e-6;
std::mt19937 rnd(time(0));
char str[MAXN];
signed main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",str);
    int cnt=1;
    for(int i=1;i<n;++i)
    {
        if(str[i]!=str[i-1])
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;

int main()
{
	while(scanf("%lld",&N),N != -1){
		double x = N / 2.0;
		do{
			x = x - (x * x * x - N) / (3 * x * x);
		}while(abs(x * x * x - N) >= 0.00001 * N);
		printf("%.10f\n",x);
	}

	return 0;
}

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

signed main(void){
    int n,k; cin >>n >>k;
    int ans = 0;
    for(int i=k+1;i<=n;i++){
        ans += (n/i)*(i-k);
        if (k!=0){
            ans += max((int)0,(n%i) -k+1);
        }else{
            ans += (n%i);
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

/*
[x^Ny^K]  \sum_{t=0}^\infty [(M-1)(x+yx^2+y^2x^3+...)]^t
[x^Ny^K]  1/[1- (M-1)(x+yx^2+y^2x^3+...)]
[x^Ny^K]  1/[1- (M-1)x/(1-yx)]
[x^Ny^K]  (1-yx)/[1-yx - (M-1)x]
[x^Ny^K]  (1-yx) \sum_{i=0}^\infty (yx+(M-1)x)^i

[y^K]  (y+(M-1))^N - y (y+(M-1))^{N-1}
\binom{N}{K} (M-1)^{N-K} - \binom{N-1}{K-1} (M-1)^{N-K}
(M-1)^{N-K} \binom{N-1}{K}

\sum_{i=0}^K (M-1)^{N-i} \binom{N-1}{i}
M\sum_{i=0}^K (M-1)^{N-i-1} \binom{N-1}{i}
*/

int n, m, k;

constexpr int mod = 998244353;

using u64 = unsigned long long int;

int inv[200001];

int modpow(int a, int n){
  int r = 1;
  for(; n; n >>= 1){
    if(n & 1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}

int main(){
  std::cin >> n >> m >> k;

  if(k == n - 1){
    std::cout << modpow(m, n) << std::endl;
    return 0;
  }

  u64 ans = 0;
  u64 binom = 1;
  u64 mm = modpow(m-1, n-1);
  const u64 im = modpow(m-1, mod-2);
  inv[1] = 1;
  for(int i = 0; i <= k; i++){
    ans += mm * binom % mod;
    mm = mm * im % mod;
    binom = binom * (n-1-i) % mod * inv[i+1] % mod;
    inv[i+2] = mod - (u64) inv[mod % (i+2)] * (mod / (i+2)) % mod;
  }
  ans %= mod;
  ans = ans * m % mod;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4156
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

sum=0
for i in range(n):
    sum+=b[i]
#print(sum)
for j in range(n-1):
        if a[j+1]==a[j]+1:
            #print(a[j])
            #print(c[a[j]-1])
            sum+=c[a[j]-1]
print(sum)

Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}




int main() {

  long n, w;
  string a, b, c;
  string s[3];

  cin >> n ;
  cin >> a ;
  cin >> b ;
  cin >> c ;


  vector<long> count(3,0);
  // for(int i=0;i<n;i++){
  //   if (a[i] != b[i] || a[i] != c[i]){
  //     count[0]++;
  //   }
  // }
  // for(int i=0;i<n;i++){
  //   if (b[i] != a[i] || b[i] != c[i]){
  //     count[1]++;
  //   }
  // }
  // for(int i=0;i<n;i++){
  //   if (c[i] != b[i] || c[i] != a[i]){
  //     count[2]++;
  //   }
  // }





  // long ans = min(min(count[0],count[1]),count[2]);
  long ans = 0;
  for(int i=0;i<n;i++){
    if (c[i] != b[i] && c[i] != a[i] && b[i] != a[i]){
      ans+=2;
      continue;
    }
    if (a[i] !=c[i] || a[i] !=b[i] || c[i] !=b[i]){
      ans++;
      continue;
    }
  }

  cout << ans;



}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long x;
int main()
{
    long A=0,B=0;
    for(long i=1;i<=3;i++)
    {
        cin>>x;
        if(x==5) A++;
        else B++;
    }
    if(A==2 && B==1) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
N = int(input())
D = [list(map(int,input().split())) for i in range(N)]

for i in range(N-2):
    if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
        print('Yes')
        break
else:
    print("No")

Measured memory_bytes: 9140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>

#define rep(i, n) for(int i=0;i<n;i++)
#define IOS() ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define INT_MINI -987654321
#define INT_MAXI 987654321
#define ABS(X) ((X) < 0 ? -(X) : (X))


using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

long double a, b, c;


void input() {

    cin >> a >> b >> c;
}

void process() {

    long double aa, bb, cc;
    long double eps = 1.0E-14;
    aa = sqrt(a);
    bb = sqrt(b);
    cc = sqrt(c);

    if(aa + bb + eps < cc) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

int main() {

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

    input();
    process();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define MAX_n 50001
using namespace std;
bool is_prime[51000];

void sieve() {

  for(int i=0;i<51000;i++) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for(int i=2;i<51000;i++) {
    if(is_prime[i]) {
      for(int j=2*i;j<51000;j+=i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  int n;
  sieve();
  while(cin >> n) {
    for(int i=1;i<n;i++) {
      if(is_prime[n-i]) {
        cout << n-i << " ";
        break;
      }
    }

    for(int i=1;i<n;i++) {
      if(is_prime[n+i]) {
        cout << n+i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>
#include <queue>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> A(1 + H + 1,
                                   std::vector<char>(1 + W + 1, '@'));
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      std::cin >> A[i][j];

  // Main
  std::vector<std::vector<int>> dp(1 + H + 1,
                                   std::vector<int>(1 + W + 1, IINF));

  std::vector<std::vector<bool>> finished(1 + H + 1,
                                          std::vector<bool>(1 + W + 1, false));

  std::queue<std::tuple<int, int>> que;
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      if (A[i][j] == '#') {
        finished[i][j] = true;
        dp[i][j] = 0;
        que.push(std::make_tuple(i, j));
      }

  while (not que.empty()) {
    int i, j;
    std::tie(i, j) = que.front();
    que.pop();

    if (i >= 2 and not finished[i - 1][j]) {
      finished[i - 1][j] = true;
      dp[i - 1][j] = dp[i][j] + 1;
      que.push(std::make_tuple(i - 1, j));
    }

    if (i <= H - 1 and not finished[i + 1][j]) {
      finished[i + 1][j] = true;
      dp[i + 1][j] = dp[i][j] + 1;
      que.push(std::make_tuple(i + 1, j));
    }

    if (j >= 2 and not finished[i][j - 1]) {
      finished[i][j - 1] = true;
      dp[i][j - 1] = dp[i][j] + 1;
      que.push(std::make_tuple(i, j - 1));
    }

    if (j <= W - 1 and not finished[i][j + 1]) {
      finished[i][j + 1] = true;
      dp[i][j + 1] = dp[i][j] + 1;
      que.push(std::make_tuple(i, j + 1));
    }
  }

  // Output
  int res = 0;
  for (int i = 1; i <= H; ++i)
    for (int j = 1; j <= W; ++j)
      chmax(res, dp[i][j]);
  std::cout << res << std::endl;


  return 0;
}


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

typedef long long ll;
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n;	cin >> n;
	string c;	cin >> c;
	ll l, r;
	ll cnt = 0;

	l = 0;
	r = c.length() - 1;
	while( l < r ){
		while( c[l] == 'R' ){
			l++;
		}
		while( c[r] == 'W' ){
			r--;
		}

		if( l < r ){
			cnt++;
			l++;
			r--;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3748
#include <iostream>
using namespace std;
int main()
{
  long long N, Y;
  cin >> N >> Y;
  int x = -1, y = -1, z = -1;
  for (int a = 0; a <= N; ++a)
  {
    for (int b = 0; b <= N - a; ++b)
    {
      for (int c = 0; c <= N - a - b; c++)
      {
          long long sum = 10000 * a + 5000 * b + 1000 * c;
        if ((a+b+c)==N&&sum == Y)
          x = a, y = b, z = c;
      }
    }
  }
  cout << x << " " << y << " " << z << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,k;
	string s; cin>>n>>s>>k; k--;

	rep(i,n) if(s[i]!=s[k]) s[i]='*';
	cout<<s<<'\n';

	return 0;
}


Measured memory_bytes: 3476
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)


map<string, int> mp;
#define ll long long



int main() {
    int n, k;
    cin >> n >> k;
    int c = 0;
    rep(i,n) {
        int x;
        cin >> x;
        c += min(x, k - x);
    }
    cout << c*2 << endl;
    return 0;
}

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

namespace ABC113_C
{
    public class Program

    {

        public  class City
        {
            public int index { get; set; }
            public int year { get; set; } 
            public int p { get; set; }
            public int BirthOrder { get; set; }

            public City(int i,int year,int p)
            {
                this.index = i;
                this.year = year;
                this.p = p;
                this.BirthOrder = 0;
            }
        }

        public static void Main(string[] args)
        {
            int[] line = ReadIntAr();
            int n = line[0];
            int m = line[1];

            List<City> cities = new List<City>();
            int[] tmp;
            for (int i = 0 ; i < m ; i++)
            {
                tmp = ReadIntAr();
                cities.Add(new City(i,tmp[1],tmp[0]));
            }

            var tmp2 = cities.OrderBy(x => x.p).ThenBy(x => x.year);

            int k = 1;
            int beforeP = 0 ;
            foreach (var item in tmp2)
            {
                if (beforeP != item.p) k = 1;
                item.BirthOrder = k;
                beforeP = item.p;
                k++;
            }

            var res = cities.OrderBy(x => x.index).ToArray();
            for (int i = 0 ; i < m ; i++)
            {
                Console.WriteLine(res[i].p.ToString("000000") + res[i].BirthOrder.ToString("000000"));
            }
            
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}


Measured memory_bytes: 31956
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void A()
{
  string S;
  cin >> S;
  
  if( S[2] == S[3] && S[4] == S[5] )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void B()
{
  int X;
  cin >> X;
  
  int five_hundred = X / 500;
  int five = (X - five_hundred * 500) / 5;
  
  cout << five_hundred * 1000 + five * 5 << endl;
}

void C()
{
  int K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  for( int &i : A )
    cin >> i;
  
  vector<int> distances(N);
  for( int i = 0; i < N; ++i )
    if( i == N-1 )
      distances[i] = abs(K - A[i] + A[0]);
    else
      distances[i] = abs(A[i] - A[i+1]);
  
  int max_distance = distances[0];
  for( int i = 0; i < N; ++i ){    
    if( max_distance < distances[i] )
      max_distance = distances[i];
  }
  
  cout << K - max_distance << endl;
}

int main()
{
  //A();
  //B();
  C();
  
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Long[] array = new Long[n];
        Long[] arrayb = new Long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
            arrayb[i] = array[i];
        }
        Arrays.sort(array);
        for (int i = 0; i < n; i++) {
            if (arrayb[i] <= array[(n / 2) - 1]) {
                System.out.println(array[n / 2]);
            } else {
                System.out.println(array[(n / 2) - 1]);
            }
        }
    }
}


Measured memory_bytes: 98924