akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
	long long N;
	scanf("%lld",&N);
	int h,n;
	long long w;
	long long s;
	long long k;
	for(h=1;h<=3500;h++){
		for(n=h;n<=3500;n++){
			s=N*h*n;
			k=4*h*n-N*n-N*h;
			if(k>0&&(s%k)==0){w=s/k;goto A;}
		}
	}
	A:
	printf("%d %d %lld",h,n,w);
	return 0;
}

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

int main()
{
    int a[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
        }
    }
    int x[3],y[3];
    for(int i=0; i<3; i++){
        x[i] = a[0][i];
    }
    for(int i=0; i<3; i++){
        y[i] = a[i][0] - x[0];
    }
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if(x[j]+y[i] != a[i][j]){
                cout <<"No" << endl;
                return 0;
            }
        }
    }
    cout <<"Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
/*
数え上げpdfを読んで
３条件を満たせば全て作れる
・各桁の和がM以下
・1から引いたやつの各桁の和がN以下
・各桁の和はM-a(K-1)
この3つを満たせばいいのはどうして？
3つ目の条件と同じ数になるように最初に1を消してしまうことは出来るし、0も同じようにして減らせる
そうしたら各桁に対してそれを集めてそれとぎゅってすればおっけー
たとえば0.304が作りたかったらまず1を7個、0を3K-9個にした後、1を4個と0をK-4個でぎゅってして、
出来た0.4と0をK-1個でぎゅってして、出来た0.04と1を3個と0をK-4個ぎゅってすればオッケー
*/
int dp[5010][5010];
//main
signed main(){
  int N,M,K;cin>>N>>M>>K;
  std::vector<int> w(5015,0);
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<=5000;i++){
    for(int j=0;j<=5000;j++)w[j+1]=(w[j]+dp[i][j])%MOD;
    for(int j=0;j<=5000;j++)dp[i+1][j]=(w[j+1]-w[max(0LL,j-(K-1))]+MOD)%MOD;
  }
  int ans=0;
  for(int i=0;i<=5000;i++){
    for(int j=1;j<=5000;j++){
      if(M-j>=0&&(M-j)%(K-1)==0&&i*(K-1)+1-j==N)ans+=dp[i][j];
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  sort(P.begin(),P.end());
  for(int i=0;i<K;i++){
    sum+=P.at(i);
  }
  cout << sum << endl;
}
  

Measured memory_bytes: 3628
import numpy as np
N, K =map(int, input().split())
X = [int(_) for _ in input().split()]
X2 = np.zeros((N,))
X2 += X
minus = X2[X2 < 0] * (-1)
minus.sort()
plus = X2[X2 >= 0]
lenM, lenP = len(minus), len(plus)

def length(i, j):
    if i == 0:
        return plus[j-1]
    if j == 0:
        return  minus[i-1]
    else:
        LtoR = min(minus[i-1], plus[j-1])
        return plus[j-1] + minus[i-1] + LtoR

minLength = 1000000000
for i in range(0, K+1):
    a, b = i, K-i
    if lenM >= a and lenP >= b :
        minLength = min(minLength, length(a, b))

print(int(minLength))

Measured memory_bytes: 23072
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define ll long long

bool d(int i) {
	int num = 0;
	for (int k = 1; k <= i; k++) {
		if (i % k == 0)num++;
	}
	if (num == 8)return true;
	else return false;
}

int main() {
	int k, n, hoge;
	string s;
	cin >> s >> k;
	bool f = true;
	for (int i = 0; i < k; i++) {
		if (s[i] != '1') {
			f = false;
			hoge = i;
			break;
		}
	}
	if (s[0] != '1')cout << s[0] << endl;
	else if (f) cout << 1 << endl;
	else cout << s[hoge] << endl;
	return 0;
}

Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 1e6 + 5;
const int M   = 1e9 + 7;
ll F[N],G[N];

ll power_mod(ll a,ll n){
	ll ret = 1;
	while(n){

		if(n&1) ret = ret * a % M;
		a = a*a%M;

		n>>=1;
	}
	return ret;
}

int main(){
	
	F[0] = G[0] = 1;
	for(int i=1;i<N;i++){
		F[i] = F[i-1] * i % M;
		G[i] = power_mod(F[i],M - 2);
	}

	int x,y;
	cin>>x>>y;
	if((x+y)%3){
		cout<<0<<endl;
		return 0;
	}
	int n = (x+y)/3;
	int u = x - n,v = y - n;
	if(u<0 or v<0){
		cout<<0<<endl;
		return 0;
	}


	ll ret = F[n] * G[u] % M * G[v]%M;

	cout<<ret<<endl;
	

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }
        for(int i = 0; i < N-1; i++){
        cin >> C.at(i);
    }

    int satisfy_sum = B.at(A.at(0)-1);
    for(int i = 1; i < N; i++){
        int Bnum = A.at(i) - 1;
        satisfy_sum += B.at(Bnum);
        if( i < N && A.at(i) == A.at(i-1)+1){
            satisfy_sum += C.at(A.at(i-1)-1);
        }
        // cout << satisfy_sum << endl;
    }
    cout << satisfy_sum << endl;
}

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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string s;
	cin >> s;
	vector<int> ans(N);
	// 4ways to think
	// SS SW WS WW
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			vector<int> res;
			res.push_back(i);
			res.push_back(j);
			for(int k=0;k<N;k++){
				if(s[k]=='o')res.push_back(res[k]^res[k+1]);
				else res.push_back(res[k]^res[k+1]^1);
			}
			if(res[N] == i && res[N+1] == j){
				for(int l=1;l<=N;l++){
					cout << (res[l]? 'W': 'S');
				}
				cout << endl;
				return 0;
			}
		}
	}
	puts("-1");
}

Measured memory_bytes: 1732
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    char a[300]= {0},b[300]= {0};
    int i,j;
    while(cin>>a>>b)
    {
        int len=strlen(a);
        int len1=strlen(b);
        int sum=0;
        if(len==len1)
        {
            for (i=0,j=len1-1; i<len; i++,j--)
            {
                if (b[j]!=a[i])
                    break;
                sum++;
            }
        }
        if (sum==len)
            printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include<cstring>
using namespace std;
const int maxn=100001;
int f[maxn];
int d[maxn];
int find(int x)
{
    if(f[x]==x)
        return x;
    int r=find(f[x]);
    d[x]=d[f[x]]+d[x];
    return f[x]=r;
}


int fix(int x,int y,int z)
{
    int fx=find(x);
    int fy=find(y);
    if(fx==fy)
     return z==d[y]-d[x];
    f[fy]=fx;
    d[fy]=d[x]+z-d[y];
    return 1;
}

int main()
{
    int n,m;
    int flag=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        f[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        if(flag)
            flag=fix(x,y,z);
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef priority_queue <ll> pqb;
typedef priority_queue <ll, vector<ll>, greater<ll>> pqs;
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  
 
inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}

bool cmp(pll a,pll b)
{
  ll as=a.ff-a.ss;
  ll bs=b.ff-b.ss;
    return (as>bs);
}

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

vl v[100005];
bool vis[100005];

int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   	string s,t;
   	cin>>s>>t;
   	ll n=s.length();
   	ll m=t.length();
   	ll dp[n+1][m+1];
   	memset(dp,0,sizeof dp);
   	for(ll i=1;i<=n;i++){
   		for(ll j=1;j<=m;j++){
   			if(s[i-1]==t[j-1]){
   				dp[i][j]=dp[i-1][j-1]+1;
   				//ans[i][j]+=t[j-1];
   			}
   			else{
   				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
   			}
   		}
   		//cout<<ans<<endl;
   	}
   	string ans;
   	ll i=n;
   	ll j=m;
   	while(i>=1 && j>=1){
   		if(dp[i][j]==dp[i-1][j]){
   			i--;
   		}
   		else if(dp[i][j]==dp[i][j-1]){
   			j--;
   		}
   		else{
   			ans+=s[i-1];
   			i--;
   			j--;
   		}
   	}
   	REVERSE(ans);
   	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 76340
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
  		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] ans = new int[n];
		Arrays.fill(ans, 0);
		for(int i = 0; i < m; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			a--;b--;
			ans[a]++;
			ans[b]++;
		}
		
		sc.close();
		
		for(int i = 0; i < n; i++){
			out.println(ans[i]);
		}
		out.flush();
	}

	static class Pair{
		int a,b;
		public Pair(int a, int b){
			this.a = a;
			this.b = b;
		}
	}
}

Measured memory_bytes: 23124
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n = readln.strip.to!int;
  auto s = readln.strip;
  foreach (c; s) {
    auto i = c.to!int - 65;
    i = (i + n) % 26;
    write((65+i).to!char);
  }
  writeln;
}



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

int cnt;

void insertionSort(vector<int> &v, const int g) {
	int work, k, size = v.size();
	for (int i = g; i < v.size(); ++i) {
		work = v[i];
		k = i - g;
		while (k >= 0 && v[k] > work) {
			v[k + g] = v[k];
			k -= g;
			++cnt;
		}
		v[k + g] = work;
	}
}

void shellSort(vector<int> &v) {
	vector<int> G;
	cnt = 0;
	
	for (int i = 1;;) {
		if (i > v.size()) break;
		G.push_back(i);
		i = 3 * i + 1;
	}
	cout << G.size() << endl;

	reverse(G.begin(), G.end());

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		cout << *itr;
		if (itr != G.end() - 1) cout << " ";
	}
	cout << endl;

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		insertionSort(v, *itr);
	}
}

int main() {
	int n;
	vector<int> v;

	cin >> n;

	v.resize(n);

	for (int i = 0; i < v.size(); ++i)
		scanf("%d", &v[i]);

	shellSort(v);
	cout << cnt << endl;

	int size = v.size();
	for (int i = 0; i < size; ++i) {
		cout << v[i];
		if (i != size - 1)  cout << endl;
	}
	return 0;
}



Measured memory_bytes: 6732
import sys
s = raw_input()

ss = s.replace("x","")

if(ss == ss[::-1]):
    pass

else:
    print "-1"
    sys.exit()


count = 0

right = 0
left = len(s)-1

for i in range(len(s)*2):

    if ( s[right] != s[left]):
        count += 1
        if(s[right]!="x"):
            right -= 1

        else:
            left += 1
            
    right += 1
    left -= 1
    if(right>=left):
        print count
        sys.exit()




Measured memory_bytes: 11140
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    for (;;) {
        auto wh = readln.split.to!(int[]);
        auto w = wh[0];
        auto h = wh[1];
        if (w == 0 && h == 0) return;

        auto MAP = new int[][](h, w);
        foreach (i; 0..h) {
            foreach (j, n; readln.split.to!(int[])) MAP[i][j] = n;
        }

        int c = 1;
        foreach (j; 0..w) foreach (i; 0..h) if (MAP[i][j] == 1) {
            ++c;
            void go(int x, int y) {
                MAP[y][x] = c;
                foreach (dx; [-1,0,1]) foreach (dy; [-1,0,1]) {
                    auto xx = x+dx;
                    auto yy = y+dy;
                    if (xx < 0 || xx >= w || yy < 0 || yy >= h || MAP[yy][xx] != 1) continue;
                    go(xx, yy);
                }
            }
            go(j, i);
        }
        writeln(c-1);
    }
}


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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        String[] A = br.readLine().split(" " , n);
        String[] B = A.clone();

        //BubbleSort 
        for(int i=0; i<A.length; i++){
            for(int j=A.length-1; j>i; j--){
                if(A[j].charAt(1)<A[j-1].charAt(1)){
                    swap(A, j, j-1);
                }
            } 
        }
        printArray(A);
        System.out.println("Stable");

        //SelectionSort
        for(int i=0; i<B.length; i++){
            int min_i = i;
            for(int j=i+1; j<B.length; j++){
                if(B[j].charAt(1)<B[min_i].charAt(1)){
                    min_i = j;
                }
            }
            if(min_i!=i) swap(B, i, min_i);
        }
        String judge = Arrays.equals(A,B)?"Stable":"Not stable";
        printArray(B);
        System.out.println(judge);
    }

    static void printArray(String[] A){
    	StringBuilder sb = new StringBuilder();
        for(String k : A){
            sb.append(k + " ");
        }
        System.out.println(sb.toString().substring(0 , sb.length() - 1));
    }

    static void swap(String[] A, int i, int j){
    	String k = A[i];
        A[i] = A[j];
        A[j] = k;
    }
}



Measured memory_bytes: 24500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N,K;cin >> N >> K;
    double ans = 0;
    Rep(i,N){
        double tmp = (double)i;
        int count = 0;
        while(tmp<K){
            tmp *= 2;
            count++;
        }
        // cout << count << " " << pow(0.5, count) << endl;
        if(count>0)ans += (double)((double)(1.0/(double)N) * pow(0.5, count));
        else ans += (double)(1.0/(double)N);
    }
    printf("%0.12f\n", ans);
    return 0;
}

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

int main() {
  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  int distance = abs(a-b);
  
  if (v <= w) {
    cout << "NO" << endl;
    return 0;
  }
  
  long long shortened = (v - w) * t;
  if (distance <= shortened) {
    cout << "YES" << endl;
  } else cout << "NO" << endl;
  
  return 0;
}

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

main :: IO()
main = do
  [n, k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  hs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length $ filter (>= k) hs

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> a;
    inputVector(a, N);

    sort(all(a));

    bool allEven = true;

    for (int num : a) {
        allEven &= num % 2 == 0;
    }

    cout << (allEven ? "second" : "first") << endl;

    return 0;
}


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

int main()
{
    int n;
    long long sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        if((i%5!=0)&&(i%3!=0))
            sum+=i;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>

#define MAX 1000000
#define sqrtMAX 1000

int main(void)
{
  int n;
  int b[MAX+1] = {0};
  int i, j;
  int sum;
  int count;

  // ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
  b[0] = 1;
  b[1] = 1;
  for(i=4; i<=MAX; i+=2)
      b[i] = 1;
  for(i=3; i<=sqrtMAX; i+=2)
      for(j=i+i; j<=MAX; j+=i)
          b[j] = 1;

  while(scanf("%d", &n)!=EOF) {
      if(n == 0)
          break;
      sum = 0;
      count = 0;
      for(i=2; count<n; i++) {
        if(b[i]==0) {
              count++;
              sum+=i;
        }
      }
      printf("%d\n", sum);
    }
  return 0;
}

Measured memory_bytes: 0
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
// const int N = 1e5 + 5 ;
const int mod = 1e9 + 7 ;
// const int N = 1e5 + 5 ;

ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}






int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {
	int n ;
	cin >> n ;
	vector<int> h(n), dp(n , mod) ;
	for (int i = 0 ; i < n ; i++) {
		cin >> h[i] ;
	}
	dp[0] = 0 ;
	for (int i = 0 ; i < n ; i++) {
		if (i + 1 < n ) {
			dp[i + 1] = min(dp[i + 1] , dp[i] + abs(h[i] - h[i + 1])) ;
		}
		if (i + 2 < n) {
			dp[i + 2] = min(dp[i + 2] , dp[i] + abs(h[i] - h[i + 2])) ;
		}
	}
	cout << dp[n - 1] <<  "\n";



// }



	return 0 ;
}





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

int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    printf("%d %d %f\n",d,r,f);
    return 0;
}


Measured memory_bytes: 3204
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n; cin >> n;
  vector<ll> A(n+1), B(n);
  loop(i,0,n+1) cin >> A[i];
  loop(i,0,n) cin >> B[i];
  ll cnt = 0;
  ll b = B[n-1];
  ll &a = A[n];
  ll &a2 = A[n-1];
  ll d = min(b, a);
  cnt += d;
  a -= d;
  b -= d;
  ll d2 = min(b, a2);
  a2 -= d2;
  cnt += d2;
  
  loop(i,0,n-1) {
    ll b = B[i];
    ll &a = A[i];
    ll &a2 = A[i+1];
    ll d = min(b, a);
    a -= d;
    b -= d;
    cnt += d;
    ll d2 = min(b, a2);
    a2 -= d2;
    cnt += d2;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4844
a,b,c,d=map(int,input().split())
if d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
else:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c+1
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//cd+1  
print(b-a+1-c2-d2+cd2)


Measured memory_bytes: 3444
N,K = map(int,input().split())
D = []
A = []
for k in range(K):
    D.append(int(input()))
    A.append([int(i) for i in input().split()])
P = [True for i in range(N)]
for a in A:
    for aa in a:
        P[aa-1] = False
print(sum(P))

Measured memory_bytes: 9144
#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++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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() {
    int s, w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    lli cnt[N + 1];
    fill(cnt, cnt + N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        cnt[a[i]]++;
    }
    lli tmp = 0;
    lli total = 0;
    for (int i = 0; i <= N; i++)
    {
        total += (cnt[i] * (cnt[i] - 1)) / 2;
    }
    for (int i = 0; i < N; i++)
    {
        tmp = total;
        tmp -= (cnt[a[i]] * (cnt[a[i]] - 1)) / 2;
        tmp += ((cnt[a[i]] - 1) * (cnt[a[i]] - 2)) / 2;
        cout << tmp << endl;
    }
    return 0;
}


Measured memory_bytes: 5904
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
class SegTree {
  constexpr static int DEFAULT = INT_MAX;
  int Combine(int l, int r) { return min(l,r); }

  vector<int> seg_tree;
  int n = 0;

  void Build(vector<int>& A, int v, int tl, int tr) {
    if (tl == tr) {
      seg_tree[v] = A[tl];
    } else {
      int tm = tl + (tr - tl) / 2;
      Build(A, v*2, tl, tm);
      Build(A, v*2+1, tm+1, tr);
      seg_tree[v] = Combine(seg_tree[v*2], seg_tree[v*2+1]);
    } 
  }
 public:

  SegTree(vector<int>& A) {
    n = A.size();
    seg_tree.resize(4*n);
    Build(A, 1, 0, n-1);
  }

  SegTree(int _n) : n(_n) {
    //seg_tree.resize(4*n);
    seg_tree.resize(4*n, DEFAULT);
  }

  int Query(int l, int r, int tl, int tr, int v) {
    if (l > r) return DEFAULT;
    if (l == tl && r == tr) return seg_tree[v];
    int tm = tl + (tr - tl) / 2;
    return Combine(Query(l, min(r, tm), tl, tm, v*2), 
                   Query(max(l, tm+1), r, tm+1, tr, v*2+1));
  }

  int Query(int l, int r) {
    return Query(l, r, 0, n-1, 1);
  }

  void Update(int pos, int new_val, int tl, int tr, int v) {
    if (tl == tr) {
      seg_tree[v] = new_val;
      return;
    }

    int tm = tl + (tr - tl) / 2;
    if (pos <= tm) {
      Update(pos, new_val, tl, tm, v*2);
    } else {
      Update(pos, new_val, tm+1, tr, v*2+1);
    }
    seg_tree[v] = Combine(seg_tree[v*2], seg_tree[v*2+1]);
  }

  void Update(int pos, int new_val) {
    Update(pos, new_val, 0, n-1, 1);
  }
};

 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  vector<int> A(n);
  for (auto& _a : A) cin >> _a;
  SegTree stree(A);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (stree.Query(0, i) == A[i]) ++ans;
  }
  cout << ans << endl;
  

}


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

int main()
{
  int a, b;
  cin >> a >>  b;

  if(a*b%2==0) cout << "Even" << endl;
  else cout << "Odd" << endl;

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	double a;
	while(cin >> a)
	{
		double sum = 0;
		for(int i = 0; i < 10; ++i)
		{
			sum += a;
			if(i % 2 == 0)
			{
				a *= 2;
			}
			else
			{
				a /= 3;
			}
		}
		printf("%.8f\n", sum);
	}
}

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

Measured memory_bytes: 0
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)

	val a, b, c = sc.nextInt
	
	pw.println(if (Seq(a, b, c).distinct.size == 2) "Yes" else "No")
	pw.flush()
}

Measured memory_bytes: 27320
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

# まず重複する数字を探す
start = -1
end = -1
checker = {}
for i in range(len(A)):
  if A[i] not in checker:
    checker[A[i]] = i
  else:
    end = i
    start = checker[A[i]]
    break
    
# 1 2 3 4 3 5 6
# について、全組み合わせから、1 2 [3 4 3] 5 6のように同じ数で囲まれた部分を一個と見做した
# 区間での組み合わせを引く
L = (N + 1) - (end - start)  # 短くした区間の長さ
    
DIV = 10 ** 9 + 7
n = (10 ** 6) * 2 # PyPyじゃないと通らない。 * 5が限界くらい
g1 = [1] * 2 + [0] * (n - 2) # 元テーブル
g2 = [1] * 2 + [0] * (n - 2) #逆元テーブル
inverse = [0, 1] + [0] * (n - 2) #逆元テーブル計算用テーブル

for i in range(2, n):
  g1[i] = (g1[i - 1] * i) % DIV
  inverse[i] = (-inverse[DIV % i] * (DIV // i)) % DIV
  g2[i] = (g2[i - 1] * inverse[i]) % DIV

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

for k in range(1, N + 2):
  if k == 1:
    print(N)
  elif L - 1 >= k - 1:
    print((nCr(N + 1, k, DIV) - nCr(L - 1, k - 1, DIV)) % DIV)
  else:
    print(nCr(N + 1, k, DIV))

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

using namespace std;

#define endl '\n'
typedef long long ll;
const int mod = 1e9 + 7;

ll pot(ll a,ll b){
  ll ans = 1;

  while(b){
    if(b & 1){
      ans = ans * a % mod;
    }
    b = b >> 1;
    a = a*a % mod;
  }

  return ans;
}

int main(){

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

 
  int n;
  cin >> n;
  map <pair <ll,ll>, pair <ll,ll> > mp;

  int pair_zeros = 0;

  while(n--){
    ll a, b;
    cin >> a >> b;
    if(a == 0 && b == 0)
      pair_zeros++;
    else if(a == 0 && b)
      mp[{0,1}].first++;
    else if(a && b == 0)
      mp[{0,1}].second++;
    else{
      int neg = 0;
      if(a < 0)
        a=-a,neg++;
      if(b < 0)
        b=-b,neg++;

      ll mdc = __gcd(a,b);
      a/=mdc;
      b/=mdc;

      if(neg == 1)
        mp[{a,b}].second++;
      else
        mp[{b,a}].first++;
    }

  }

   ll ans = 1;

    for(auto it=mp.begin();it!=mp.end();it++){
      ll x = it->second.first;
      ll y = it->second.second;
      ll prod = (((pot(2,x) + pot(2,y) - 1)%mod)+mod)%mod;
      ans = (((ans * prod)%mod)+mod)%mod;
    }

    ans = (((ans + pair_zeros -1)%mod)+mod)%mod;

    cout << ans << endl;

  return 0;
}

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

int main(){
    string x;
    int a[26]{0};
    getline(cin,x);
    while(x.size()>0){     
        for(int i = 0;i<x.size();i++){
            int k = 0;
            if(x[i] >= 'a' && x[i] <= 'z'){
                k = x[i] - 'a';
                a[k] += 1;
            }else if(x[i] >= 'A' && x[i] <= 'Z'){
                k = x[i] - 'A';
                a[k] += 1;
            }        
        }
        getline(cin,x);
    }
    for(int i = 0;i<26;i++){
        char temp = 'a'+i;
        cout<<temp<<" : "<<a[i]<<endl;
    }
    return 0;
}


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

struct Edge{
	int src, dst, weight;
	Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) { }
};

typedef vector<Edge> Node;
typedef vector<Node> Graph;


int N, M;
Graph graph;
vector<int> weights;

void dfs(int minw, int maxw, bool arr[100], int idx){
	if(arr[idx]) return;
	arr[idx] = true;
	for(auto e : graph[idx]){
		if(minw <= e.weight && e.weight <= maxw){
			dfs(minw, maxw, arr, e.dst);
		}
	}
}

bool connect(int minw, int maxw){
	bool arr[100];	
	for(int i = 0; i < N; i++) arr[i] = false;
	dfs(minw, maxw, arr, 0);
	int cnt = 0;
	for(int i = 0; i < N; i++) cnt += arr[i];
	return cnt == N;
}

int main(){
	while(cin >> N >> M, N){
		graph.assign(N, Node());
		weights.clear();
		//for(int i = 0; i < N; i++){
		//	graph.push_back(Node());
		//}
		for(int i = 0; i < M; i++){
			int a, b, w;
			cin >> a >> b >> w;
			a--; b--;
			graph[a].push_back(Edge(a, b, w));
			graph[b].push_back(Edge(b, a, w));
			weights.push_back(w);
		}
		sort(weights.begin(), weights.end());
		weights.erase(unique(weights.begin(), weights.end()), weights.end());

		int left = -1;
		int right = 10010;
		while(right - left > 1){
			int m = (left + right) / 2;
			bool flg = false;
			for(int v : weights){
				if(connect(v, v + m)){
					flg = true;
					break;
				}
			}
			if(flg){
				right = m;
			}else{
				left = m;
			}
		}
		if(right == 10010){
			cout << -1 << endl;
		}else{
			cout << right << endl;
		}
	}
}

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

char b[10];

signed main(){
	long long a;
	cin>>a>>b;
	
	long long b2;
	b2=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
	
	long long z=a*b2/100;
	
	cout<<z<<endl;
	
	return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

int solve(int N, vi& a) {
    int cnt=1;
    int type=0,val=a[0];
    rep1(i, N-1){
        if (a[i] == val) continue;
        if (a[i] > val && type >= 0) {
            val = a[i]; type = 1;
        }
        else if (a[i] < val && type <= 0) {
            val = a[i]; type = -1;
        }
        else {
            val = a[i]; type = 0; ++cnt;
        }
    }
    return cnt;
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<complex>
#include<cstdio>
#include<cmath>
using namespace std;
typedef complex<double> P;
double F(double a,double b,double c){
	return acos((b*b+c*c-a*a)/(2*b*c));
}
int main(){
	int n;
	double d,e,f,g,h,i,x,y,r;
	scanf("%d",&n);
	for(;n--;){
		scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);
		P a(d,g),b(e,h),c(f,i);
		double A=abs(b-c),B=abs(c-a),C=abs(a-b),s=F(A,B,C),t=F(B,C,A),u=F(C,A,B);
		r = A/sin(s)/2.;
		x = ( d*sin(2*s) + e*sin(2*t) + f*sin(2*u) ) /
			( sin(2*s) + sin(2*t) + sin(2*u) );
		y = ( g*sin(2*s) + h*sin(2*t) + i*sin(2*u) ) /
			( sin(2*s) + sin(2*t) + sin(2*u) );
		printf("%.3f %.3f %.3f\n",x,y,r);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> p(n);
	for(int i = 0; i < n; i++) scanf("%d", &p[i]);
	
	std::vector<int> vec = p; sort(begin(vec), end(vec));
	for(int i = 0; i < n; i++) {
		for(int j = i; j < n; j++) {
			std::swap(p[i], p[j]);
			if(vec == p) {
				printf("YES\n");
				return 0;
			}
			std::swap(p[i], p[j]);
		}
	}
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    lint H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    }
    else 
        cout << (H * W + 1) / 2 << endl;
    return 0;
};

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;



int main()
{   IOS;
cout.precision(30);
    ll n;
    cin >> n;
    vector<ll> L(n,0);
    bool B=true;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        L[i]=x;

    }
    L[0]-=1;
    for(ll i=1;i<n;i++)
    {
        if (L[i]>L[i-1])
            L[i]-=1;

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

        }
    }

        cout << "Yes";



    return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().strip().split()))

count = 0
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            count += 1
        else:
            print('DENIED')
            exit()

print('APPROVED')

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

const int MAXN = 3010;

string s,t;
int dp[MAXN][MAXN],N,M;
stack<char> resposta;

int solve(int a,int b){

	if(a < 0 || b < 0) return 0;

	if(dp[a][b] != -1) return dp[a][b];

	if(s[a] == t[b]) return dp[a][b] = 1 + solve(a-1,b-1);

	return dp[a][b] = max(solve(a-1,b),solve(a,b-1));

}

void build(int a,int b){

	if(a < 0 || b < 0) return;

	if(s[a] == t[b]){
		resposta.push(s[a]);
		build(a-1,b-1);
		return;
	}

	if(solve(a-1,b) > solve(a,b-1)) build(a-1,b);
	else build(a,b-1);

}

int main(){

	memset(dp,-1,sizeof(dp));

	cin >> s;
	cin >> t;

	N = (int)s.size();
	M = (int)t.size();

	build(N-1,M-1);

	while(!resposta.empty()){
		cout << resposta.top();
		resposta.pop();
	}
	cout << endl;

	return 0;

}

Measured memory_bytes: 35968
#include <iostream>
#include <algorithm>
using namespace std;
int n, r[1009], w[1009]; bool dp[1009];
int main() {
	while (cin >> n, n) {
		int sumr = 0, sumw = 0, maxr = 0, maxptr = 0;
		for (int i = 0; i < n; i++) {
			cin >> r[i] >> w[i];
			sumr += r[i];
			sumw += w[i];
			if (r[i] >= r[maxptr]) {
				maxptr = i;
				maxr = r[i];
			}
		}
		if (maxr * 2 <= sumr) {
			cout << sumr + sumw << endl;
		}
		else {
			fill(dp, dp + maxr * 2 - sumr + 1, false); dp[0] = true;
			int res = 0;
			for (int i = 0; i < n; i++) {
				if (i == maxptr) continue;
				for (int j = maxr * 2 - sumr; j >= w[i]; j--) {
					if (dp[j - w[i]]) {
						dp[j] = true;
						res = max(res, j);
					}
				}
			}
			cout << max(maxr * 2 + sumw - res, maxr * 2) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {
  string n;
  cin >> n;
  
  bool flag = false;

  rep(i, 3) {
    if (n[i] == '7') flag = true;
  }

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

using namespace std;

int main(){
	string S; cin>>S;
	
	unsigned long long num;
	num=S[9]-'0'+(S[8]-'0')*10+(S[6]-'0')*100+(S[5]-'0')*1000+(S[3]-'0')*10000+(S[2]-'0')*100000+(S[1]-'0')*1000000+(S[0]-'0')*10000000;

	if(num<=20190430)cout<<"Heisei"<<endl;
	else cout<<"TBD"<<endl;

	return 0;
}


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

using namespace std;

#define all(v) v.begin(), v.end()
#define F first
#define S second
#define FOR(i, n) for(int i = 0; i < (int) n; i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

	int n; cin >> n;
	string s = to_string(n);
	vector<string> v;
	for(int i = 1; i <= n; i++)
		v.push_back(to_string(i));
	
	ll ans = 0;
	int m[10][10] = {0};
	for(int i = 1; i <= n; i++){
		char comeca = v[i-1].back(), termina = v[i-1].front();
		m[comeca-'0'][termina-'0']++;
	}

	for(int i = 1; i <= n; i++){
		char comeca = v[i-1].back(), termina = v[i-1].front();
		ans += m[termina-'0'][comeca-'0'];
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 11248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,x,mn,ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>x;
    mn = INT_MAX;
    for(int i=1;i<=n;i++){
        int temp;cin>>temp;
        mn = min(mn,temp);
        ans++; x-=temp;
    }
    while(x>0){
        if(x-mn >= 0){ans++;x-=mn;}
        else{break;}
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <cstdio>

/*
max(N- [x2, ..., xN] [ 1 2 3 4 ... 4 3 2], 0)

(1 + z + z^2 + ... + z^N) (1 + z^2 + z^4 + ... + z^{2N}) ...
f(z) = 1/[(1-z){(1-z^2)(1-z^3)...(1-z^{N/2})}^2]


[z^N] (N f(z) - z * f'(z))/(1-z)
[z^N] (f(z)(N - z * f'(z)/f(z)))/(1-z)

f'(z)/f(z) = 1/(1-z) + 2(2z/(1-z^2) + 3z^2/(1-z^3) + ...

log f = \sum_{i=2}^{N/2}

f(z) = (1-z)(1-z^{N/2+1})^2(1-z^{N/2+2})^2... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1})(1-2z^{N/2+2})... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1}-2z^{N/2+2}-...) / [(1-z)(1-z^2)...]^2
f(z) = (1-z-2z^{N/2+1}) / [(1-z)(1-z^2)...]^2

f(z) = 1/[(1-z)(1-z^2)(1-z^3)...(1-z^{N/2})]^2
f(z) = (1-2z^{N/2+1} - ... )/[(1-z)(1-z^2)...]^2
*/

int n, m;

int dp[5001];

int main(){
  scanf("%d%d", &n, &m);

/*
  dp[0] = 1;
  dp[1] = m-1;
  dp[(n+1)/2+1] = m-2;

  if(n & 1){
    dp[(n+1)/2] -= 1;
    dp[(n+1)/2+1] += 1;
    if(dp[(n+1)/2] < 0) dp[(n+1)/2] += m;
  }
*/
  dp[0] = 1;
  for(int i = (n+1)/2+1; i <= n; i++) dp[i] = m-2;
  if(n & 1){
    for(int j = (n+1)/2; j <= n; j++){
      dp[j] -= dp[j-(n+1)/2];
      if(dp[j] < 0) dp[j] += m;
    }
  }

  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }
  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }

/*
  for(int i = 0; i <= n; i++) dp[i] = 1;
  for(int i = 2; i <= n/2; i++){
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
 

  if(n & 1){
    for(int j = (n+1)/2; j <= n; j++){
      dp[j] += dp[j-(n+1)/2];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
*/

  long long int c = 0;
/*
  for(int i = 0; i <= n; i++){
    c = (c + (long long) (n - i) * dp[i]) % m;
  }
*/
  for(int i = 0; i < n; i++){
    c += dp[i];
  }

  printf("%d\n", (int) (c % m));

  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();

		Map<Integer, List<Long>> dic = new HashMap<>();
		List<Pair> toi = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			int x = sc.nextInt();
			long y = sc.nextLong();
			toi.add(new Pair(x, y));
			List<Long> list = dic.getOrDefault(x, new ArrayList<>());
			list.add(y);
			dic.put(x, list);
		}

		Map<Integer, Long[]> sortDic = new HashMap<>();
		dic.entrySet().stream().forEach(e -> {
			Long[] tmp = e.getValue().toArray(new Long[e.getValue().size()]);
			Arrays.sort(tmp);
			sortDic.put(e.getKey(), tmp);
		});

		for (int i = 0; i < toi.size(); i++) {
			Pair mon = toi.get(i);
			String x = String.valueOf(mon.x);
			String paddingleft = x.format("%6s", x).replace(" ", "0");
			String index = String.valueOf(Arrays.binarySearch(sortDic.get(mon.x), mon.y) + 1);
			String paddingRight = index.format("%6s", index).replace(" ", "0");
			out.println(paddingleft + paddingRight);
		}
		out.flush();

	}

	static class Pair {
		public int x;
		public long y;

		public Pair(int x, long y) {
			this.x = x;
			this.y = y;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 179960