akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"0\n"; return 0;}
#define yup {cout<<"YES\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {

    get2(n,k);
    vv<db> A(n);
    rep(i,n) {
        get(a);
        A[i] = (a+1)/2.0;
    }

    db sum = 0, maxi = 0;
    rep(i,k) sum += A[i];
    maxi = sum;

    rep2(i,k,n)  { sum += A[i]-A[i-k]; maxi = max(maxi,sum); }

    printf("%.10Lf\n", maxi);
    return 0;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String input = br.readLine();

			String[] tmpArray = input.split(" ");
			int n = Integer.parseInt(tmpArray[0]);
			int m = Integer.parseInt(tmpArray[1]);

			if(n == 0 && m == 0){
				break;
			}

			Problem problems[] = new Problem[n];

			for(int i = 0; i < n; i++){
				tmpArray = br.readLine().split(" ");

				problems[i] = new Problem(Integer.parseInt(tmpArray[0]), Integer.parseInt(tmpArray[1]));
			}

			Arrays.sort(problems);

			boolean selected[] = new boolean[m + 1];

			int result = 0;

			for(int i = 0; i < n; i++){
				if(!selected[problems[i].difficulty]){
					selected[problems[i].difficulty] = true;
					result += problems[i].recommended;
				}
			}

			System.out.println(result);
		}
	}

}

class Problem implements Comparable<Problem>{
	int difficulty;
	int recommended;

	Problem (int diff, int rec){
		difficulty = diff;
		recommended = rec;
	}

	@Override
	public int compareTo(Problem p1) {
		return p1.recommended - this.recommended;
	}
}


Measured memory_bytes: 26908
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  VI A(M);
  REP(i, M) cin >> A.at(i);
  SORTG(A);

  VI dp(N+1, -INF);
  VI num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  dp.at(0) = 0;

  REP2(i, 1, N+1)
  {
    REPx(x, A)
    {
      int tmp;
      if (i - num.at(x) < 0) continue;
      else tmp = dp.at(i-num.at(x)) + 1;
      dp.at(i) = max(tmp, dp.at(i));
    }
  }
  string ans = "";
  const int digit = dp.at(N);
  REP(i, digit)
  {
    REPx(x, A)
    {
      int idx = N - num.at(x);
      if (idx < 0) continue;
      if (i == digit-1 && idx != 0) continue;
      if (dp.at(idx) == dp.at(N) - 1)
      {
        ans += to_string(x);
        N -= num.at(x);
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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

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

 int ss = t.length() ;
unsigned int sx=  s.length()  - ss;

std::vector<string>v ;
for (int i =  0 ; i <= sx;i++ )
{
    string o =s.substr (i ,ss);
    //cout << o << endl;
    if (o  == t)
    {
        cout << 0 ;
        return 0;
    }
    v.push_back (o);
}
int mx  = -1, c= 0;
for (int i  = 0 ; i <v.size() ; i++){
    c=0;
for (int j  = 0 ; j <ss ; j++)
{
    if (t[j] == v[i][j])
    c++;
}
mx  = max (mx , c);
}
cout << abs (ss  - mx);
}


Measured memory_bytes: 3748
#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first - r.first, l.second - r.second); }


template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
const lint MOD = 1e9 + 7;
typedef modint<MOD> ModInt;
#pragma endregion
set<int64_t> st;
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
			st.insert(i);
		}
	}
	if (n != 1) {
		ret[n] = 1;
		st.insert(n);
	}
	return ret;
}

ModInt val[10000];
map<int64_t, int> mps[10000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint N, A;
	cin >> N;
	REP(i, N) {
		cin >> A;
		val[i].a = A;
	}
	mps[0] = prime_factor(val[0].a);
	REP(i, N - 1) {
		mps[i+1] = prime_factor(val[i+1].a);
		for (auto itr : mps[i + 1]) {
			if (mps[0].find(itr.first) == mps[0].end()) mps[0][itr.first] = itr.second;
			else mps[0][itr.first] = max(mps[0][itr.first], itr.second);
		}
	}
	ModInt lcm = 1;
	for (auto itr : mps[0]) {
		lcm *= pow(itr.first, itr.second);
	}
	ModInt ans = 0;
	REP(i, N) {
		ans += lcm / val[i];
	}
	cout << ans.a;
}


Measured memory_bytes: 3968
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
int i=1;
int a=0;
int b=0;
while(i<=s1.size()+s2.size())
{
	if(i%2)
		cout<<s1[a],a++;
	else
		cout<<s2[b],b++;
	i++;
}
return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
import bisect


n = int(input())
info = []
for i in range(n):
    x, y, u = input().split()
    info.append((int(x), int(y), u))
INF = 10 ** 18
ans = INF


info = sorted(info, key=itemgetter(0))
u = {}
d = {}
l = {}
r = {}
for x, y, dire in info:
    xy = x + y
    if dire == "U":
        if xy not in u:
            u[xy] = []
        u[xy].append(x)
    if dire == "D":
        if xy not in d:
            d[xy] = []
        d[xy].append(x)
    if dire == "L":
        if xy not in l:
            l[xy] = []
        l[xy].append(x)
    if dire == "R":
        if xy not in r:
            r[xy] = []
        r[xy].append(x)

for xy in u:
    if xy not in r:
        continue
    for x in u[xy]:
        ind = bisect.bisect_left(r[xy], x) - 1
        if ind < 0:
            continue
        ans = min((x - r[xy][ind]) * 10, ans)

for xy in l:
    if xy not in d:
        continue
    for x in l[xy]:
        ind = bisect.bisect_left(d[xy], x) - 1
        if ind < 0:
            continue
        ans = min((x - d[xy][ind]) * 10, ans)

info = sorted(info, key=itemgetter(0))
u = {}
d = {}
l = {}
r = {}
for x, y, dire in info:
    xy = x - y
    if dire == "U":
        if xy not in u:
            u[xy] = []
        u[xy].append(x)
    if dire == "D":
        if xy not in d:
            d[xy] = []
        d[xy].append(x)
    if dire == "L":
        if xy not in l:
            l[xy] = []
        l[xy].append(x)
    if dire == "R":
        if xy not in r:
            r[xy] = []
        r[xy].append(x)

for xy in d:
    if xy not in r:
        continue
    for x in d[xy]:
        ind = bisect.bisect_left(r[xy], x) - 1
        if ind < 0:
            continue
        ans = min((x - r[xy][ind]) * 10, ans)

for xy in l:
    if xy not in u:
        continue
    for x in l[xy]:
        ind = bisect.bisect_left(u[xy], x) - 1
        if ind < 0:
            continue
        ans = min((x - u[xy][ind]) * 10, ans)

l = {}
r = {}
for x, y, dire in info:
    if dire == "L":
        if y not in l:
            l[y] = []
        l[y].append(x)
    if dire == "R":
        if y not in r:
            r[y] = []
        r[y].append(x)

for y in l:
    if y not in r:
        continue
    for x in l[y]:
        ind = bisect.bisect_left(r[y], x) - 1
        if ind < 0:
            continue
        ans = min((x - r[y][ind]) * 5, ans)

info = sorted(info, key=itemgetter(1))
u = {}
d = {}
for x, y, dire in info:
    if dire == "U":
        if x not in u:
            u[x] = []
        u[x].append(y)
    if dire == "D":
        if x not in d:
            d[x] = []
        d[x].append(y)

for x in d:
    if x not in u:
        continue
    for y in d[x]:
        ind = bisect.bisect_left(u[x], y) - 1
        if ind < 0:
            continue
        ans = min((y - u[x][ind]) * 5, ans)

if ans == INF:
    print("SAFE")
else:
    print(ans)

Measured memory_bytes: 237212
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] n = SpIntRead(' ');
        int cost = 0;
        Array.Sort(n);
        Console.WriteLine(Math.Abs(n[2] - n[1]) + Math.Abs(n[1] - n[0]));
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }

}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N, M, a;
  vector<bool> ok(1000000, true);
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    cin >> a;
    ok[a] = false;
  }

  vector<ll> data(N + 10, 0);
  data[0] = 1;
  for(int i = 1; i <= N; i++) {
    if(0 <= i - 1) {
      if(ok[i - 1]) data[i] = (data[i] + data[i - 1]) % mod;
    }
    if(0 <= i - 2) {
      if(ok[i - 2]) data[i] = (data[i] + data[i - 2]) % mod;
    }
  }
  cout << data[N] << endl;
  return 0;
}


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

typedef long long ll;
const int NMAX = 1e6 + 10;
const int MOD = 1e9 + 7;
int fac[NMAX];
int main(int argc, char const *argv[])
{
	int n , a;
	int all_gcd;
	bool flag = true;
	scanf("%d",&n);
	for(register int i = 1;i <= n;i++)
	{
		scanf("%d",&a);
		if(i == 1)	all_gcd = a;
		else all_gcd = __gcd(all_gcd , a);
		for(register int i = 2 ; i * i <= a;i++)
		{
			if(a % i == 0 && fac[i])	flag = false;
			while(a % i == 0)
			{
				fac[i] = 1;
				a /= i;
			}
		}
		if(a != 1)
		{
			if(fac[a])	flag = false;
			fac[a] = 1;
		}
	}
	if(flag)
		puts("pairwise coprime");
	else if(all_gcd == 1)
		puts("setwise coprime");
	else
		puts("not coprime");
	return 0;
}

Measured memory_bytes: 7520
#include <stdio.h>
#include <string.h>
void charRot(char *, int);

int main(void)
{
    int Tlength = -1, i;
    char S[101], T[101];

    scanf("%s %s", S, T);

    while (T[++Tlength] != '\0')
        ;

    for (i = 0; i < Tlength; i++)
    {
        if (strcmp(S, T) == 0)
        {
            printf("Yes\n");
            return 0;
        }
        charRot(T, Tlength);
    }
    printf("No\n");
    return 0;
}

void charRot(char *enT, int length)
{
    char temp = enT[length - 1];
    int i;
    for (i = length - 1; i > 0; i--)
    {
        enT[i] = enT[i - 1];
    }
    enT[0] = temp;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

const int maxn = 505;
ll a[maxn][maxn];
int n;

const int maxm = 1e4 + 5;
bool vis[maxm];

map<int, int> zhu, fu;

ll gcd(ll x, ll y){
    return y == 0 ? x : gcd(y, x % y);
}

ll lcm(ll x, ll y){
    return x / gcd(x, y) * y;
}

void solve(){
    memset(vis, 0, sizeof(vis));
    vector<int> prime;
    vis[1] = 1;
    for(int i = 2;i < maxm;i++){
        if(!vis[i]){
            prime.push_back(i);
            for(int j = 2 * i;j < maxm;j += i){
                vis[j] = 1;
            }
        }
    }
    int front = 0, rear = n - 1;
    for(int i = 2;i <= 2 * n;i += 2){
        int k = i / 2;
        if(k & 1){
            zhu[i] = prime[front++];
        }else{
            zhu[i] = prime[rear--];
        }
    }
    int k;
    if(n & 1)
        k = n;
    else
        k = n - 1;
    front = n, rear = n + k - 1;
    for(int i = 1 - k, odd = 1;i <= k - 1;i += 2, odd++){
        if(odd & 1){
            fu[i] = prime[front++];
        }else{
            fu[i] = prime[rear--];
        }
    }
    for(int i = 1;i <= n;i++){
        int st;
        if(i & 1){
            st = 1;
        }else{
            st = 2;
        }
        for(int j = st;j <= n;j += 2){
            int id1 = zhu[i + j];
            int id2 = fu[i - j]; 
            a[i][j] = 1LL * id1 * id2;
        }
    }
    for(int i = 1;i <= n;i++){
        int st;
        if(i & 1){
            st = 2;
        }else{
            st = 1;
        }
        for(int j = st;j <= n;j += 2){
            a[i][j] = 1;
            if(j > 1){
                a[i][j] = lcm(a[i][j], a[i][j - 1]);
            }
            if(j < n){
                a[i][j] = lcm(a[i][j], a[i][j + 1]);
            }
            if(i > 1){
                a[i][j] = lcm(a[i][j], a[i - 1][j]);
            }
            if(i < n){
                a[i][j] = lcm(a[i][j], a[i + 1][j]);
            }
            a[i][j]++;
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            cout << a[i][j] << ((j == n) ? '\n' : ' ');
        }
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    if(n == 2){
        cout << 4 << " " << 7 << endl;
        cout << 23 << " " << 10 << endl;
        return 0;
    }
    solve();
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int a, b; cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a<=12 && 6<=a) cout << b/2 << endl;
    else cout << 0 << endl;
}

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

int main(){
    string s; cin >> s;
    vector<int> a(3,0);
    for(int i=0; i<s.length(); i++){
        a[s.at(i)-'a']++;
    }
    if(abs(a[0]-a[1])<=1 && abs(a[1]-a[2])<=1 && abs(a[0]-a[2])<=1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;

}

Measured memory_bytes: 3704
// Try Educational DP Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	macro_rules! get {
		($t:ty) => (get().parse::<$t>().unwrap());
		() => (get!(usize));
	}
	let n = get!();
	let m = get!();
	
	let mut tree = vec![vec![]; n];
	let mut refs = vec![0_i64; n];
	for _ in 0..m {
		let x = get!()-1;
		let y = get!()-1;
		refs[y] += 1;
		tree[x].push(y);
	}
	let mut ps = vec![];
	for i in 0..refs.len() {
		if refs[i] == 0 {
			ps.push(i);
		}
	}
	let mut dp = vec![0; n];
	while let Some(x) = ps.pop() {
		for &y in tree[x].iter() {
			dp[y] = std::cmp::max(dp[y], dp[x]+1);
			refs[y] -= 1;
			if refs[y] == 0 {
				ps.push(y);
			}
		}
	}
	let ans = dp.iter().max().unwrap();
	println!("{}", ans);
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a<b) ans += b*2-1;
    else if (a>b) ans += a*2-1;
    else ans += a+b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long n, x, a[2005], dp[2005][2005], sum, ans = inf;
int main() {
  scanf("%lld%lld", &n, &x);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) {
    dp[i][0] = a[i];
    for (int j = 1; j < n; j++) {
      int k = i - j;
      if (k <= 0) k += n;
      dp[i][j] = min(dp[i][j - 1], a[k]);
    }
  }
  for (int i = 0; i < n; i++) {
    sum = x * i;
    for (int j = 1; j <= n; j++) sum += dp[j][i];
    ans = min(ans, sum);
  }
  printf("%lld", ans);
  return 0;
}


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

namespace Yuzuki
{
    class Yukari
    {
        public static void Main(string[] args)
        {
            string[] buf = Console.ReadLine().Split();
            int n = int.Parse(buf[0]), k = int.Parse(buf[1]);
            int m = (int)1e9 + 7;
            long ans = 0;
            for (long i = k; i <= n+1; i++)
            {
                long l = i * (i - 1) / 2, r = (2 * n - i + 1) * i / 2;
                ans += r - l + 1;
                ans %= m;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >>n >>m;
  
  int l, r;
  int lmax=1, rmin=100001;
  
  for(int i=0; i<m; i++){
    cin >>l >>r;
    if(l>lmax){
      lmax=l;
    }
    if(rmin>r){
      rmin=r;
    }
  }
  
  if(rmin>=lmax){
    cout <<rmin-lmax+1 <<endl;
  }
  else{
    cout <<0 <<endl;
  }
}	

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

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

    int index = 0;
    int ret = 0;
    while(index < n) {
        if(h[index] == 0) {
            index++;
        } else {
            int curmin = h[index];
            int len = 1;
            while(index+len < n && h[index+len] > 0) {
                curmin = min(curmin, h[index+len]);
                len++;
            }
            ret += curmin;
            for(int i = 0; i < len; ++i) {
                h[index+i] -= curmin;
            }
        }
    }
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s,t;
int n,k;

int get(string s){
	int n = s.size();
	int res = 0;
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1]){
			s[i] = '-';
			res++;
		}
	}
	return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
	//while(true){

	cin >> s;
	t = s;
	n = s.size();
	cin >> k;
	
 //    s="";
 //    //cin >> s;
 //    for(int i=0;i<10;i++){
 //        char c = 'a' + rand()%26;
 //        s+=c;
 //    }
 //    if(rand()%2){
 //        s[9]=s[0];
 //    }
 //    t = s;
 //    int n = s.length();
 //    int k,l=0,m=0,cnt=0;
 //    //cin >> k;
 //    k = 50;
 //    if(rand()%2)k++;
 // n = s.size();
	string t1 = s+s;
	string t2 = s+s+s;

	int a,b,c;
	a = get(s);
	b = get(t1);
	c = get(t2);
	//cout << a << " " << b << " " << c<< endl;
	int d1 = b-a;
	int d2 = c-b;
	int ans = a;
	if(k%2){
		ans += ((k-1)/2)*( d1+d2 );
	}
	else {
		ans += (k/2)*d1 + ((k-1)/2)*d2;
	}
//	int ans1;

//  cout << ans1 << " " << ans << endl;
  // if(ans1!=ans){
  // 	cout << t << " " << k << endl;
  // 	break;
  // }

	cout << ans << endl;

	//}
return 0;
}
///....


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;
struct P{
	int a,b;
};
bool cpm(const P &s,const P &t){
	return s.b<t.b;
}
int main(){
	int n,sum,x,y;
	while(cin>>n,n){
		P box[100];
		for(int i=0;i<n;i++){
			cin>>x>>y;
			box[i].a=x;
			box[i].b=y;
		}
		sort(box,box+n,cpm);
		sum=0;
		int i;
		
		for(i=0;i<n;i++){
			sum+=box[i].a;
			if(sum>box[i].b)
			break;
		}
		if(i==n)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
const int mo = 2019;
main()
{
    int l,r;
    cin >> l >> r ;
    if( r - l >= 1e4 ) { cout << 0 << endl;}
    else
    {
        int ans = 2019;
        for( int i = l; i < r; i++ )
        {
            for( int j = i + 1; j <= r; j++ )
            {
                ans = min( ans, i * j % mo );
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars
odd = []
eve = []
s.each_slice(2){|e|eve << e[0]; odd << e[1]}
if eve.compact.all?{|e|e=='R'||e=='U'||e=='D'} && odd.compact.all?{|e|e=='L'||e=='U'||e=='D'}
	puts "Yes"
else
	puts "No"
end


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


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
n = 2*10**3
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

for i in range(1, K+1):
    print(cmb(N-K+1, i, mod) * cmb(K-1, i-1, mod) % mod)


Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
    double r;
    cin >> r;
    double pi =acos(-1);
    cout << fixed << setprecision(6);
    double area =r*r*pi;
    double cir =2*r*pi;
    cout << area << " "<< cir <<endl;
    
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n; cin >> n;
  int ans = 0;

  int tmp_min = 1e9;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;

    if (tmp_min >= a) {
      ans++;
      tmp_min = a;
    }
  }

  cout << ans << endl;
}

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

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll money = 1000, stock;
  for (ll i = 0; i < N - 1; i++) {
    ll stock = 0;
    if (A[i + 1] > A[i]) stock = money / A[i];
    money += (A[i + 1] - A[i]) * stock;
  }
  cout << money << '\n';

  return 0;
}

Measured memory_bytes: 3644
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans += min(b[i], a[i]) + min(max(b[i] - a[i],0), a[i+1])
    a[i+1] = (a[i+1] - min(max(b[i] - a[i],0), a[i+1]))

print(ans)

Measured memory_bytes: 24140
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

import fractions
from functools import reduce
def calc_gcd(A):
    return reduce(fractions.gcd, A)

N,K = LI()
A = LI()

g = calc_gcd(A)
if K%g == 0 and K <= max(A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 88172
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

char s[500005];


int main(){
    cin >> n >> s;
    for(ll i=1;i<n;i++){
        ll tmp = 0;
        for(ll j=0;j+i<n;j++){
            ll i1,i2;
            i1 = j;
            i2 = j + i;
            if(s[i1] == s[i2]){
                tmp++;
            } else {
                tmp = min(tmp, i);
                ans = max(ans, tmp);
                tmp = 0;
            }
        }
        tmp = min(tmp, i);
        ans = max(ans, tmp);
    }
    p(ans);
}


















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

long long n,sum[200005],num;
map<long long,long long> a; 

int main()
{
    cin>>n;
    for(long long i=1;i<=n;i++){
    	long long x;
    	cin>>x;
    	sum[i]=sum[i-1]+x;
    	a[sum[i]]++;
    	if(sum[i]==0) num++; 
	}
	for(long long i=1;i<=n;i++){
		if(a[sum[i]]==0) continue;
		num+=(a[sum[i]]*(a[sum[i]]-1)/2);
		a[sum[i]]=0;
	}
	cout<<num<<endl;
	return 0;
}
// 1 0 1 0 1 0 1

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

int main() {
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)&&s.at(1)!=s.at(2)&&s.at(2)==s.at(3)) {
    cout << "Yes" << endl;
    return 0;
  }
  if(s.at(0)==s.at(2)&&s.at(1)!=s.at(2)&&s.at(1)==s.at(3)) {
    cout << "Yes" << endl;
    return 0;
  }
  if(s.at(0)==s.at(3)&&s.at(1)!=s.at(3)&&s.at(2)==s.at(1)) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define A 0
#define B 0
#define C 0
#define INF 10000
int n,hi[N][N];

int Minimum();

int main(){
  int i,j,q;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){

      scanf("%d",&q);

      if(q==-1){
	hi[i][j]=INF;
      }	else{
	hi[i][j]=q;
      }
      
    }
  }
  printf("%d\n",Minimum());

  return 0;
}

int Minimum(){
  int i,k,st,min,count=0;
  int de[N],p[N],judge[N];

  for(i=0;i<n;i++){
    de[i]=INF;
    p[i]=-1;
    judge[i]=0;
  }

  de[0]=0;

  while(1){
    min=INF;
    st=-1;
    for(i=0;i<n;i++){
      if(min>de[i] && judge[i]!=2){
	st=i;
	min=de[i];
      }
    }
    if(st==-1) break;
    judge[st]=2;

    for(k=0;k<n;k++){
      if(judge[k] !=2 && hi[st][k] !=INF){
	if(hi[st][k] < de[k]){
	  de[k]=hi[st][k];
	  p[k]=st;
	  judge[k]=1;
	}
      }
    }
  }
    
  for(i=0;i<n;i++){
    if(p[i] !=-1)
      count+= hi[i][p[i]];
  }

  return count;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}


vector<int> frac;
void init_frac(int N) {
   frac.push_back(1);
   for (int i = 1; i <= N; i++) {
      frac.push_back(mod(frac[i-1] * i));
   }
}
int powM(int x, int n) {
   int res = 1;
   while (n > 0) {
      if ((n & 1) == 1) {
         res = mod(res * x);
      }
      x = mod(x * x);
      n >>= 1;
   }
   return res;
}
int inverseM(int x) {
   return powM(x, MOD-2);
}
int comb(int n, int r) {
   if (n < 0 || n-r < 0 || r < 0) {
      return 0;
   }
   return mod(frac[n] * inverseM(mod(frac[n-r]*frac[r])));
}

signed main()
{
   int N, M; cin >> N >> M;

   vector<bool> isprime((int)pow(M,0.5)+1, true);
   isprime[0] = isprime[1] = false;
   for(int i = 2; i*i <= M; i++) {
      if (isprime[i]) {
         for (int j = 2; (i*j)*(i*j) <= M; j++) {
            isprime[i*j] = false;
         }
      }
   }
   dump(isprime)

   map<int,int> p_num;
   int tmpM = M;
   for(int i = 2; i < isprime.size(); i++) {
      if (!isprime[i]) continue;
      while (tmpM % i == 0) {
         p_num[i]++;
         tmpM /= i;
      }
   }
   if (tmpM != 1) p_num[tmpM]++;
   dump(p_num)

   init_frac(N + 50);
   int ans = 1;
   EACH(i, p_num) {
      ans = mod(ans * comb(N-1 + i->second, i->second));
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 1404
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >>d;
	while (1) {
		c = c - b;
		if (c <= 0) {
			cout << "Yes";
			return 0;
		}
		a = a - d;
		if (a <= 0) {
			cout << "No";
			return 0;
		}
	}
}

Measured memory_bytes: 3620
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
string s;
int n;
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  cin >> n >> s;
  bool f = false;
  for(auto &c:s)c-='1',f|=(c==1);

  f(i,0,n)if(s[i]==2)s[i]=!f;

  vector<int>cnt(1000*1000+5);

  f(i,1,1000*1000+5){
    cnt[i]=cnt[i-1]+__builtin_ctz(i);
  }

  int ans = 0;
  f(i,0,n)if(cnt[n-1]<=cnt[i]+cnt[n-i-1])ans^=s[i];

  if(!f)ans*=2;
  cout<<ans<<'\n';



  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,T; cin>>n>>T;
    int mini = 1010;
    rep(i,n){
        int c,t; cin>>c>>t;
        if (t<=T){
            mini = min(mini, c);
        }
    }
    if (mini == 1010){
        cout<<"TLE\n";
    }else{
        cout<<mini<<endl;        
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

int lsone(int n)
{
	return (n&-n);
}

void mult(ll a[matmax][matmax], ll b[matmax][matmax], ll c[matmax][matmax], int m, int n, int p)
{
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= p; j++)
		{
			c[i][j] = 0;
			for (int k = 1; k <= n; k++)
			{
				c[i][j] += (a[i][k]*b[k][j])%mod;
				c[i][j] %= mod;
			}
		}
	}
}

void mat_pow(ll a[matmax][matmax], ll c[matmax][matmax], int n, ll p)
{
	if (p == 0)
	{
		for (int i = 1; i <= n; i++)
			c[i][i] = 1;
	}
	else if (p == 1)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
				c[i][j] = a[i][j];
		}
	}
	else
	{
		ll d[matmax][matmax];
		mat_pow(a, d, n, p/2);
		if (p % 2)
		{
			ll e[matmax][matmax];
			mult(d, d, e, n, n, n);
			mult(e, a, c, n, n, n);
		}
		else
		{
			mult(d, d, c, n, n, n);
		}
	}
}

ll pow1(ll a, ll b)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2);
		x *= x;
		x %= mod;
		if (b%2)
		{
			x *= a;
			x %= mod;
		}
		return x;
	}
}

ll n;
string s;
int ans, num1[400000], num2[400000];
int main()
{
	fastio;		
	cin>>n>>s;
	ans = n;
	for (int i = 1; i <= n; i++)
	{ 
		num1[i] = num1[i-1];
		if (s[i-1] == 'W')
			num1[i]++;
	}
	num2[n+1] = 0;
	for (int i = n; i >= 1; i--)
	{
		num2[i] = num2[i+1];
		if (s[i-1] == 'E')
			num2[i]++;
	}

	for (int i = 1; i <= n; i++)
	{
		int temp = num1[i-1] + num2[i+1];
		ans = min(ans, temp);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));


int main() {

	string s;
	cin >> s;
	int n = s.size();

	int cnt0 = 0, cnt1 = 0;
	rep(i, 0, n) {
		if (s[i] == '0') cnt0++;
		if (s[i] == '1') cnt1++;
	}

	int ans = min(cnt0, cnt1);
	cout << ans * 2 << endl;

	return 0;
}

Measured memory_bytes: 3732
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		if(n%2==0){
			System.out.println(n/2);
		}else{
			System.out.println(n/2+1);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n,a,b;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    ll ans = 0;
    ans += (n/(a+b) )*a;
    ans += min(n%(a+b),a);
    print(ans);
    return 0;
}

Measured memory_bytes: 256
var lines = []; var result = Infinity;
var readline = require('readline');


var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var T = Number(lines[0].split(" ")[1]);

    lines.shift();

    var array = lines.map(value => value.split(" ").map(value => Number(value)));

    for (var i of array) {
        if (i[1] <= T) { result = Math.min(result, i[0]); }
    }
    result !== Infinity ? console.log(result): console.log("TLE");
});

Measured memory_bytes: 11596
#include<bits/stdc++.h>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
//inline void chmax(ll& a, ll b) {
//    a = max(a, b);
//}
typedef pair<ll, ll> P;
const ll INF = 1e12;
const int MX = 2005;
ll dp[MX][MX];
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n+1) rep(j, n+1) dp[i][j] = -INF;
    dp[0][0] = 0;
    vector<P> p;
    rep(i, n) p.emplace_back(a[i], i);
    sort(p.rbegin(), p.rend());
    rep(i, n) {
        int pi = p[i].second;
        rep(l, i+1) {
//            cout << a[pi] << endl;
            ll r = i-l;
            chmax(dp[i+1][l+1], dp[i][l]+ll(pi-l)*a[pi]);
            chmax(dp[i+1][l], dp[i][l]+ll((n-r-1)-pi)*a[pi]);
        }
    }
    ll ans = 0;
    rep(i, n+1) chmax(ans, dp[n][i]);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 35024
N,K = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
MOD = 10**9+7

es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

MAXN = K+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def npr(n,r):
    if n<r: return 0
    return fac[n] * finv[n-r]


ans = K
stack = [(0,0)]
visited = [0]*N
while stack:
    v,d = stack.pop()
    visited[v] = 1
    c = 0
    for to in es[v]:
        if visited[to]: continue
        c += 1
        stack.append((to,d+1))
    if c==0: continue
    m = npr(K-1,c) if d==0 else npr(K-2,c)
    ans *= m
    ans %= MOD
print(ans)

Measured memory_bytes: 56004
n = int(input())
MOD = 10 ** 9 + 7

a = list(map(int, input().split()))
a.sort()

if n % 2 == 1:
    for i in range(n):
        if i % 2 == 1 and a[i] - 1 == i: continue
        elif i % 2 == 0 and a[i] == i: continue
        else: 
            print(0)
            exit()
else:
    for i in range(n):
        if i % 2 == 1 and a[i] == i: continue
        elif i % 2 == 0 and a[i] - 1 == i: continue
        else: 
            print(0)
            exit()

print(2 ** (n//2) % MOD)

Measured memory_bytes: 14008