akhauriyash/Code-Regression huggingface dataset:
import bisect
N,A,B=map(int,input().split())
M=[int(input()) for i in range(N)]

M.sort()


MAX=10**9
MIN=0
MID=-(-(MAX+MIN)//2)

for i in range(100):
    if (MAX-MIN)<=1:
        break
    else:
        cnt=0
        for j in range(len(M)):
            if (M[j]-MID*B)<=0:
                pass
            else:
                if (M[j]-MID*B)%(A-B)==0:
                    cnt+=(M[j]-MID*B)//(A-B)
                else:
                    cnt+=((M[j]-MID*B)//(A-B)+1)
        if cnt<=MID:
            MAX=MID
            MID=(MAX+MIN)//2
        else:
            MIN=MID
            MID=(MAX+MIN)//2
#print(M)
print(int(MAX))
#print(cnt)
                

Measured memory_bytes: 51032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.AtCoder_Begginer_Contest_158
{
    class A
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            Boolean isSame = true;
            for(int i = 0; i < input1.Length - 1; i++)
            {
                if(input1[i] != input1[i+1])
                {
                    isSame = false;
                }
            }

            Console.WriteLine(isSame ? "No" : "Yes");

        }
    }
}


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

int main() {
    string S;
    cin >> S;
    bool ans = true;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 != 0) {
            if (S.at(i) != 'L' && S.at(i) != 'U' && S.at(i) != 'D') {
                ans = false;
            }
        }
        else {
            if (S.at(i) != 'R' && S.at(i) != 'U' && S.at(i) != 'D') {
                ans = false;
            }
        }
    }
    if (ans) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type edge struct {
	node   int
	weight int
}

type count struct {
	node  int
	count int
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	e := make([][]edge, n)
	w := make([]int, n)
	c := make([]int, n)
	v := make([]int, n)
	f := make([]bool, n)

	for i := 0; i < n-1; i++ {
		a := nextInt()
		b := nextInt()
		e[a-1] = append(e[a-1], edge{b - 1, 0})
		e[b-1] = append(e[b-1], edge{a - 1, 0})
	}
	for i := 0; i < n; i++ {
		v[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(v)))

	idx := 0
	tail := 1
	f[0] = true
	for idx < n {
		w[c[idx]] = v[idx]
		for _, v := range e[c[idx]] {
			if f[v.node] == false {
				c[tail] = v.node
				f[v.node] = true
				tail++
			}
		}
		idx++
	}

	sum := 0
	for i := 0; i < n; i++ {
		for j := 0; j < len(e[i]); j++ {
			x := w[i]
			if w[e[i][j].node] < w[i] {
				x = w[e[i][j].node]
			}
			e[i][j].weight = x
			sum += x
		}
	}
	//fmt.Printf("%v\n", v)
	//fmt.Printf("%v\n", c)
	//fmt.Printf("%v\n", w)
	//fmt.Printf("%v\n", e)

	_, _ = fmt.Fprintf(writer, "%d\n", sum/2)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fprintf(writer, "%d", w[i])
		if i != n-1 {
			_, _ = fmt.Fprintf(writer, " ")
		}
	}
}

func main() {
	answer(os.Stdin, os.Stdout)
}


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

int n, k; 

signed main(void){
    cin >> n >> k;

    int x = 0;
    rep(i, n - 1){
        int lb = 0, ub = (int)1e18;

        rep(loop, 100){
            int mid = (lb + ub) / 2;
            if(mid - x - 1 >= mid / k){
                ub = mid;
            }
            else {
                lb = mid;
            }
        }

        x = ub;
    }

    cout << x << endl;

	return 0;
}

Measured memory_bytes: 3076
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += (n-1)/i;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3652
import java.util.Scanner;

/**
 * Created 2017/05/25.
 * nextLineの挙動とか
 */
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long N = sc.nextLong();
      long b = sc.nextLong();
      long r = sc.nextLong();
     
      long s = b+r;
      long cnt = N / s;
      long mod = N % s;
      long p = Math.min(mod,b);
      long sum = b * cnt;
      long result = sum + p;
     System.out.println(result);
   }
}


Measured memory_bytes: 23764
fun main(args:Array<String>) {
    val (s, t) = readLine()!!.split(" ")
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    val u = readLine()!!
    if (s == u) {
        println("${a - 1} ${b}")
        return
    }
    println("${a} ${b - 1}")
}

Measured memory_bytes: 36036
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    lint n; cin>>n;
    vector<lint> a(n); 
    REP(i,n) cin>>a[i];
    lint cnt = 0;
    lint minimum = linf;
    REP(i,n){
        if(a[i]<0) cnt++;
        minimum = min(minimum, abs(a[i]));
    }
    lint ans = 0;
    if(cnt%2==1) ans -= 2*minimum;
    REP(i,n) ans += abs(a[i]);
    print(ans); 
    return 0;
}

Measured memory_bytes: 1024
using System;
namespace csharptest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int []a=new int[n];
            string[] str = Console.ReadLine().Split(' ');
            for (int m = 0; m < n; m++)
                a[m]=int.Parse(str[m]);
            Array.Reverse(a);
            Console.Write(a[0]);
            for (int m = 1; m < n; m++)
            {
                Console.Write(" " + a[m]);
            }
            Console.WriteLine();
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

const ll INF=1e18;
const int MAX_N=114514;
const int MAX_E=214514;

struct edge{
	pii u;
	pii v;
	int cost;
};

int root[MAX_N], depth[MAX_N];

edge es[MAX_E];
int V, E;

bool comp(const edge& e1, const edge& e2){
	return e1.cost<e2.cost;
}

// n要素で初期化
void init_union_find(int n){
	REP(i, n){
		root[i]=i;
		depth[i]=0;
	}
}

// xの根を求める
int find(int x){
	if(root[x]==x){
		return x;
	}
	else{
		return root[x]=find(root[x]);
	}
}

// xとyが属する集合を併合
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y){
		return;
	}
	if(depth[x]<depth[y]){
		root[x]=y;
	}
	else{
		root[y]=x;
		if(depth[x]==depth[y]){
			++depth[x];
		}
	}
	return;
}

// xとyが同じ集合に属するか判定
bool same(int x, int y){
	return find(x)==find(y);
}

ll kruskal(){
	sort(es, es+E, comp);
	init_union_find(V);
	ll res=0;
	REP(i, E){
		edge e=es[i];
		if(!same(e.u.second, e.v.second)){
			unite(e.u.second, e.v.second);
			res+=e.cost;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	pii x[114514], y[114514];
	cin>>n;
	V=n;
	E=2*(n-1);
	REP(i, n){
		cin>>x[i].first>>y[i].first;
		x[i].second=i;
		y[i].second=i;
	}
	sort(x, x+n);
	REP(i, n-1){
		edge e;
		e.u=x[i];
		e.v=x[i+1];
		e.cost=e.v.first-e.u.first;
		es[i]=e;
	}
	sort(y, y+n);
	REP(i, n-1){
		edge e;
		e.u=y[i];
		e.v=y[i+1];
		e.cost=e.v.first-e.u.first;
		es[n-1+i]=e;
	}
	cout<<kruskal()<<'\n';
	return 0;
}


Measured memory_bytes: 7040
from fractions import gcd
a,b=map(int,input().split())

n=max(a,b)
m=min(a,b)
ans=0
for i in range(1,m+1):
    ans=n*i
    if ans%m==0:
        print(ans)
        exit(0)

'''
ans=a*b//gcd(a,b)
print(ans)
'''

Measured memory_bytes: 5052
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

typedef long long ll;
ll n,x,ans;

ll f(ll a,ll b){
	if(b/a*a==b)return 2*b-a;
	return b/a*a*2+f(b%a,a);
}

int main(){
	scanf("%lld%lld",&n,&x);
	ans=n+(x<=n-x?f(x,n-x):f(n-x,x));
	printf("%lld\n",ans);
	return 0;
}

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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
    int n,x;
    cin >> n;
    vector<int> V(n);
    for(int i=0;i<n;++i)
        cin >> V[i];
    ll ans = 0;
    for(int i=0;i<n;++i)
    {
        cin >> x;
        if(x<V[i]) ans += V[i] - x;
    }    
    cout << ans;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}


Measured memory_bytes: 256
#include <iostream>

namespace NS20200711Acing
{

  class NumberOfMultiples final
  {
  public:
    NumberOfMultiples() = default;
    ~NumberOfMultiples() = default;

  public:
    void Run();

    void Input();
    void Calc();
    void Output();

  private:
    int m_L;
    int m_R;
    int m_d;
    int m_answer = 0;
  };

  void NumberOfMultiples::Run()
  {
    Input();
    Calc();
    Output();
  }

  void NumberOfMultiples::Input()
  {
    std::cin >> m_L;
    std::cin >> m_R;
    std::cin >> m_d;
  }

  void NumberOfMultiples::Calc()
  {
    int amari = m_L % m_d;

    for (int i = (amari == 0) ?m_L : m_L + ( m_d - amari); i <= m_R; i += m_d)
    {
      m_answer++;
    }
  }

  void NumberOfMultiples::Output()
  {
    std::cout << m_answer << std::endl;
  }

}
int main()
{
  NS20200711Acing::NumberOfMultiples prob;
  prob.Run();

  return 0;
}



Measured memory_bytes: 3104
#encoding utf-8
x = int(input())

exp_list = [1]
for i in range(2,33):
    j = 2
    while(i**j <= 1000):
        exp_list.append(i**j)
        j += 1

exp_list.sort()
in_list = [i for i in exp_list if i <= x]
print(in_list[-1])


Measured memory_bytes: 2940
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

void debug_out() {};
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

struct C1 {
    vector<ll> v_{};
    explicit C1(vector<ll> v) : v_(move(v)){}
    explicit C1(ll N, vector<ll> r, vector<tuple<ll, ll, ll>> v) {}
    ll resolve() {
        return 0;
    }
};

int main() {
    string S;
    cin >> S ;
    for (ll i=0; i < S.size(); ++i) {
        if ((i % 2 == 0 && S[i] == 'L') ||
            (i % 2 == 1 && S[i] == 'R'))
        {
            cout <<"No" << endl;
            return 0;
        }
    }
    cout <<"Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
//カタラン数を語らん!w

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 1;
	for (int i = 1; i < s.length(); ++i) {
		if (s[i - 1] != s[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

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

    int n;
    cin >> n;
    int x = (n/1000)*1000;
    if(n%1000) x += 1000;
    cout << x-n;
    return 0;
}

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

const int MOD = (int)1e9+7;

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

	int ans=0;
	int count=0;
	for(int i=0;i<S.size();i++){
		if(S.at(i)=='A' || S.at(i)=='C' || S.at(i)=='G' || S.at(i)=='T'){
			count++;
		}
		else{
			ans=max(ans,count);
			count=0;
		}
	}
	ans=max(ans,count);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String lastWeek = sc.next();
        if(lastWeek.equals("ABC")){
            System.out.print("ARC");
        }else{
            System.out.print("ABC");
        }
    }

}


Measured memory_bytes: 35480
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
int main(){
    int N,count=0;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a,a+N);
    long long w=0,h=0;
    for(int i=0;i<N;i++){
        count++;
        if(a[i]!=a[i+1]){
            if(count>=4){
                w=a[i];
                h=a[i];
            }else if(count>=2){
                w=h;
                h=a[i];
            }
            count=0;
        }
    }
    cout << h*w << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        int n[];
        n = new int [3];
        int temp;
        String s = "";
        Scanner sc = new Scanner(System.in);
        n[0] = sc.nextInt();
        n[1] = sc.nextInt();
        n[2] = sc.nextInt();

        for (int i = 0;  i < 2 ;i++) {
            if (n[i] > n[i + 1]) {
                 temp =n[i];
                 n[i] = n[i + 1];
                 n[i + 1] = temp;
            }
        }
        if (n[0] > n[1]) {
                 temp =n[0];
                 n[0] = n[1];
                 n[1] = temp;
        }
        System.out.println(n[0] + " " + n[1] + " " + n[2]);
    }
}


Measured memory_bytes: 26176
N=int(input())
import itertools
A=list(itertools.product([0,1,2,3,4,5],repeat=6))
ans=10**6
cnt=0
for i in A:
  a=6*i[0]+36*i[1]+216*i[2]+1296*i[3]+7776*i[4]+46656*i[5]
  if a<=N:
    b=N-a
    cnt=sum(i)
    for j in range(6,0,-1):
      d=b//(9**j)
      b-=(9**j)*d
      cnt+=d
    cnt+=b
    ans=min(cnt,ans)
print(ans)

Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
class Union_Find {
  private:
	vector<T> t, s;

  public:
	explicit Union_Find(T max_length) {
		for (int i = 0; i < max_length + 1; ++i) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(T x, T y) {
		if (same(x, y)) return;
		T tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	T Find(T n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(T x, T y) {
		return Find(x) == Find(y);
	}

	T get_Size(size_t a) {
		return s[a];
	}
};
int x[]={1,0,-1,0}, y[]={0,1,0,-1};
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    vector<vector<int>> dp(h,vector<int>(w,MOD));
    dp[0][0]=(s[0][0]=='.'?0:1);
    rep(i,h){
        rep(j,w){
            if(i>0){
                if(s[i][j]=='#'&&s[i-1][j]=='.'){
                    dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
                }
                else{
                    dp[i][j]=min(dp[i][j],dp[i-1][j]);
                }
            }
            if(j>0){
                if(s[i][j]=='#'&&s[i][j-1]=='.'){
                    dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
                }
                else{
                    dp[i][j]=min(dp[i][j],dp[i][j-1]);
                }
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  vector<int> v(n, 1);
  vector<bool> b(n, false);
  b[0] = true;

  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (b[x] == true)
      b[y] = true;
    v[y]++;
    v[x]--;
    if (v[x] == 0)
      b[x] = false;
  }

  int ans = 0;
  rep(i, 0, n) {
    if (b[i])
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll N,A,B,C,D;

int main(){
    cin>>N>>A>>B>>C>>D;
    N--;
    A=abs(A-B);
    ll x=D-C, y=D+C;
    ll R=N*D, L=N*C;
    bool able=false;
    while(true){
        if(A>R) break;
        if(L<=A && A<=R) {able=true; break;}
        A+=y;
    }
    if(able) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll ans = 0;
  ll cur = 0;
  while (cur < n) {
    cur++;
    if (cur % 3 == 0 && cur % 5 == 0) continue;
    if (cur % 3 == 0) continue;
    if (cur % 5 == 0) continue;
    ans += cur;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int X;
	cin >> X;
	int ans = (int)sqrt(X) * (int)sqrt(X);

	for (int i = 2; i < X; i++)
	{
		for (int j = 2; j < X; j++)
		{
			int tmp = pow(i, j);
			if (X < tmp)
			{
				break;
			}
			ans = max(ans, tmp);
		}
	}

	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

namespace std {
	#define u(x, a, b) for(ll x = a; x < b; x++)
	#define d(x, a, b) for(ll x = a; x > b; x--)
}

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 100000000000000007

vector<char> ans;
char letters[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
	ll n; 
	cin >> n;
	
	while(n>0){
		ll rem = (n-1)%26;
		ans.push_back(letters[rem]);
		n-=rem;
		n/=26;
	}	
	
	d(one, ans.size()-1, -1){cout << ans[one];}
}


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

int main(void){
    int n;
    cin >> n;
    int a,b,c;
    int dp[100005][3];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(int i=1; i<=n; i++){
        cin >> a >> b >> c;
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
    return 0;
}

Measured memory_bytes: 1408
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
    string s, T;
    cin>>s>>T;
    if((s.size()+1==T.size())&&(string(T.begin(), --(T.end()))==s)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}





Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i, n) cin >> d[i];
  vector<vector<double>> dp(n + 1, vector<double>(10001, -1));
  REP(i, 10001) dp[0][i] = 0;
  REP(i, n) {
    REP(j, 10001) {
      if (dp[i][j] < 0) continue;
      double l = dp[i][j] + sqrt(4 * d[i] * j) - j + d[i];
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      dp[i + 1][d[i]] = max(dp[i + 1][d[i]], l);
    }
  }
  double ans = 0;
  REP(i, 10001) ans = max(ans, dp[n][i]);
  cout << fixed << setprecision(8) << ans << endl;
}



Measured memory_bytes: 42172
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
void fun()
{

}
/// check for test case before submitting
void vfun()
{
    ll n;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];
    sort(v.begin(),v.end());
    ll mincs=INT_MAX;
    for(ll k=-100;k<=100;k++)
    {
        ll cst=0;
         fo(i,n)
         {
             cst+=pow(abs(v[i]-k),2);
         }
         mincs=min(mincs,cst);
    }
    cout<<mincs;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
   // cin>>test;
    while(test--)
    {

        ll n;
        cin>>n;
        vector <ll> a(n),b(n),c(n);
        fo(i,n)
            cin>>a[i];
        fo(i,n)
            cin>>b[i];
        fo(i,n)
            cin>>c[i];
        sort(a.begin(),a.end());
        sort(c.begin(),c.end());
        ll ans=0;
        fo(i,n)
        {
            auto it1=lower_bound(a.begin(),a.end(),b[i]);
            ll left=it1-a.begin();
            auto it2=upper_bound(c.begin(),c.end(),b[i]);
            ll right=c.end()-it2;

            ans+=(left*right);
        }

        cout<<ans<<endl;
        //fun();
       // vfun();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not



Measured memory_bytes: 5572
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 123456;
LL sufsum[MAXN];

bool check(int ans, int N, vector<int> &A, LL M) {
    LL cnt = 0;
    for (int i = 0; i < N; i++) {
        int cur = A[i];
        int rem = ans - cur;
        int idx = lower_bound(A.begin(), A.end(), rem) - A.begin();
        cnt += (N - idx);
    }
    return cnt >= M;
}

int main() {
    LL N, M;
    scanf("%lld %lld", &N, &M);
    vector<int> A, B;
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    for (int i = N - 1; i >= 0; i--)
        sufsum[i] = sufsum[i + 1] + A[i];
    int l = 0, r = (LL)1e6 + 1, ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid, N, A, M)) {
            ans = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    LL res = 0, cnt = 0;
    for (int i = 0; i < N; i++) {
        int cur = A[i];
        int rem = ans - cur;
        int idx = upper_bound(A.begin(), A.end(), rem) - A.begin();
        LL cur_cnt = N - idx;
        cnt += cur_cnt;
        res += (cur_cnt * cur);
        res += (sufsum[idx] - sufsum[N]);
    }
    res += (M - cnt) * ans;
    printf("%lld\n", res);

    return 0;
}


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

int main()
{
  int n ;
  cin >> n  ;
  int a[n] ;
    for(int i=0; i<n; i++){
      cin >> a[i] ;
  }  
  sort(a,a+n, greater<int>());  // a[0:N] を大きい順にソート
  
  int alice = 0;
  int bob = 0;
   for(int i=0;i<n;++i){
     if(i%2==0)
       alice+=a[i];
     else
       bob+=a[i];
   }
  cout << alice-bob << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
#define vecP vector<P>
// cout << setprecision(15) << std::fixed;


int main() {
	int n;
	cin >> n;
	vecll A(n);
	vecllvec x(n), y(n);
	for (int i = 0;i < n;i++) {
		cin >> A[i];
		//x.resize(A[i]);y.resize(A[i]);
		for (int j = 0;j < A[i];j++) {
			int a, b;
			cin >> a >> b;
			x[i].push_back(a);y[i].push_back(b);
		}
	}
	int ans = 0;
	for (int s = 0;s<(1<<n);s++) {
		int cou = 0;
		bool che = false;
		vecb Honest(n, false);
		for (int i = 0;i < n;i++) if (s >> i & 1) { Honest[i] = true; cou++; }
		for (int i = 0;i < n;i++) {
			if (!Honest[i]) continue;
			for (int j = 0;j < A[i];j++) {
				if (Honest[x[i][j] - 1] != y[i][j]) {
					che = true;
					break;
				}
			}
			if (che) break;
		}
		if(!che) chmax(ans, cou);
	}
	print(ans);
	return 0;
}




Measured memory_bytes: 256
def main():
    from itertools import groupby
    n, k, c = map(int, input().split())
    s = list(input())

    if c == 0:
        a = [i + 1 for i, c in enumerate(s) if c == 'o']
        if len(a) == k:
            print(*a, sep='\n')
        else:
            print()
        exit()

    check_f = []
    x = 0
    for i, j in enumerate(s, 1):
        if x:
            x -= 1
            continue
        if j == 'o':
            x = c
            check_f.append(i)
        if len(check_f) == k:
            break

    check_b = []
    x = 0
    for i, j in enumerate(s[::-1]):
        if x:
            x -= 1
            continue
        if j == 'o':
            x = c
            check_b.append(n - i)
        if len(check_b) == k:
            break

    ans = list(set(check_f) & set(check_b))
    ans.sort()
    ans = '\n'.join(map(str, ans))
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int n,m;
  	cin >> n >> m;
  	vector<int> dist(n,5);
  	vector<int> a(m);
  	vector<int> b(m);
  	dist[0] = 0;
  	for(int i = 0; i<m;i++) {
      	cin >> a[i] >> b[i];
      	a[i]--;b[i]--;
      	if(a[i] == 0)
          	dist[b[i]] = 1;
    }
  	for(int i = 0; i<m;i++) {
    	if(dist[a[i]]== 1) {
			dist[b[i]] = 2;
        } else if(dist[b[i]] == 1) {
          	dist[a[i]] = 2;
        }
    }
  	if(dist[n-1] <= 2)
	   	printf("POSSIBLE\n");
  	else
      	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

ll n;
V<V<V<double> > > dp(305, V<V<double> >(305, V<double>(305, 0.0)));
V<V<V<bool> > > flag(305, V<V<bool> >(305, V<bool>(305, false)));

double f(ll c1, ll c2, ll c3) {
  if (flag.at(c1).at(c2).at(c3)) return dp.at(c1).at(c2).at(c3);
  flag.at(c1).at(c2).at(c3) = true;
  double ans = 1 / (1-(double)(n-c1-c2-c3)/n);
  if (c1>0) ans += f(c1-1, c2, c3)*(c1/(double)n)/(1-(double)(n-c1-c2-c3)/n);
  if (c2>0) ans += f(c1+1, c2-1, c3)*(c2/(double)n)/(1-(double)(n-c1-c2-c3)/n);
  if (c3>0) ans += f(c1, c2+1, c3-1)*(c3/(double)n)/(1-(double)(n-c1-c2-c3)/n);
  return dp.at(c1).at(c2).at(c3) = ans;
}

int main() {
  flag.at(0).at(0).at(0) = true;
  cin >> n;
  vll a(n); REP(i, n) cin >> a.at(i);
  vll c(3, 0);
  REP(i, n) c.at(a.at(i)-1)++;
  cout << fixed << setprecision(12) << f(c.at(0), c.at(1), c.at(2)) << endl;
  return 0;
}


Measured memory_bytes: 232960
#include <stdio.h>

int main() {
    
    int n, c, t = 0;
    scanf("%d", &n);
    int v[n*2];
    
    for (int i = 1; i < n+1; ++i)
        v[i] = 0;
    
    for (int i = 1; i < n; ++i) {
        scanf("%d", &c);
        v[c] += 1;
    }
    
    for (int i = 1; i < n+1; ++i)
        printf("%d\n", v[i]);

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int ar[100];
int main()
{
	fastio;

	int n;
	cin >> n;

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

	ll money = 1000;
	for (int i = 1; i < n; ++i)
	{
		if (ar[i-1] < ar[i])
		{
			ll stock = money / ar[i-1];
			money += (ar[i] - ar[i-1]) * stock;
		}
	}
	cout << money << '\n';

	return 0;
}


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

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

const int INF = 1 << 30;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, M, R;
  cin >> N >> M >> R;

  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }
  sort(r.begin(), r.end());

  int dis[210][210];
  fill((int*)dis, (int*)(dis + N), INF);
  for (int i = 0; i < N; i++) dis[i][i] = 0;
  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--, B--;
    dis[A][B] = dis[B][A] = C;
  }
  for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
    if (dis[i][k] == INF || dis[k][j] == INF) continue;
    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  }
  int ans = INF;
  do {
    int sub = 0;
    for (int i = 0; i + 1 < R; i++) {
      sub += dis[r[i]][r[i + 1]];
    }
    ans = min(ans, sub);
  } while (next_permutation(r.begin(), r.end()));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
n = int(input())
l = input().split()
max = -1e9;min = 1e9;sum = 0
for i in range(n):
    sum+=int(l[i])
    if max<int(l[i]):
        max = int(l[i])
    if min>int(l[i]):
        min = int(l[i])
print(min,max,sum)



Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

const int limit = 50;
vint a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

int main(){
  int x;
  cin >> x;
  int a = x/1000;
  int b = x%1000/100;
  int c = x%100/10;
  int d = x%10;
  string op = "+-";
  bool ok = false;
  rep(i,2){
    int ans1 = 0;
    if(i == 0) ans1 = a + b;
    else ans1 = a - b;
    ok = false;
    rep(j,2){
      int ans2 = ans1; 
      if(j == 0) ans2 += c;
      else ans2 -= c;
      rep(s,2){
        int ans3 = ans2;
        if(s == 0) ans3 += d;
        else ans3 -= d;
        if(ans3 == 7){
          cout << a << op[i] << b << op[j] << c << op[s] << d << "=7" << endl;
          ok = true;
          break;
        }
      }
      if(ok) break;
    }
    if(ok) break;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int INF = 1e9 - 1;

int main()
{
	ios::sync_with_stdio(false);
	
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	if (h * w == 1)
	{
		cout << "No\n";
		return 0;
	}
	int X = INF / (h * w - 1);
	ll sum = 0;
	for (int i=0; i<H; i++)
		for (int j=0; j<W; j++)
			if (i % h == h - 1 && j % w == w - 1)
				sum -= h * w * X - X + 1;
			else
				sum += X;
	if (sum <= 0)
	{
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	for (int i=0; i<H; i++)
	{
		for (int j=0; j<W; j++)
			if (i % h == h - 1 && j % w == w - 1)
				cout << -(h * w * X - X + 1) << " ";
			else
				cout << X << " ";
		cout << "\n";
	}

	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	int a, b, c, ans, n, x, s;
  	s = 1;
  	while(s){
      	ans = 0;
    	cin >> n >> x;
      	if (n == 0 && x == 0) s = 0;
      	else {
        	for (int i = 1; i <= n-2; i++ ){
            	for (int j = i+1; j <= n-1; j++ ){
                  	for (int k = j+1; k <= n; k++ ){
                      	
                    	if (i+j+k == x) ans++;
                	}
                }
            }
        cout << ans << endl;
        }
     	
    }
  
    
    return 0;
}



Measured memory_bytes: 3076
# 解説見た

from itertools import tee


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def solve(N, L, a):
    for knot, pair in enumerate(pairwise(a), 1):
        if sum(pair) >= L:
            break
    else:
        return []
        # 隣接和は全てL未満のため、最後の一つを外せない

    ans = []
    for i in range(1, knot):
        ans.append(i)
    for i in range(N - 1, knot - 1, - 1):
        ans.append(i)
    return ans


if __name__ == '__main__':
    N, L = map(int, input().split())
    a = tuple(map(int, input().split()))
    ans = solve(N, L, a)
    if ans:
        print('Possible')
        print(*ans, sep='\n')
    else:
        print('Impossible')


Measured memory_bytes: 14644
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
int used[303][303][303];
double dp[303][303][303];
double dfs(int n,int x,int y,int z){
  double &res=dp[x][y][z];
  if(used[x][y][z]) return res;
  used[x][y][z]=1;
  res=0;
  if(x+y+z==0) return res;
  if(x) res+=dfs(n,x-1,  y,  z)*x/n;
  if(y) res+=dfs(n,x+1,y-1,  z)*y/n;
  if(z) res+=dfs(n,  x,y+1,z-1)*z/n;
  res+=1;
  double w=n-(x+y+z);
  res/=1.0-w/n;
  return res;
}

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int x=0,y=0,z=0;
  for(int c:a){
    x+=c==1;
    y+=c==2;
    z+=c==3;
  }
  memset(used,0,sizeof(used));
  cout<<dfs(n,x,y,z)<<endl;
  return 0;
}


Measured memory_bytes: 326272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
map<int,bool> x_;
map<int,bool> y_;
int x_p = 0;
int y_p = 0;
int times = 0;
int main(){
  string s; cin >> s; s += 'T'; cerr << s << endl;
  int x,y; cin >> x >> y;
  x_[0] = 1,y_[0] = 1;
  bool vec = false;
  rep(q,s.size()){
    if(s[q] == 'F'){
      if(vec == false)
        x_p++;
      else
        y_p++;
    }else{
      if(vec == false){
        map<int,bool> x__;
        for(auto i:x_){
          if(x_[i.FST] == 1){
            x__[i.FST + x_p] = 1;
            if(times != 0)
              x__[i.FST - x_p] = 1;
            else
              times = 1;
          }
        }
        x_p = 0; y_p=0;
        x_.clear();
        x_ = x__;
        //cerr << x__.size() << endl;
      }else{
        map<int,bool> y__;
        for(auto i:y_){
          if(y_[i.FST] == 1){
            y__[i.FST + y_p] = 1;
            y__[i.FST - y_p] = 1;
          }
        }
        y_p = 0; x_p=0;
        y_.clear();
        y_ = y__;
      }
      vec = (vec == 1)?0:1;
    }
  }
  //for(auto i:x_) cerr << i.FST << endl;
  if(y_[y] == 1 && x_[x] == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int a[60][60];

int main()
{
    int h, w;
    cin >> h >> w;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            char c;
            cin >> c;

            if(c == '#')
                a[i][j] = 1;
        }
    }

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(!a[i][j])
                continue;
            int cnt = 0;
            for(int k = 0; k < 4; k++)
                cnt += a[i + dx[k]][j + dy[k]];
            if(!cnt)
                return cout << "No\n", 0;
        }
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3592