akhauriyash/Code-Regression huggingface dataset:
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R second
#define pb push_back
#define mp make_pair
typedef long long ll;

const int maxn=2000+10;
int n, k, d[maxn][maxn], ans=maxn;
vector<int> g[maxn];
vector<pair<int, int> > e;
bool mark[maxn];
void bfs(int src)
{
    queue<int> q;
    memset(mark, 0, sizeof mark);
    d[src][src]=0;mark[src]=1;q.push(src);
    while(q.size())
    {
	int cur=q.front();q.pop();
	for(auto child:g[cur]) if(!mark[child]){mark[child]++;d[src][child]=d[src][cur]+1;q.push(child);}
    }
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n>>k;
    for(int i=0, x, y; i<n-1; i++) cin>>x>>y, x--, y--, g[x].pb(y), g[y].pb(x), e.pb({x,y});
    for(int i=0; i<n; i++) bfs(i);
    for(int i=0; i<n; i++)
    {
	int now=0;
	for(int j=0; j<n; j++) if(d[i][j]>k/2) now++;
	ans=min(ans, now);
    }
    for(auto ed:e)
    {
	int x=ed.L, y=ed.R, now=0;
	for(int i=0; i<n; i++) if(min(d[x][i],d[y][i])>(k-1)/2) now++;
	ans=min(ans, now);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 16128
#include <iostream>
#include <vector>
#include <cstdint>

using i64 = std::int64_t;

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

	std::vector<i64> v(n);
	for (auto&& e : v)
		std::cin >> e;

	i64 ans = 0;
	std::vector<i64> count(n + 1);
	for (auto&& e : v) {
		ans += count[e];

		++count[e];
	}

	for (auto&& e : v)
		std::cout << ans - (count[e] - 1) << std::endl;
}

Measured memory_bytes: 5760
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.min(a, b) + Math.min(c, d));
	}
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] a = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            a[c - 'a']++;
        }
        for (int i = 0; i < a.length; i++) {
            if (a[i] > 1) {
                System.out.println("no");
                return;
            }
        }
        System.out.println("yes");
    }
}

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

namespace ConsoleApplication3
{
    class Program
    {
        public static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            int[] b = new int[a];
            for(int e = 0; e < a; e++)
            {
                b[e] = e + 1;
            }
            int c = int.Parse(Console.ReadLine());
            for(int d = 0; d < c; d++)
            {   int m;
                var f = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
                m = b[f[0]-1];
                b[f[0]-1]= b[f[1]-1];
                b[f[1]-1] = m;
            }
            for (int n = 0; n < a - 1; n++) Console.WriteLine(b[n]);
            Console.WriteLine(b[a - 1]);
        }
    }
}

Measured memory_bytes: 9444
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main = do
  [a,b] <- getInts
  let [a',b'] = [f a, f b]
  putStrLn $ case (compare a' b') of
    LT -> "Bob"
    GT -> "Alice"
    EQ -> "Draw"
  where
    f 1 = 14
    f x = x


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

using namespace std;

int d[200004];

int main() {
	int n; scanf("%d",&n);
	int cnt=1;
	for (int i=1; i<=n; i++) scanf("%d",&d[i]);
	for (int i=1; i<=n; i++) {
		if (d[i]==cnt) cnt++;
	}
	if (cnt>1) printf("%d",n-cnt+1);
	else printf("-1");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]

using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//k!
ll facctorialMethod(ll k)
{
	ll sum = 1;
	for (ll i = 1; i <= k; ++i)
	{
		sum *= i;
		sum %= MOD;
	}
	return sum;
}

//nCr
ll permutationMethod(ll n, ll r)
{
	ll n_sum, r_sum;
	r = n - r;
	n_sum = facctorialMethod(n);
	r_sum = facctorialMethod(r);
	return n_sum / r_sum;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll pow_kai(int a, int n)
{ //aのn乗を計算します。
	ll x = 1;
	while (n > 0)
	{ //全てのbitが捨てられるまで。
		if (n & 1)
		{ //1番右のbitが1のとき。
			x = (x * a) % MOD;
		}
		a = (a * a) % MOD;
		n >>= 1; //bit全体を右に1つシフトして一番右を捨てる。
	}
	return x % MOD;
}

ll sum(ll a, ll d, ll n, ll mod)
{
	mod *= 2;
	ll ret = (2 * a + d * (n - 1)) % mod;
	ret = ret * n % mod;
	return ret / 2;
}

int main()
{
	int n, m;
	cin >> n >> m;
	rep(i,m){
		int a;
		cin >> a;
		n -= a;
	}
	cout << (n < 0 ? -1 : n) << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int[][] a = new int[4][4];
        for(int i = 0; i < 4; i++) {
            a[i][0] = stdIn.nextInt();
            a[i][1] = stdIn.nextInt();
        }
        for(int i = 0; i< 4; i++) {
            switch(a[i][0]) {
            case 1: System.out.println(a[i][1] * 6000);break;
            case 2: System.out.println(a[i][1] * 4000);break;
            case 3: System.out.println(a[i][1] * 3000);break;
            case 4: System.out.println(a[i][1] * 2000);break;
            }
        }
    }
         
}

Measured memory_bytes: 17168
#include <iostream>
#include <math.h>
#include <complex>

using namespace std;

int main() {
	int x1, y1, r1;
	int x2, y2, r2;
	
	cin >> x1 >> y1 >> r1;
	cin >> x2 >> y2 >> r2;
	
	int X = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
	
	if(r1+r2 < X){
		cout << 4 << endl;
	} else if(X == r1+r2){
		cout << 3 << endl;
	} else if(abs(r1-r2) < X){
		cout << 2 << endl;
	} else if(X == abs(r1-r2)){
		cout << 1 << endl;
	} else{
		cout << 0 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
vector<int> x,y,r,c,cover;
vector<bool> already;
int dfs(int n,int sta){
  if(already[sta]) return 0;
  already[sta]=true;
  int answer=0;
  REP(j,n){
    if((cover[j]&sta)||((1<<j)&(~sta))) continue;
    REP(i,j){
      if((cover[i]&sta)||((1<<i)&(~sta))) continue;
      if(c[i]==c[j]) answer=max(answer,2+dfs(n,sta&(~(1<<i))&(~(1<<j))));
    }
  }
  return answer;
}
int solve(int n){
  x.resize(n);
  y.resize(n);
  r.resize(n);
  c.resize(n);
  REP(i,n) cin >> x[i] >> y[i] >> r[i] >> c[i];
  cover.assign(n,0);
  REP(j,n) REP(i,j){
    if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<(r[i]+r[j])*(r[i]+r[j]))
      cover[j]=(cover[j]|(1<<i));
  }
  already.assign((1<<n),false);
  return dfs(n,(1<<n)-1);
}
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    cout << solve(n) << endl;
  }
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int count = 1;
	char color = S[0];
	for (int i = 1; i < N; i++) {
		if (color != S[i]) {
			color = S[i];
			count++;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int m;
    cin >> m;
    ll total = 0;
    ll cnt = 0;
    for (int i = 0; i < m; i++)
    {
        ll d, c;
        cin >> d >> c;
        total += d * c;
        if (total >= 10)
        {
            cnt += total / 9;
            total %= 9;
            if (total == 0)
            {
                --cnt;
                total = 9;
            }
        }
        cnt += c;
    }
    cout << cnt - 1 << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    int count=0;
    for(int i=0;i<n;){
        if(s.substr(i,3)=="ABC"){
            i+=3;
            count++;
        }else i++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#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=a;i<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());

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 d[401][401];

const ll MAXN=200001;

ll par[MAXN];
ll rnk[MAXN];
ll Size[MAXN];

vec D(MAXN,-1);

ll Co[MAXN][2];

void shoki(){
    for(ll i=0;i<MAXN;i++) {par[i]=i; rnk[i]=0; Size[i]=1;}
}

ll sch(ll x){
    if(par[x]==x) return x;
    else return par[x]=sch(par[x]);
}

void con(ll A,ll B){
    A=sch(A);
    B=sch(B);
    if(A==B) return;
    if(rnk[A]>rnk[B]) swap(A,B);
    par[A]=B;
    Size[B]+=Size[A];
    Size[A]=Size[B];
    if(rnk[A]==rnk[B]) rnk[B]++;

    return;
}

ll is_size(ll k){
    return Size[sch(k)];
}

bool same(ll A,ll B){
    return sch(A)==sch(B);
}

int main(){
    shoki();
    rep(i,401) rep(j,401) d[i][j]=INF;
    ll H,W; cin>>H>>W;
    rep(i,H){
        string S; cin>>S;
        rep(j,W){
            if(S.at(j)=='#') d[i][j]=1;
            else d[i][j]=0;
            D.at(i*450+j)=d[i][j];
        }
    }

    rep(i,H) rep(j,W){
        if(i!=H-1){
            if(d[i][j]!=d[i+1][j]) con(i*450+j,(i+1)*450+j); 
        }

        if(j!=W-1){
            if(d[i][j]!=d[i][j+1]) con(i*450+j,i*450+j+1); 
        }
    }
    rep(i,H) rep(j,W){
        ll x=i*450+j;
        //cout<<sch(x)<<endl;
        Co[sch(x)][D.at(x)]++;
    }
    ll ans=0;
    rep(i,H) rep(j,W){
        ll x=i*450+j;
       // cout<<Co[x][0]<<' '<<Co[x][1]<<endl;
        ans+=Co[x][0]*Co[x][1];
    }
    cout<<ans<<endl;

    




}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> a(h); for (int i = 0; i < h; i++) cin >> a[i];
  for (int i = 0; i < h; i++) {
    cout << '#';
    for (int j = 1; j < w - 1; j++) {
      if (i & 1) cout << '#';
      else cout << a[i][j];
    }
    cout << ".\n";
  }
  cout << '\n';
  for (int i = 0; i < h; i++) {
    cout << '.';
    for (int j = 1; j < w - 1; j++) {
      if (i & 1) cout << a[i][j];
      else cout << '#';
    }
    cout << "#\n";
  }
}

Measured memory_bytes: 1024
//>> OI Solution Info <<//
// Version: 2
// State: Progress
// Problem: Tak and Hotels
// ID: ---
// Timeline:
//   --- ~ --- Initialize
// Review:
//   ---
//>> End <<//
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 y_0
#define y1 y_1
#define yn y_n
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n,l,q,a[100005],p[20][100005],pow2[20];

inline bool getBit(unsigned int x,unsigned int p){
	return (x>>p)&1;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	scanf("%d %d",&l,&q);
	int pos=n-1;
	for(int i=n-1;i>=0;i--){
		while(a[pos]-a[i]>l)pos--;
		p[0][i]=pos;
	}
	pow2[0]=1;
	for(int i=1;i<20;i++){
		pow2[i]=pow2[i-1]*2;
		for(int j=0;j<n;j++)p[i][j]=p[i-1][p[i-1][j]];
	}
	while(q--){
		int a,b;
		scanf("%d %d",&a,&b);
		a--,b--;
		if(a>b)swap(a,b);
		int left=0,right=n;
		while(left<=right){
			int mid=(left+right)/2,pos=a;
			for(int i=19;i>=0;i--)if(getBit(mid,i))pos=p[i][pos];
			if(pos>=b)right=mid-1;else left=mid+1;
		}
		printf("%d\n",left);
	}
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=false,fll=false;

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

       cin >> s;
       rep(i,Size(s)){
           if(s[i]=='C'){
               fl=true;
           }
           else if(s[i]=='F' && fl){
               Cout("Yes");
               return 0;
           }
       }
       Cout("No");
       
return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

int1 = lambda x: int(x) - 1

N, M = map(int, input().split())

not_start_point = set()
to_point = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int1, input().split())
    not_start_point.add(y)
    to_point[x].append(y)

start_point = set(range(N)) - not_start_point

dp_memo = [-1]*N
for x in range(N):
    if len(to_point[x]) == 0:
        dp_memo[x] = 0

# 点i始点のLongest Pathの長さ
def dp(i):
    if dp_memo[i] >= 0:
        return dp_memo[i]
    lp = 0
    for j in to_point[i]:
        lp = max(lp, dp(j)+1)
    dp_memo[i] = lp
    return lp

ans = 0
for s in start_point:
    ans = max(ans, dp(s))

print(ans)

Measured memory_bytes: 175148
n = int(input())

count = n

for i in range(0, n + 1):

    current_count = 0
    t = i
    while t > 0:
        current_count += t%6
        t //= 6

    t = n - i
    while t > 0:
        current_count += t%9
        t //= 9

    if count > current_count:
        count = current_count
print(count)






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

int main(){
    long long n;
    cin >> n;
    long long a[n];

    long long minus_cnt = 0;
    long long sum = 0;
    long long abs_min = 1e15;
    for(long long i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] < 0) minus_cnt++;

        sum += abs(a[i]);
        abs_min = min(abs_min, abs(a[i]));
    }

    if(minus_cnt % 2 == 0) cout << sum << endl;
    else cout << sum - 2*abs_min << endl;
    return 0;
    
}

Measured memory_bytes: 4388
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long



signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int lower = 0;
    int upper = 0;
    rep(i, K) {
        lower += i;
        upper += N - i;
    }
    int ans = 0;
    REP(i, K, N + 1) {
        int d = upper - lower;
        //cout << lower << " " << upper << endl;
        ans += d + 1;
        ans %= mod;
        lower += i;
        upper += N - i;
    }
    cout << ans << endl;

    return 0;
}


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

public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] hen = new int[3];
		for(int j=0; j<n;j++) {
		for(int i=0; i<3;i++)hen[i]=sc.nextInt();
		Arrays.sort(hen);
		if(hen[0]*hen[0]+hen[1]*hen[1]==hen[2]*hen[2]) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}
}


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

int check(int i, int num[])
{
    string pay = to_string(i);
    for(int p = 0; p < pay.length(); p++){
        if(num[pay[p]-'0']==1) {
            return 0;
        }
    }
    return 1;
}

int main(void)
{
    int N, K;
    int num[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int n;
    cin >> N >> K;
    for(int i = 0; i < K; i++) {
        int n;
        cin >> n;
        num[n] = 1;
    }
    //while(!check(N, num)) N++;
  	for(int i = N; i <= 100000; i++){
      if(check(i, num)){
        cout << i << endl;
        break;
      }
    }
    //cout << N << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  int M;
  cin >> M;
  vector<string> T(M);
  for(int i=0;i<M;i++){
    cin >> T.at(i);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    int score=0;
    for(int j=0;j<N;j++){
      if(S.at(j) == S.at(i)){
        score++;
      }
    }
    for(int k=0;k<M;k++){
      if(T.at(k) == S.at(i)){
        score--;
      }
    }
    ans = max(ans,score);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,k] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n k as
  mapM_ (\b -> putStrLn $ if b then "Yes" else "No") ans

compute :: Int -> Int -> [Int] -> [Bool]
compute n k as = zipWith (<) as (drop k as)

{-
as と drop k as を用意して、
次に進むたびに、左だけ減って右だけ増えるので、L<Rなら真に増加する
-}

Measured memory_bytes: 23880
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
	++n;
	if(noww>w || nowh>h) return 0;
	if(noww==w && nowh==h) return 1;
	int ret=0;
	n=0;
	if(n)
	ret+=dfs(w,h,++noww,nowh,n,b);
	ret+=dfs(w,h,noww,++nowh,n,b);
	ret+=dfs(w,h,++noww,nowh,n,b);
	ret+=dfs(w,h,noww,++nowh,n,b);
	return ret;
}

int main()u{
	int w,h;
	cin >> w >> h;
	cout << dfs(w,h,1,1,2,0) << endl;
	return 0;
}
*/

int main(){
	int n,m;
	while(cin >> n >> m&&n!=0&&m!=0){
		vector<int> stu1(m);
		vector<int> stu2(m);
		vector<int> f(n+1);
		int cnt=0;
		for(int i=0; i<m; ++i){
			cin >> stu1[i] >> stu2[i];
			if(stu1[i]==1){
				++cnt;
				f[stu2[i]]=1;
			}
		}
		for(int i=0; i<m; ++i){
			if(f[stu1[i]]==1&&f[stu2[i]]==0&&stu1[i]!=1){
				++cnt;
				f[stu2[i]]=2;
			}
			if(f[stu1[i]]==0&&f[stu2[i]]==1&&stu1[i]!=1){
				++cnt;
				f[stu1[i]]=2;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<long long, int> mp;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a] = 1 - mp[a];
    }
    int ans = 0;
    for(auto e : mp) ans += e.second;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<vector<ll> > dp(2001,vector<ll>(2001));
    for (int i = 0; i <= 2000; i++){
        dp[i][0] = 1;
        dp[i][i] = 1;
    }
    for (int i = 2; i <= 2000; i++){
        for (int j = 1; j <= i - 1; j++){
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % 1000000007;
        }
    }
    for (ll i = 1; i <= K; i++){
        ll ans = ((dp[N - K + 1][i] * dp[K - 1][i - 1]) % 1000000007);
        cout << ans << endl;
    }
}



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

constexpr long long MOD = 1e9 + 7;

long long binExp(long long a, long long e) {
	if (e == 0) {
		return 1;
	}

	if (e % 2 == 1) {
		return (binExp(a, e - 1) * a) % MOD;
	}

	long long b = binExp(a, e / 2);
	return (b * b) % MOD;
}

long long f(long long a) {
	long long r = 1;
	for (long long i = 2; i <= a; ++i) {
		r = (r * i) % MOD;
	}

	return r;
}

long long inv(long long a) {
	return binExp(a, MOD - 2);
}

long long c(long long k, long long n) {
	long long a = f(k);
	long long b = inv(f(n));
	long long d = inv(f(k - n));

	return ((a * b) % MOD * d) % MOD;
}

int main() {
	long long x, y;
	cin >> x >> y;

	if ((x + y) % 3 != 0) {
		cout << 0;
		return 0;
	}

	long long k = (x + y) / 3;
	long long n = x - k;

	if (n < 0 || k - n < 0) {
		cout << 0;
		return 0;
	}

	cout << c(k, n);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){

  int count = 0, countnot = 0;
  char a[5];
  scanf("%s", a);
  for(int i= 0; i < 3; i++){
    for(int j = i + 1; j < 4; j++){
      if(a[i] == a[j]){
	count++;
      }	else{
	countnot++;
      }
    }
  }
  //printf("%d",count);
  //printf("%d",countnot);
  if(count == 2 && countnot == 4){
    printf("Yes\n");
  }	else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int H, W, K;
string S[20];
int ans;

int main() {
  cin >> H >> W >> K;
  rep(i, 0, H) { cin >> S[i]; }

  ans = inf;

  for (int bit = 0; bit < (1 << (H - 1)); bit++) {
    bool gok = true;
    vector<int> line(H, 0);
    int cnt = 0;
    for (int i = 0; i < H; i++) {
      line[i] = cnt;
      if (bit & (1 << i)) {
        cnt++;
      }
    }

    vector<int> white(cnt + 1, 0);
    int add = cnt;
    for (int i = 0; i < W; i++) {
      vector<int> one(cnt + 1, 0);
      bool ok = true;
      for (int j = 0; j < H; j++) {
        if (S[j][i] == '1') {
          white[line[j]]++;
          one[line[j]]++;

          if (white[line[j]] > K) {
            ok = false;
          }
          if (one[line[j]] > K) {
            gok = false;
          }
        }
      }
      if (!ok) {
        white = one;
        add++;
      }
    }
    if (!gok) {
      continue;
    }

    ans = min(ans, add);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
"""
Rを立法数とする
a * R と a**2 * R a**1 * R → a**2*R a**1*R a**2*R
3つはなれてるとあかん！！　でも取り除かれてるはずだよな…
→Rを取り除いて後はDP

どうやって立法数を取り除く？
10**3.3まで試し割り？→5secだから間に合うかなぁ


Rを取り除く→10**3.333333以下の素数の3乗で割れるか確かめる

対になるsの導出：
素因数分解→10**5まで試し割(割れて10**5以下になったらdivlis方式に変える)
→巨大素数ばっかりだと死ぬ
2乗して新たに生まれたRを取り除けばok！！！！
→範囲は？10**6.6666以下か？(やばくね？)

sと対になるsでは片方しか取れない(dicで管理するかぁ)
sと対sの中で小さい方に合わせてdicで管理かなぁ
"""
def Sieve(n): #n以下の素数全列挙(O(nloglogn)) retは素数が入ってる。divlisはその数字の素因数が一つ入ってる

    ret = []
    divlis = [-1] * (n+1) #何で割ったかのリスト(初期値は-1)
    
    flag = [True] * (n+1)
    flag[0] = False
    flag[1] = False

    ind = 2
    while ind <= n:

        if flag[ind]:
            ret.append(ind)

            ind2 = ind ** 2

            while ind2 <= n:
                flag[ind2] = False
                divlis[ind2] = ind
                ind2 += ind

        ind += 1

    return ret,divlis


N = int(input())
dic = {}

ret,divlis = Sieve(10**5)
ret2 = []
for i in ret:
    ret2.append(i**2)
div3 = 0

for loop in range(N):

    s = int(input())
    ndic = {}

    for i in ret:

        if i**3 > 10**10:
            break

        while s % i == 0:
            if i not in ndic:
                ndic[i] = 1
            else:
                ndic[i] += 1
            s //= i

    if s in ret2:
        ndic[int(s**0.5)] = 2
    else:
        ndic[s] = 1
    
    S = 1
    T = 1
    #print (ndic)
    for i in ndic:
        S *= i ** (ndic[i] % 3)
        T *= i ** ((-1 * ndic[i]) % 3)

    #print (S,T)

    if S == T:
        div3 += 1
    elif S < T:
        if S not in dic:
            dic[S] = [1,0]
        else:
            dic[S][0] += 1
    else:
        if T not in dic:
            dic[T] = [0,1]
        else:
            dic[T][1] += 1

ans = min(1,div3)

for i in dic:
    ans += max(dic[i])

print (ans)

Measured memory_bytes: 88536
Option Explicit On

Module Module1

    Sub Main()

        Dim tmp As String() = Split(Console.ReadLine(), " ")

        Dim A As Integer = CInt(tmp(0))
        Dim B As Integer = CInt(tmp(1))
        Dim C As Integer = CInt(tmp(2))
        Dim K As Integer = CInt(tmp(3))

        Dim ans As Integer

        If A <= K Then
            ans = A
            K -= A
            If B <= K Then
                K -= B
                If C <= K Then
                    ans -= C
                Else
                    ans -= K
                End If
            End If
        Else
            ans = K
        End If

        Console.WriteLine(ans)

    End Sub
End Module


Measured memory_bytes: 28380
#include <stdio.h>
#define N 100000

typedef struct jobdata{
    int a;
    int b;
    struct jobdata *next;
}Job;

Job heap[N];
int top = -1;

typedef Job key;

void marge(key data[], key work[], int start, int mid, int end){
    int i = start;
    int j = mid + 1;
    int k = start;
    while(i <= mid && j <= end){
        if(data[i].a <= data[j].a){
            work[k++] = data[i++];
        }else{
            work[k++] = data[j++];
        }
    }
    
    if(i <= mid){
        while(i <= mid){
            work[k++] = data[i++];
        }
    }else{
        while(j <= end){
            work[k++] = data[j++];
        }
    }
    
    for(k = start; k <= end; k++){
        data[k] = work[k];
    }
}

void margesort(key data[], key work[], int start, int end){
    int mid;
    if(start < end){
        mid = start + (end - start)/2;
        margesort(data, work, start, mid);
        margesort(data, work, mid + 1, end);

        marge(data, work, start, mid, end);
    }
}

void pushheap(Job input){
    int point,child;
    Job tmp;
    top++;
    heap[top] = input;
    point = top;
    while(point > 0){
        child = (point-1)/2;
        if(heap[child].b < heap[point].b){
            tmp = heap[point];
            heap[point] = heap[child];
            heap[child] = tmp;
        }else{
            break;
        }
        point = child;
    }
}

Job popheap(void){
    int point,cl,cr;//child left/right
    Job tmp;
 
    tmp = heap[top];
    heap[top] = heap[0];
    heap[0] = tmp;
    
    point = 0;
    
    while(point < top){
        cl = point*2+1;
        cr = cl+1;
        if(cl >= top){
            break;
        }
        
        if(cr >= top || heap[cl].b > heap[cr].b){
            if(heap[cl].b > heap[point].b){
                tmp = heap[cl];
                heap[cl] = heap[point];
                heap[point] = tmp;
                point = cl;
            }else{
                break;
            }
        }else{
            if(heap[cr].b > heap[point].b){
                tmp = heap[cr];
                heap[cr] = heap[point];
                heap[point] = tmp;
                point = cr;
            }else{
                break;
            }
        }
    }
    return heap[top--];
}

int main(void){
    int n,m;
    static Job data[N];
    static Job work[N];
    Job tmp;
    long int total = 0;
    
    int i,j;

    scanf("%d %d", &n, &m);
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &data[i].a, &data[i].b);
    }
    
    margesort(data, work, 0, n-1);
    
    for(i = 1, j = 0; i <= m; i++){
        while(j < n && data[j].a == i){
            pushheap(data[j++]);
        }
        
        if(top >= 0){
            tmp = popheap();
        
            total += tmp.b;
        }
    }
    
    printf("%ld\n", total);
    
    return 0;
}

Measured memory_bytes: 4864
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> x;
    rep(i,n){
        int a;
        cin >> a;
        x.emplace_back(a, i);
    }
    sort(x.begin(), x.end());
    vector<int> ans(n);
    rep(i,n/2){
        ans[x[i].second] = x[n/2].first;
    }
    for(int i = n/2; i < n; i++){
        ans[x[i].second] = x[n/2-1].first;
    }
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

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

#define ll long long
#define pb push_back
#define iter std::vector<int>::iterator

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

	// reading values
	int n; cin >> n;

	// create vector of stones and future cost values
	vector<int> h(n), dp(n);

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

	// cost of stone 0 = 0
	dp[0] = 0;
	// cost of stone 1 equals the difference between the first and second
	dp[1] = abs(h[0] - h[1]);

	// from the second until the last stone
	for (int i=2; i<n; i++) {


		// the cost to reach to position[i] is equal 
		// to the minimum value considering reaching from h[i-1] and h[i-2]
		
		// the optimal cost is measured computing dp[i-1] and adding the
		// new cost to it, that is abs(h[i] - h[i-1]) or dp[i-2] and adding the 
		// new cos to it, abs(h[i] - h[i-2])  
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));

	}

	cout << dp[n-1];

	return 0;	
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	int key,i,j,k,l;
	int array[] = new int[101];

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();
	for(l=1;l<=array[0];l++){
	    array[l] = scan.nextInt();
	}
	
	
	for(i=1;i<=array[0];i++){
	    key = array[i];
	    j = i-1;
	    while(j>0 && array[j]>key){
		array[j+1] = array[j];
		j--;
		array[j+1] = key;
	    }
	    for(k=1;k<=array[0];k++){
		if(k==array[0]){System.out.print(array[k]+"\n");
		    break;
		}
		System.out.print(array[k]+" ");
	    }
	}
    }
}



Measured memory_bytes: 31832
//omajinai c++ atcoder
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<cmath>
#include<iomanip>
#include<type_traits>
//#include<numbers>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
#define yes() printf("Yes\n")
#define no() printf("No\n")
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;

int main() {
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2];
}




Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int main(){

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==c)
    cout<<0<<endl;
    else
    cout<<1<<endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        //System.out.println(n/(2*d+1));

        System.out.println((int)Math.ceil((double)n/(2*d+1)));
    }
}


Measured memory_bytes: 21588
N = int(input())
S = input()
ans = N
x = 0
y = S.count('E')
for i in range(N):
    if S[i-1] == 'W' and i > 0:
        x += 1
    if S[i] == 'E':
        y -= 1
    if x + y < ans:
        ans = x + y
print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[3005][3005];

void Main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    rep(i, N) {
        rep(j, M) {
            if (S[i] == T[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    string ans = "";
    int s = N - 1;
    int t = M - 1;
    while ((s >= 0 && t >= 0) && ans.size() < dp[N][M]) {
        if (S[s] == T[t]) {
            ans += S[s];
            s--;
            t--;
        } else {
            if (s > 0 && t > 0) {
                if (dp[s+1][t] > dp[s][t+1]) {
                    t--;
                } else {
                    s--;
                }
            } else {
                if (s == 0) {
                    t--;
                } else {
                    s--;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 2000000000000000000
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  ll n,ans=0;
  cin>>n;
  ll gg=n/3;
  for(ll i=1;i<=gg;i++) {
  	ll kk=n-(i*3);
  	kk=kk+i-1;
  	ll a=1,b=1;
  	if(kk<i-1) { break; } else {
  	for(ll j=1;j<=kk;j++) { a=a*j%M; }
  	for(ll j=1;j<=i-1;j++) { b=b*j%M; }
  	for(ll j=1;j<=kk-i+1;j++) { b=b*j%M; }
  		a=a*powmod(b,M-2,M)%M;
  	ans+=a;
  	//cout<<gg<<'\n';
  }
  }
  ans=(ans+M)%M;
  cout<<ans;
  //}
  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line



const int inf = 1001001001;
int dist[100005][3];
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> to(n);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a, --b;
		to[a].push_back(b); // 有向グラフ
	}
	int sv, tv;
	cin >> sv >> tv;
	--sv, --tv; //sからtにいけるか。

	rep(i,n)rep(j,3) dist[i][j] = inf;
	queue<P> q;
	q.push(P(sv,0));
	dist[sv][0] = 0;

	while(!q.empty()){
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (int u : to[v]) {
			int nl = (l+1) % 3;
			if (dist[u][nl] != inf) continue;
			dist[u][nl] = dist[v][l]+1;
			q.push(P(u,nl));
		}
	}
	int ans = dist[tv][0];
	if (ans == inf) ans = -1; 
	else ans /= 3;
	cout << ans << endl;
}


Measured memory_bytes: 9728
#include <stdio.h>
#define N 100

int matrixChainOrder(int *, int);

int main(){
  int n, i, p[N];

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d%d", &p[i], &p[i + 1]);

  printf("%d\n", matrixChainOrder(p, n));

  return 0;
}

int matrixChainOrder(int *p, int n){
  int i, j, k, l,m[N][N], q;

  for(i = 1; i <= n; i++) m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      j = i + l - 1;
      m[i][j] = 1000000;
      for(k = i; k <= j - 1; k++){
	q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
	if(m[i][j] > q) m[i][j] = q;
      }
    }
  }

  return m[1][n];
}

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

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r ;
  if(x+r <=W && y+r <=H && 0<=x-r && 0<=y-r)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 1160
function main(input){
    let lines = input.split("\n");
    let str = lines[0]+lines[0];
    if(str.indexOf(lines[1])!==-1){
        console.log("Yes");
    }else{
        console.log("No");
    }
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15096
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    map<int, int> Q;
    int A, B;
    for (int i = 0; i < N; i++)
    {
        cin >> A >> B;
        Q[B] += A;
    }

    int t = 0;
    for (auto& p : Q)
    {
        t += p.second;
        if (t > p.first)
        {
            cout << "No" << endl;
            return 0;
        }

    }
    
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int n,q,k,i;
#define rep(i,n) for(i=0;i<n;i++)
int a[100000];
int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	cin >> q;
	while (q--) {
		cin >> k;
		cout << lower_bound(a, a + n, k) - a <<" "<< upper_bound(a, a + n, k) - a << endl;
	}
}


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

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


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

long long valid(long long a, long long b, long long mid){
    long long taxb = mid*0.1, taxa = mid*0.08;
    if(taxb == b && taxa == a){
        return 0;
    }
    else if(taxb > b || taxa > a)
        return 1;
    else{
        return -1;
    }
}

long long bin_s(long long a, long long b){
    long long ans = -1, first = 1, last = 1000, mid;
    while(first<=last){
        mid = (first+last)/2;
        long long d = valid(a, b, mid);
        if(d == 0){
            ans = mid;
            last = mid-1;
        }
        else if(d == 1){
            last = mid-1;
        }
        else{
            first = mid+1;
        }
    }
    return ans;
}

int main()
{
    //textIO();
    fastIO();

    long long a, b;
    cin >> a >> b;
    cout << bin_s(a, b) << '\n';

    return 0;
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

ll gcd(ll a, ll b)
{
    return (a < b) ? gcd(b, a) : ((a % b) ? gcd(b, a % b) : b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

ll powmod(ll x, ll p, ll m)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return powmod(x, p - 1, m) * x % m;
    ll r = powmod(x, p / 2, m);
    return r * r % m;
}

constexpr ll MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    while (N != 0)
    {
        llv A(N);
        ll sum = 0;
        rep(i, N)
        {
            cin >> A[i];
            sum += A[i];
        }
        ll ans = 0;
        rep(i, N)
        {
            ans += (A[i] * N <= sum);
        }
        cout << ans << endl;
        cin >> N;
    }

    return 0;
}



Measured memory_bytes: 3164
#include<iostream> 
using namespace std;
int main()
{
	int n,x=0,y=0;
	
	cin>>n;
	
	int v[n],c[n];
	
	for(int i=1;i<=n;i++)
	cin>>v[i];
	
	for(int i=1;i<=n;i++)
	cin>>c[i];
	
	for(int i=1;i<=n;i++)
	{
		if(v[i]-c[i]>=1)
		{
			x+=v[i];
			y+=c[i]; 
		}
	}
	
	cout<<x-y;
	
	return 0;
}

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

using namespace std;

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

int main(){
  int n;cin>>n;
  float sum = 0;
  REP(i, n){
    float tmp;cin>>tmp;
    sum += 1/tmp;
  }
  cout<<1/sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll A, B, K;
  cin >> A >> B >> K;

  for (auto i = 0; i < K; i++) {
    if (i % 2 == 0) {
      if (A % 2 == 1) A--;
      A /= 2;
      B += A;
    } else {
      if (B % 2 == 1) B--;
      B /= 2;
      A += B;
    }
  }

  cout << A << " " << B << endl;

  return 0;
}


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

#define fi first
#define se second

int main() {
	int chair[17] = {0};
	int ans[100];
	queue<pair<int,int> > customer;

	for(int clock = 0; clock <= 500 || !customer.empty(); clock++) {
		if(!(clock % 5) && clock < 500) {
			if((clock / 5) % 5 == 1)
				customer.push(pair<int,int>(clock / 5, 5));
			else
				customer.push(pair<int,int>(clock / 5, 2));
		}

		bool flg = true;
		while(flg && !customer.empty()) {
			int seq;
			pair<int,int> tmp;
			bool prev;

			flg = false;
			tmp = customer.front();
			seq = 0;
			for(int i = 0; i < 17; i++) {
				if(chair[i] <= clock)
					seq++;
				else
					seq = 0;
				if(seq >= tmp.se) {
					ans[tmp.fi] = clock - 5 * tmp.fi;
					for(int j = 0; j < tmp.se; j++) {
						chair[i - seq  + 1 + j] = 17 * (tmp.fi % 2) + 3 * (tmp.fi % 3) + 19 + clock;
					}
					customer.pop();
					flg = true;
					break;
				}
			}
		}
	}

	int q;
	while(cin >> q) {
		cout << ans[q] << endl;
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c>>d;
    ans=(a-c)*(b-d);
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,b;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  b=accumulate(a.begin(),a.end(),0);
  
  if(b-a.at(N-1)>a.at(N-1))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

 static const int N=100;

int min(int a,int b){return a < b ? a : b;}

int main(){
  int i,j,k,l,v;
  int n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=0;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
	v=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }
  /*  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%4d",m[i][j]);
    }
    printf("\n");
    }*/
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2056