akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long min = n-1;
            for (int i = 1; i<=1000000 ; i++) {
                if ((n%i)==0) if (min>i+n/i-2) min = i+n/i-2;
            }
            out.println(min);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 10);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public Long nextLong() { return Long.parseLong(next()); }


    }

}


Measured memory_bytes: 24916
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <list>
using namespace std;

int main(){
    list <int> stack;
    list <int>::iterator begin,end; //begin to end hutatu no iterator wo sakusei
    int n,x;
    string str;
    cin>>n;
    for(int i=0;i<n; i++){
        cin>>str;
        if(str=="insert"){
            cin>>x;
            stack.push_front(x);
        }
        else if(str=="delete"){
            cin>>x;
            for(begin=stack.begin(),end=stack.end();begin!=end;++begin){
                if(*begin==x){
                    stack.erase(begin);
                    break;
                }
            }
        }
        else if(str=="deleteFirst"){
            stack.pop_front();
        }
        else{
            stack.pop_back();
        }

    }
    for(begin=stack.begin(),end=--stack.end();begin!=end;++begin){
        cout<<*begin<<" ";
    }
    cout<<*begin<<endl;

}


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

using namespace std;

typedef long long int lint;

string numbers[10004];
int ten[10];

int main() {

    int k;
    int n;
    cin >> n >> k;
    for(int i=0; i<k; i++){
        int x;
        cin >> x;
        ten[x] = 1;
    }




    for(int i=n; ; i++){
        int checknum = i;
        while(checknum){
            if(!ten[checknum%10]){
                checknum = checknum/10;
            }else{
                break;
            }
        }
        if(!checknum){
            cout << i;
            return 0;
        }
    }













    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll ans=0,n,a[30],b[30],c[30];

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	reg(i,1,n)cin>>b[i];
	reg(i,1,n-1)cin>>c[i];
}

int main(void){
	init();
	ll bf=-1;
	rep(i,n){
		ans+=b[a[i]];
		if(bf!=-1 && bf+1==a[i]){
			ans+=c[bf];
		}
		bf=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

ll dig(ll n){
    ll x=0;
    while(n>0){
        x++;
        n /= 10;
    }
    return x;
}

int main(){
    ll n;
    cin >> n;
    ll ans=10000;
    for(int i=0;i<dig(n)-2;i++){
        ll a=n;
        rep(j,i){
            a /= 10;
        }
        a %= 1000;
        ans=min(ans,abs(a-753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

long long dp[100001];

using namespace std;

int main(void)
{
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
    {
        long long price, value;
        cin >> price >> value;
        for(int j = k; j >= price; --j)
        {
            dp[j] = max(dp[j], dp[j - price] + value);
        }
    }

    cout << dp[k] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int s;
    cin >> s;
    int MAX = 1000010;
    int a[MAX];
    REP(i, MAX)
    {
        a[i] = 0;
    }
    int i = 1;

    while (1)
    {
        if (a[s] == 1)
        {
            cout << i << endl;
            return 0;
        }
        a[s] = 1;
        if (s % 2 == 0)
        {
            s /= 2;
        }
        else
        {
            s = 3 * s + 1;
        }

        i++;
    }
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,r,c,j,k=0,a[102][102],b[102][102];
    int s=0,col=0,cr[102][102];

    while(scanf("%d%d",&r,&c)!=EOF)
    {
        for(i=0; i<r; i++)
        {
            for(j=0; j<c; j++)
            {
                cin>>a[i][j];
            }
        }
        //row sumation.........
        for(i=0; i<=r; i++)
        {
            for(j=0; j<=c; j++)
            {
                if(j==c )
                {
                    b[i][j]=s;

                }

                else
                {
                    s=s+a[i][j];

                }


                //cout<<"B "<<b[i][j];
                // a[r][c]=sum[i][j];
            }
            s=0;
        }
        //column summation...
        for(i=0; i<=c; i++)
        {
            for(j=0; j<=r; j++)
            {
                if(j==r)
                {
                    cr[j][i]=col;
                    // cout<<"cr "<<cr[i][j];
                }
                else
                {
                    if(i==c)
                    {
                        col=col+b[j][i];
                    }
                    else
                    {
                        col=col+a[j][i];
                    }

                }


                //cout<<"B "<<b[i][j];
                // a[r][c]=sum[i][j];
            }
            col=0;
        }
        //result..........
        for(i=0; i<=r; i++)
        {
            for(j=0; j<=c; j++)
            {

                if(j==c && i!=r)
                {

                    cout<<b[i][j];

                }
                else if(i==r)
                {
                    if(j==c)
                    {
                        cout<<cr[i][j];

                    }
                    else
                    {
                        cout<<cr[i][j]<<" ";

                    }
                }
                else
                {
                    if(j==c)
                    {
                        cout<<a[i][j];
                    }
                    else
                    {
                        cout<<a[i][j]<<" ";

                    }
                }
            }
            cout<<endl;
        }
    }
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string s;
    cin>>s;
    int i;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='7')
            break;
    }
    if(i==s.length())
    {
        cout<<"No\n";
    }
    else
        cout<<"Yes\n";

}


Measured memory_bytes: 3620
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, Q, *query = map(int, read().split())

    N -= 2
    row = [N] * N
    col = [N] * N
    R = C = N

    ans = N * N
    for q, x in zip(*[iter(query)] * 2):
        x -= 2
        if q == 1:
            if x < C:
                ans -= R
                for i in range(x + 1, C):
                    col[i] = R
                C = x
            else:
                ans -= col[x]
        else:
            if x < R:
                ans -= C
                for i in range(x + 1, R):
                    row[i] = C
                R = x
            else:
                ans -= row[x]
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 118476
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int fx = 0;
    int x = N;
    while (x) {
        fx += x % 10;
        x /= 10;
    }

    if (N % fx == 0) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==111)
cout<<"999";
if(n==119)
cout<<"991";
if(n==191)
cout<<"919";
if(n==911)
cout<<"199";
if(n==199)
cout<<"911";
if(n==991)
cout<<"119";
if(n==919)
cout<<"191";
if(n==999)
cout<<"111";
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		sc.close();
		int max = N + L - 1;
		int ans;
		if (max < 0) {
			ans = (L + max - 1) * (N - 1) / 2;
		} else if (L > 0) {
			ans = (L + max + 1) * (N - 1) / 2;
		} else {
			ans = (L + max) * N / 2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] dat = br.readLine().split(" ");
        int r = Integer.parseInt(dat[0]);
        int c = Integer.parseInt(dat[1]);
        StringBuilder out=new StringBuilder();
        int g,p,gg=0;
        String str;
        int[] SumC=new int[c];
        for (int i=0;i<r;i++){
            str =br.readLine();
            dat = str.split(" ");
            g=0;
            for (int j=0;j<c;j++){
                p=Integer.parseInt(dat[j]);
                g += p;
                SumC[j] += p;
            }
            gg+=g;
            out.append(str+" "+g+"\n");
        }
        for (int j=0;j<c;j++) out.append(SumC[j]+" ");
        out.append(gg);
        System.out.println(out);
    }
}

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

int tmp[5][4][11];
int main() {
	int n ; cin >> n ;
	while(n--){
		int b,f,r,v; cin >> b >> f >> r >> v ;
		tmp[b][f][r]+=v;
	}
	for(int i=1;i<=4;++i){
		for(int j=1;j<=3;++j){
			for(int k=1;k<=10;++k){
				cout << ' ' << tmp[i][j][k] ;
			}
			cout << '\n';
		}
		if(i<4){
		for(int j=0;j<20;++j) cout << '#';
		cout << '\n';
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	cout << c-min(a-b,c);
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#!/bin/bash

read line

set -- $line

total_candy=$(( $1 + $2 + $3))

if [ $(( $total_candy % 2 )) -eq 0 ]; then
  if [ $1 -eq $(( $2 + $3 )) ]; then
    echo Yes
    exit
  elif [ $2 -eq $(( $1 + $3 )) ]; then
    echo Yes
    exit
  elif [ $3 -eq $(( $1 + $2 )) ]; then
    echo Yes
    exit
  else
    echo No
  fi
else 
  echo No
fi

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

lint mod;

lint powmod(long x, long n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

vector<lint> fact;
vector<lint> revfact;

void setfact(int n){
  fact.resize(n+1); revfact.resize(n+1);
  fact[0] = 1;
  rep(i, n) fact[i+1] = fact[i] * (i+1) % mod;
  
  revfact[n] = 0;
  revfact[n-1] = powmod(fact[n-1], mod-2);
  for(int i=n-2; i>=0; i--) revfact[i] = revfact[i+1] * (i+1) % mod;
}

lint getP(int n, int r){
    return fact[n] * revfact[n-r] % mod;
}

int main(){
    lint p;
    scanf("%lld", &p);
    lint a[p];
    rep(i, p) scanf("%lld", &a[i]);
    mod = p;
    setfact(p);
    rep(i, p){
        rep(j, i) a[i] = (a[i] - getP(i, j)*a[j]%mod + mod) % mod;
        a[i] = a[i] * revfact[i] % mod;
    }
    lint b[p+1];
    rep(i, p+1) b[i] = 0;
    b[0] = 1;
    rrep(i, p){
        rrep(j, p+1){
            b[j] = b[j] * (p-i) % mod;
            if(j > 0) b[j] = (b[j] + b[j-1]) % mod;
        }
        b[0] = (b[0] + a[i]) % mod;
    }
    b[1] = (b[1] + b[p]) % mod;
    rep(i, p) printf("%lld ", b[i]);
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i=0; i<n; i++) {
    cin >> p.at(i);
  }
  
  vector<int> pla(n);
  for (int i=0; i<n; i++) {
    pla.at(p.at(i)-1) = i+1;
  }
  
  vector<long long> a(n), b(n);
  for (int i=0; i<n; i++) {
    a.at(i) = 20000 * (i+1);
    b.at(i) = 20000 * (n-i) + pla.at(i);
  }
  
  for (int i=0; i<n; i++) {
    cout << a.at(i);
    if (i == n-1) cout << endl;
    else cout << ' ';
  }
  for (int i=0; i<n; i++) {
    cout << b.at(i);
    if (i == n-1) cout << endl;
    else cout << ' ';
  }
  
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string s, t;
  cin >> s >> t;
  for (char i = 'a'; i <= 'z'; i++) {
    if (s + i == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3616
use std::io;

fn main() {
  let stdin = io::stdin();
  let mut buf = String::new();
  for i in 1.. {
    buf.clear();
    stdin.read_line(&mut buf).unwrap();
    let x = buf.trim().parse::<i32>().unwrap();
    if x == 0 { break; }
    println!("Case {}: {}", i, x);
  }
}


Measured memory_bytes: 5032
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main()
{
    int n,m;cin >> n;
    vector<int> LIS(n+2,INF);
    for (int i=0;i<n;i++)
    {
        cin >> m;
        *upper_bound(LIS.begin(),LIS.end(),-m)=-m;
    }
    for (int i=0;i<n+1;i++)
    {
        if (LIS[i]==INF)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 640
A,B,K = map(int,input().split())
a = [A+i for i in range(K) if A+i <= B]
b = [B-K+1+i for i in range(K) if B-K+1+i >= A]
a.extend(b)
a = set(a)
a = [x for x in a]
a.sort()
for i in range(len(a)):
  print(a[i])

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

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

    if (a + b == c || a + c == b || b + c == a) {
        cout << "Yes" <<  endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N - 1), B(N, 0);
  for(int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N - 1; i++) {
    B.at(A.at(i) - 1)++;
  }
  for(int i = 0; i < N; i++) {
    cout << B.at(i) << endl;
  }
}

Measured memory_bytes: 4844
#include <iostream>
#include <array>
#include <vector>

using namespace std;

int main() {
	vector <array <int, 2>> sets;
	array <int, 2> pusher;
	int h = 0;
	int w = 0;
	int counter = 0;

	while (true) {
		cin >> h >> w;
		if ((h == 0) && (w == 0)) {
			break;
		}
		pusher[0] = h;
		pusher[1] = w;
		sets.push_back(pusher);
		counter++;
	}
	for (auto set : sets) {
		for (int i = 0; i < set[1]; i++) {
			cout << '#';
		}
		cout << endl;
		if (set[1] == 1) {
			if (set[0] != 1) {
				for (int i = 0; i < set[0]-1; i++) {
					cout << '#';
					cout << endl;
				}
			}
			cout << endl;
		} else {
			if (set[0] != 1) {
				for (int i = 0; i < set[0]-2; i++) {
					cout << '#';
					for (int a = 0; a < set[1]-2; a++) {
						cout << '.';
					}
					cout << '#';
					cout << endl;
				}
				for (int i = 0; i < set[1]; i++) {
					cout << '#';
				}
				cout << endl << endl;
			}
		}
	}
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int32_t main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
	ll n,xr=0;
	cin>>n;
	
	vector<ll>a(n);
	
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		xr = (xr^a[i]);
	}
	
	for(ll i =0;i<n;i++)
	{
		cout<<(xr^a[i])<<" ";
	}
	return 0;
}



Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	long double count = 0;
	long double p = 0;
	cin >> n >> k;
	int sum;

	REP(i, n){
		sum = i + 1;
		p = 1.0 / (long double)n;
		while(sum < k){
			sum = 2 * sum;
			p = p / 2.0;
		}
		count += p;
	}
	cout << fixed << setprecision(12);
	cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>
#include<set>
#include<queue>

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

using namespace std;


int main(){
	int N; cin >> N;
	vector<int> a;
	rep(i,N){
		int temp; cin >> temp;
		a.push_back(temp - 1);
	}
	int res = 0;
	rep(i,N){
		if(a[a[i]] == i)
			res++;
	}
	cout << res/2 << endl;
}

Measured memory_bytes: 892
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
if c > b > a:
    print('Yes')
    exit()

if a >= b:
    while b <= a:
        b *= 2
        cnt += 1

if b >= c:
    while c <= b:
        c *= 2
        cnt += 1

if cnt <= k:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9188
#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+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

ll f(ll n,ll k){
  return -k*k+k+n*k+1;
}

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  for(ll i=k;i<=n+1;i++){
    ans += f(n,i);
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#print(A)
X = [0 for i in range(N)]
CB = []
for i in range(M):
    b,c = map(int,input().split())
    CB.append([c,b])
CB.sort(reverse=True)
#print(CB)
index = 0
for i in range(M):
    for j in range(CB[i][1]):
        A[index] = max(A[index],CB[i][0])
        if index != N - 1:
            index += 1
            continue
        else:
            print(sum(A))
            exit()
print(sum(A))

Measured memory_bytes: 24892
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var W = input[1];
            input = ReadArrayInt();
            var val = new List<long>[4].Select(x => x = new List<long>()).ToArray();
            long wS = input[0];
            val[0].Add(input[1]);
            for (int i = 1; i < N; i++)
            {
                input = ReadArrayInt();
                val[input[0] - wS].Add(input[1]);
            }
            val = val.Select(x => x = x.OrderByDescending(y => y).ToList()).ToArray();
            var ans = 0L;
            for (int i = 0; i <= val[0].Count; i++)
            {
                long iSum = i != 0 ? val[0].Take(i).Sum() : 0;
                for (int j = 0; j <= val[1].Count; j++)
                {
                    long jSum = j != 0 ? val[1].Take(j).Sum() : 0;
                    for (int k = 0; k <= val[2].Count; k++)
                    {
                        long kSum = k != 0 ? val[2].Take(k).Sum() : 0;
                        for (int l = 0; l <= val[3].Count; l++)
                        {
                            long rem = W - wS * i - (wS + 1) * j - (wS + 2) * k - (wS + 3) * l;
                            if (rem < 0) break;
                            long lSum = l != 0 ? val[3].Take(l).Sum() : 0;
                            var sum = iSum + jSum + kSum + lSum;
                            if (sum > ans) ans = sum;
                        }
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<int> st;

  int old = -100;
  int a;
  REP(i,n){
      cin >> a;
      if (old+1==a){
          st.insert(old-1);
      }
      old = a;
  }
  int ans = 0;
  REP(i,n){
      cin >> a;
      ans+=a;
  }
  REP(i,n-1){
      cin >> a;
      if (st.count(i)==1)ans+=a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
let print_floor a =
  Array.iter (fun n -> Printf.printf " %d" n) a;
  print_newline ()
let print_building a =
  Array.iter (fun f -> print_floor f) a
let print_house a =
  print_building a.(0);
  print_endline (String.make 20 '#');
  print_building a.(1);
  print_endline (String.make 20 '#');
  print_building a.(2);
  print_endline (String.make 20 '#');
  print_building a.(3)

let () =
  let house = [|(Array.make_matrix 3 10 0);(Array.make_matrix 3 10 0);
                (Array.make_matrix 3 10 0);(Array.make_matrix 3 10 0)|] in
  let count = read_int () in
  let rec loop i =
    if i >= count then print_house house
    else
      let line = read_line () in
      let b,f,r,v = Scanf.sscanf line "%d %d %d %d"
          (fun b f r v -> b-1,f-1,r-1,v) in
      house.(b).(f).(r) <- house.(b).(f).(r) + v;
      loop (i+1) in
  loop 0

Measured memory_bytes: 2816
#include<iostream>
#include<vector>

using namespace std;

#define ll long long

const int MAX = 1e5+7;

vector<int> graph[MAX];
bool vis[MAX];
int dp[MAX];

int dfs(int s){
    if(vis[s])
        return dp[s];
    vis[s] = true;
    for(int i = 0; i < graph[s].size(); ++i){
        int t = graph[s][i];
        dp[s] = max(dp[s], dfs(t)+1); 
    }

    return dp[s];
}

int main(){
    //freopen("tree.in","r",stdin);
    //freopen("tree.out","w",stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);


    int N, M;
    cin >> N >> M;

    for(int i = 0; i < M; ++i){
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
    }

    int ans = 0;
    for(int i = 1; i <= N; ++i){
        ans = max(ans, dfs(i));
        //cout << ans << endl;
    }
    cout << ans << endl;
}   



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

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

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

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

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

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<vector<pi> > adj(n);
    rep(i,n-1){
        int u,v,w; cin>>u>>v>>w; u--; v--;
        adj[u].emplace_back(v,w%2);
        adj[v].emplace_back(u,w%2);
    }
    queue<pi> que;
    que.emplace(0,0);
    vi c(n,-1);
    while(que.size()){
        int v,color;
        tie(v,color) = que.front(); que.pop();
        c[v] = color;
        for(auto e:adj[v]){
            if (c[e.fi]!=-1) continue;
            if (e.se==1) que.emplace(e.fi,1-color);
            else que.emplace(e.fi,color);
        }
    }
    rep(i,n){
        cout<<c[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  cout << fixed << setprecision(10);
  double a,b,x;
  cin >> a >> b >> x;
  double v=a*a*b;
  double arg;
  if(v==2*x) arg = atan(b/a)*180.0/PI;
  if(v>2*x) arg = atan(a*b*b/(2*x))*180.0/PI;
  if(v<2*x) arg = atan(2*(a*a*b-x)/(a*a*a))*180.0/PI;
  cout << arg << endl;
  
}




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

string S;
int K;

int main()
{
  cin >> S;
  K = 1;
  string prev = S.substr(0, 1);
  int i = 1;
  while (i != S.size())
  {
    // cout << prev << endl;
    if (prev != S.substr(i, 1))
    {
      prev = S.substr(i, 1);
      i += 1;
      ++K;
    }
    else if (i != S.size() - 1)
    {
      prev = S.substr(i, 2);
      i += 2;
      ++K;
    }
    else
    {
      break;
    }
  }
  cout << K << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <set>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
int n, m;
long long ans;
std :: multiset<int> S;
int main(){
	n = read(), m = read();
	for (register int i = 1; i <= n; ++i) S.insert(read());
	for (register int i = 1; i <= m; ++i){
		int t = *(--S.end());
		S.erase(--S.end());
		t >>= 1, S.insert(t);
	}
	ans = 0;
	for (int v : S) ans += v;
	printf("%lld\n", ans);
}

Measured memory_bytes: 4864
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
using namespace std;

int n, k;

int p[5];
int ct[5];

int ct1 = 0;
int ct2 = 0;

int main()
{

    for (int i = 1; i <= 3; i++)
    {
        int a, b;
        cin >> a >> b;
        ct[a]++;
        ct[b]++;
    }

    for (int i = 1; i <= 4; i++)
    {
        if (ct[i] == 1)
        {
            ct1++;
        }
        else if (ct[i] == 2)
        {
            ct2++;
        }
    }

    if (ct1 == 2 && ct2 == 2)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N,K;
vector<ll> bits;
vector<ll> A,B;

int main(){
    cin >> N >> K;
    A.resize(N);
    B.resize(N);
    rep(i,N) cin >> A[i] >> B[i];
    rep(i,31){
        if(K&(1<<i))bits.pb(i);
    }
    reverse(all(bits));

    ll ans = 0;

    rep(i,N){
        if((K|A[i]) == K) ans += B[i];
    }

    debug(ans);
    for(ll i = 30;i>=0;i--){
        if(K & (1ll<<i)){
            ll t1 = (~((1ll<<(i+1))-1)) & K;
            ll t2 = 1ll<<i;
            ll t3 = (1ll<<i)-1;
            ll k2 = t1 +  t3;
           // cerr << i << " "  << static_cast<bitset<5>>(k2) << endl;
            ll cnt = 0;
            rep(j,N){
                if((k2|A[j])==k2){
                    cnt += B[j];
                }
            }
            //cerr << cnt << endl;
            chmax(ans,cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
        int n,sum=0,ans=0,max=0,min=1001;
        cin >> n;
        if(n==0) break;
        int s[n];
        for(int i=0; i<n; i++){
          cin >> s[i];
          sum += s[i];
        }
        for(int i=0; i<n; i++){
          if(s[i] > max) max = s[i];
          if(s[i] < min) min =s[i];
        }
        sum = sum -max -min;
        ans = sum/(n-2);
        cout << ans << endl;
  }
  return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;

    set<int> num;
    for(int i=0; i<2*n; i++){
        num.insert(i);
    }

    vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; i++){
        c[i] = 2*n + i;
    }

    for(int i=0; i<(n+1)/2; i++){
        a[2*i] = i;
        num.erase(a[2*i]);

        if(num.upper_bound(c[2*i] - k - a[2*i]) == num.begin()){
            cout << -1 << endl;
            return 0;
        }
        b[2*i] = *prev(num.upper_bound(c[2*i] - k - a[2*i]));
        num.erase(b[2*i]);
    }

    for(int i=0; i<n/2; i++){
        a[2*i+1] = *num.begin();
        num.erase(a[2*i+1]);

        if(num.upper_bound(c[2*i+1] - k - a[2*i+1]) == num.begin()){
            cout << -1 << endl;
            return 0;
        }
        b[2*i+1] = *prev(num.upper_bound(c[2*i+1] - k - a[2*i+1]));
        num.erase(b[2*i+1]);
    }
    
    for(int i=0; i<n; i++){
        cout << a[i] + k << " " << b[i] + k << " " << c[i] + k << endl;
    }
    return 0;
}

Measured memory_bytes: 13820
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H, W = getlist()
	if H == 1 or W == 1:
		print(1)
		return

	if (H * W) % 2 == 0:
		print(int(H * W // 2))
		return

	print((H * W // 2) + 1)


if __name__ == '__main__':
	main()

Measured memory_bytes: 38256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, A, B = LI()
    H = []
    for _ in range(N):
        H.append(I())
    ng = -1
    ok = 10**9 + 1

    def enough(n, H):
        diff = A - B
        num = 0
        for i in range(N):
            H[i] -= B * n

        for i in range(N):
            if H[i] <= 0:
                continue
            num += H[i] // diff
            if H[i] % diff > 0:
                num += 1
        return num <= n

    while ok - ng > 1:
        attack = (ok + ng) // 2
        if enough(attack, H.copy()):
            ok = attack
        else:
            ng = attack

    print(ok)



main()



Measured memory_bytes: 110460
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

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


int A[16][16];

void solve(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    int info;
    cin >> info;
    for(int j = 0; j < info; j++){
      int x, y;
      cin >> x >> y;
      x--;
      if(y == 1) A[i][x] = 1;
      else A[i][x] = -1;
    }
  }
  int ans = 0;
  for(int bit = 0; bit < 1<<N; bit++){
    bool ok = 1;
    for(int i = 0; i < N; i++){
      if(((bit>>i)&1) == 0) continue;
      for(int j = 0; j < N; j++){
        if(A[i][j] == 0) continue;
        if(A[i][j] == 1 && ((bit>>j)&1) == 0) ok = 0;
        if(A[i][j] == -1 && ((bit>>j)&1) == 1) ok = 0;
      }
    }
    if(ok) ans = max(ans, (int)cnt_bit(bit));
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0,a=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')a++;
		else a--;
		if(a<0)ans++,a++;
	}cout<<2*ans<<endl;
	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 200000;
int n, m, a[M], b[M + 1], xxxc[2 * M + 1], ans;
int * c = & xxxc[M];

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { b[a[i]]++; }
	
	inc1(i, n) {
	inc(j, b[i]) {
		c[i - j]++;
	}
	}
	
	inc1(i, n) { if(c[i] == 0) { ans++; } }
	
	inc(q, m) {
		int xx, x, y;
		cin >> xx >> y;
		xx--;
		x = a[xx];
		a[xx] = y;
		
		int xp = x - (b[x] - 1);
		c[xp]--;
		if(xp >= 1 && c[xp] == 0) { ans++; }
		b[x]--;
		
		int yp = y - b[y];
		if(yp >= 1 && c[yp] == 0) { ans--; }
		c[yp]++;
		b[y]++;
		
		cout << ans << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str0[100005];
char str1[100005];
char str2[200005];
int  ne[100005][26];

void solve()
{
    scanf("%s%s", str0, str1);
    int n0 = strlen(str0);
    int n1 = strlen(str1);
    int cnt1[26] = { 0 };
    int i,k;
    for (i = 0; i < n1; i++) {
        int tmp = str1[i] - 'a';
        cnt1[tmp]++;
    }
    strcpy(str2, str0);
    strcat(str2, str0);
    vector<int> save(26, -1);
    for (i = 0; i < n0; i++) {
        for (k = 0; k < 26; k++) {
            ne[i][k] = -1;
        }
    }

    for (i = 2 * n0 - 1; i >= 0; i--) {
        int tmp = str2[i] - 'a';
        for(k=0; k<26; k++) {
            if (save[k] >= 0) ne[i%n0][k] = save[k] - i;
        }
        save[tmp] = i;
    }
    ll sum = 0;
    int curr = n0 - 1;
    for (i = 0; i < n1; i++) {
        int tmp = str1[i] - 'a';
        if (ne[curr][tmp] < 0) {
            printf("-1\n"); return;
        }
        sum+=ne[curr][tmp];
        curr = (sum-1) % n0;
    }
    printf("%lld", sum);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 10880
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::cin >> N; N%=10;
  if(N==3) fin("bon");
  if(N==0 || N==1 || N==6 || N==8) fin("pon");
  fin("hon");
  return 0;
}


Measured memory_bytes: 3596
import sys
input = sys.stdin.readline

def Main(N, h):
    dp = [0]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), \
                                  dp[i-2] + abs(h[i]-h[i-2]))
    return dp[N-1]

def main():
    N = int(input())
    h = list(map(int, input().split()))
    print(Main(N, h))

if __name__ == '__main__':
    main()

Measured memory_bytes: 13596
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e18;
using namespace std;

int main(){
    int n;
    cin>>n;
    int lst[n];
    rep(i,0,n){
        cin>>lst[i];
    }
    int tmp=0;
    rep(i,1,n){
        tmp^=lst[i];
    }
    cout<<tmp<<endl;
    lst[0]^=tmp;
    rep(i,1,n){
        lst[i]^=lst[0];
        cout<<lst[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

struct NODE{
	int pos , bit;
	NODE(int a,int b){ pos = a ; bit = b;}
	NODE(){}
};

NODE *done[1<<15][15];
NODE Q[(1<<15)*15];
int n,m;

bool diff(int a,int b,vector<string> &ans){
	int bit = a ^ b;
	bool f = false;
	rep(i,n){
		if( (a>>i&1)^(b>>i&1)){
			f = true;
			stringstream ss;
			ss << "Switch " << (a>>i&1?"on":"off") << " room " << i+1 << ".";
			ans.push_back(ss.str());
		}
	}
	return f;
}

int main(){
	while(cin >> n >> m && n){
		vector< vector<int> > v(n);
		vector< vector<int> > room(n);
		rep(i,m){
			int a,b;
			cin >> a >> b;
			a--,b--;
			v[a].push_back(b);
			v[b].push_back(a);
		}
		rep(i,n) sort(v[i].begin(),v[i].end());
		int init = 0;
		rep(i,n){
			int a; cin >> a;
			init |= (a<<i);
		}
		rep(i,n){
			int c; cin >> c;
			rep(j,c){
				int a; cin >> a;a--;
				if(a != i) room[i].push_back(1<<a);
			}
			sort(room[i].begin(),room[i].end());
		}
		rep(i,1<<n)rep(j,n) done[i][j] = NULL;
		int head = 0 , size = 0 , ansbit = (1<<30); 
		bool flag = false;
		Q[size++] = NODE(0,init);
		done[init][0] = &Q[head];
		while(head < size){
			NODE q = Q[head];
			if(q.pos == n-1){
				if( q.bit == (1<<(n-1)) ){
					vector<string> a;
					NODE r = q;
					while(1){
						NODE next = (*done[r.bit][r.pos]);
						if(next.pos == r.pos && next.bit == r.bit) break;
						if(r.pos != next.pos){
							stringstream ss;
							ss << "Move to room " << r.pos+1 <<".";
							a.push_back(ss.str());
						}else{
							diff(r.bit,next.bit,a);
						}
						r = next;
					}
					
					cout << "You can go home in " << a.size() << " steps." << endl;
					rep(i,a.size()){
						cout << a[a.size()-1-i] << endl;
					}
					goto exit;
				}
				flag = true;
			}
			rep(j,room[q.pos].size()){
				int nextbit = q.bit ^ room[q.pos][j];
				if(done[nextbit][q.pos] == NULL){
					done[nextbit][q.pos] = &Q[head];
					Q[size++] = NODE(q.pos,nextbit);
				}
			}
			rep(i,v[q.pos].size()){
				if(q.bit >> v[q.pos][i] & 1){
					if(done[q.bit][v[q.pos][i]] == NULL){
						done[q.bit][v[q.pos][i]] = &Q[head];
						Q[size++] = NODE(v[q.pos][i],q.bit);
					}
				}
			}
			head++;
		}
		if(flag)cout << "You can not switch off all lights." << endl;
		else cout << "Help me!" << endl;
		exit:;
	}
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<string> mp(N);
    for(int i=0; i<N; i++) cin >> mp[i];

    // mp[i][j] : graph[i * M + j]
    atcoder::mf_graph<int> graph(N * M + 2);
    const int start = N * M;
    const int goal = N * M + 1;
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<M; j++)
        {
            if(mp[i][j] == '#') continue;
            int node = i * M + j;
            if((i + j) % 2 == 0) graph.add_edge(start, node, 1);
            else graph.add_edge(node, goal, 1);
        }
    }

    for(int i=0; i<N; i++)
    {
        for(int j=0; j<M; j++)
        {
            if((i + j) % 2 || mp[i][j] == '#') continue;
            int from = i * M + j;
            if(i != 0 && mp[i-1][j] == '.') graph.add_edge(from, from - M, 1);
            if(i != N - 1 && mp[i+1][j] == '.') graph.add_edge(from, from + M, 1);
            if(j != 0 && mp[i][j-1] == '.') graph.add_edge(from, from - 1, 1);
            if(j != M - 1 && mp[i][j+1] == '.') graph.add_edge(from, from + 1, 1);
        }
    }

    cout << graph.flow(start, goal) << '\n';

    auto edges = graph.edges();
    for(auto edge : edges)
    {
        if(edge.from == start || edge.to == goal || edge.flow == 0) continue;
        int fi = edge.from / M;
        int fj = edge.from % M;
        int ti = edge.to / M;
        int tj = edge.to % M;
        if(fi == ti)
        {
            if(fj == tj - 1)
            {
                mp[fi][fj] = '>';
                mp[ti][tj] = '<';
            }
            else
            {
                mp[fi][fj] = '<';
                mp[ti][tj] = '>';
            }
        }
        else
        {
            if(fi == ti - 1)
            {
                mp[fi][fj] = 'v';
                mp[ti][tj] = '^';
            }
            else
            {
                mp[fi][fj] = '^';
                mp[ti][tj] = 'v';
            }
        }
    }

    for(auto s : mp) cout << s << '\n';

    return 0;
}


Measured memory_bytes: 5592