akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int prime(int a)
{
    int num[1000000]={0};
    int count[1000000]={0};
    int i,j,c=0;

    for(i=2;i<a+1;i++){
        num[i]=i;
        count[i]=1;
    }
    for(i=2;i<a+1;i++){
        if(count[i]==1){
            for(j=i+i;j<a+1;j=j+i){
                count[j]=0;
            }
        }
    }
    for(i=2;i<a+1;i++){
        if(count[i]){
            c++;
            }
    }
    return c;
}

int main(void)
{
    int n,/*i,j,flag,*/count;

    while(scanf("%d",&n),n){
        count=prime(n*2)-prime(n);
    /*    count=0;

        for(i=n+1;i<=n*2;i++){
            flag=0;
            for(j=2;j<i;j++){
                if(i%j==0){
                    flag=1;
                    break;
                }
            }
            if(flag==0) count++;
        }
*/
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 4512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a[100001];
bool b[100001];
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = false;
	}
	int sum = 0, x = 1;
	b[1] = true;
	while (x != 2) {
		x = a[x];
		if (b[x]) {
			cout << -1 << endl;
			return 0;
		}
		b[x] = 1;
		sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1152
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

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


class BCutAndCount {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      string s;
      in >> n >> s;
      int ans = 0;
      REP(i, n - 1) {
        string t1 = s.substr(0, i + 1);
        string t2 = s.substr(i + 1, s.length() - i - 1);
        int t = 0;
        map<char, int> m1, m2;
        REP(i, t1.length()) m1[t1[i]]++;
        REP(i, t2.length()) m2[t2[i]]++;
        REP(i, 26) {
          if (m1[i + 'a'] > 0 && m2[i + 'a'] > 0) {
            t++;
          }
        }
        ans = max(ans, t);
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BCutAndCount solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0]*M
y = [0]*M
c = [0]*M
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split())
ans = 10**10
ma = max(c)
#ind = c.index(ma)
am = min(a)
bm = min(b)
mae = am + bm #ここまで
#indxy = a[x[ind]-1] + b[y[ind]-1] - ma

for i in range(M):
  mai = a[x[i]-1] + b[y[i] -1] - c[i]
  if mai < ans:
    ans = mai
if mae < ans:
  print(mae)
else:
  print(ans)

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

using namespace  std;

#define ll long long

#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;


int main(){
     
    double e=0,o=0,n;
    cin>>n;
    for (int i = 1; i<=n; ++i)
    {
        if(i%2==0){
            e+=1;
        }
        else{
            o+=1;
        }
    }
    double r;
    r=o/n;
   cout<<fixed<<setprecision(6)<<r;
 //cerr<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 21092013;
const double EPS = 1e-8;
//-------------head-------------
int n, a[N];
int main() {
	ll ans = 0;
	scanf("%d", &n);
	rep(i, 1, n + 1)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
		if (a[i] > 0) {
			ll sum = 0;
			while (i <= n && a[i] > 0)
				sum += a[i++];
			--i;
			ans += sum >> 1;
		}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBuffet solver = new BBuffet();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBuffet {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.scanInt();
            }
            long ans = 0;
            int b[] = new int[n + 1];
            for (int i = 1; i <= n; i++) b[i] = in.scanInt();
            int c[] = new int[n + 1];
            for (int i = 1; i < n; i++) c[i] = in.scanInt();
            for (int i = 0; i < n; i++) {
                ans += b[arr[i]];
                if (i != n - 1 && arr[i + 1] == arr[i] + 1) {
                    ans += c[arr[i]];
                }
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

public class Test
{
    public static void Main()
    {
        //入力
        String[] R = Console.ReadLine().Split();
        int N = int.Parse(R[0]);
        double M = int.Parse(R[1]);

        //条件
        double M_ = 1/(4 * M);

        String[] _A = Console.ReadLine().Split();
        int[] A = _A.Select(s => int.Parse(s)).ToArray();
            
        //総得票数
        int S = A.Sum();

        double S_ = S * M_;

        int count = 0;

        //主処理

        foreach (int i in A)
        {
            if (i >= S_)
            {
                ++count;
            }
        }

        //出力
        if (count >= M)
        {
            Console.WriteLine("Yes"); 
        }
        else { Console.WriteLine("No");}

    }

}



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

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

  int ans = 0;
  int pls1 = 0;
  int pls2 = 0;
  if ( s[0] == 'L' ) { pls1++; }
  if ( s[n-1] == 'R' ) { pls1++; }
  for ( int i = 0; i < n; i++ ) {
    if ( i != n-1 && s[i] == 'R' && s[i+1] == 'L' ) { pls2++; }
    if ( i != n-1 && s[i] == 'R' && s[i+1] == 'R' ) { ans++; }
    if ( i != 0   && s[i] == 'L' && s[i-1] == 'L' ) { ans++; }
  }

  if ( pls2 >= k ) {
    ans += (2*k);
  } else {
    ans += (2*pls2);
    k -= pls2;
    if ( pls1 <= k ) {
      ans += pls1;
    } else {
      ans += k;
    }
  }
  ans = ( ans == n ) ? ans-1 : ans;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3768
num = input()
ai = input().split()

flag = 0

for a in ai:
  a = int(a)
  if a % 2 == 0:
    if a % 3 != 0 and a % 5 != 0:
      flag = 1
      break

if flag == 1:
  print("DENIED")
else:
  print("APPROVED")

Measured memory_bytes: 2940
from fractions import gcd
a,b,c,d = map(int,input().split())
e = int(c*d/gcd(c,d))
n1 = b//c-a//c if a%c != 0 else b//c-a//c+1
n2 = b//d-a//d if a%d != 0 else b//d-a//d+1
n3 = b//e-a//e if a%e != 0 else b//e-a//e+1
print(b-a+1-n1-n2+n3)

Measured memory_bytes: 5088
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
  string line;
  int S;
  int h,m;
  getline (cin,line);
  stringstream(line) >> S;
  h = S/3600;
  m = (S-3600*h)/60;
  cout << h << ':' << m << ':' << S-3600*h-60*m << '\n';
  return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <set>

using namespace std;

void dfs(int n, int d);

int main()
{
	int h, w, sh, sw, gh, gw;
	cin >> h >> w >> sh >> sw >> gh >> gw;
	sh--;
	sw--;
	gh--;
	gw--;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	vector<vector<int>> map(h, vector<int>(w, -1));
	int id = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			if (map[i][j] != -1) continue;
			queue<pair<int, int>> q;
			q.push(make_pair(i, j));
			while (!q.empty()) {
				int x = q.front().first;
				int y = q.front().second;
				q.pop();

				if (map[x][y] != -1) continue;
				map[x][y] = id;

				int dx[] = { -1, 1, 0, 0 };
				int dy[] = { 0, 0, -1, 1 };
				for (int i = 0; i < 4; i++) {
					int nx = x + dx[i];
					int ny = y + dy[i];
					if (nx < 0) continue;
					if (ny < 0) continue;
					if (nx >= h) continue;
					if (ny >= w) continue;
					if (s[nx][ny] == '#') continue;
					q.push(make_pair(nx, ny));
				}
			}
			id++;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			
		}
	}
	
	vector<set<int>> st(id);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			for (int k = -2; k <= 2; k++) {
				for (int l = -2; l <= 2; l++) {
					int nx = i + k;
					int ny = l + j;
					if (nx < 0) continue;
					if (ny < 0) continue;
					if (nx >= h) continue;
					if (ny >= w) continue;
					if (s[nx][ny] == '#') continue;
					if (map[i][j] == map[nx][ny]) continue;
					st[map[i][j]].insert(map[nx][ny]);
					st[map[nx][ny]].insert(map[i][j]);
				}
			}
		}
	}

	vector<int> ans(id, -1);
	queue<pair<int, int>> r;
	r.push(make_pair(map[sh][sw], 0));
	while (!r.empty()) {
		int c = r.front().first;
		int d = r.front().second;
		r.pop();

		if (ans[c] != -1 && ans[c] <= d) continue;
		ans[c] = d;
		for (auto& i : st[c]) {
			if (ans[i] != -1 && ans[i] <= d + 1) continue;
			r.push(make_pair(i, d + 1));
		}
	}
	/*for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#')continue;
			cout << ans[map[i][j]] << (j == w - 1 ? "\n" : " ");
		}
	}*/
	cout << ans[map[gh][gw]] << endl;

	return 0;
}

Measured memory_bytes: 33888
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
	cin>>a[i];
    }
    sort(a.begin(),a.end());

    int sum=-a[0]+a[N-1];
    for(int i=1;i<N-1;i++){
	if(a[i]>=0){
	    sum+=a[i];
	}else{
	    sum-=a[i];
	}
    }
    cout<<sum<<endl;

    stack<int> S,T;
    S.push(a[N-1]);
    T.push(a[0]);
    for(int i=1;i<N-1;i++){
	if(a[i]>=0){
	    S.push(a[i]);
	}else{
	    T.push(a[i]);
	}
    }

    vector<pint> ans;
    while(S.size()>1){
	int s=S.top(); S.pop();
	int t=T.top(); T.pop();
	ans.push_back(pint(t,s));
	T.push(t-s);
    }
    while(T.size()>0){
	int s=S.top(); S.pop();
	int t=T.top(); T.pop();
	ans.push_back(pint(s,t));
	S.push(s-t);
    }

    for(pint p:ans){
	cout<<p.first<<' '<<p.second<<endl;
    }
}


Measured memory_bytes: 5104
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int A, B;
  cin >> A >> B;
  cout << (A * B) << endl;
}

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

int arr[100005];
int INF=(1<<31);
int dp[100005];
bool vis[100005];
int n,k;
int rec(int pos)
{
    if(pos==0)return 0;
    if(pos==1)return abs(arr[1]-arr[0]);
    if(vis[pos])return dp[pos];
    vis[pos]=true;
    dp[pos]=min(rec(pos-1)+abs(arr[pos]-arr[pos-1]),rec(pos-2)+abs(arr[pos]-arr[pos-2]));
    return dp[pos];
}
            int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)cin>>arr[i];
    memset(vis,false,sizeof(vis));
    cout<<rec(n-1)<<"\n";

    return 0;
}


Measured memory_bytes: 2688
use std::io;


/// https://beta.atcoder.jp/contests/abc073/tasks/abc073_b
fn main() {
    let n = read_one::<usize>();
    let mut ans = 0;
    for _ in 0..n {
        let i = read::<usize>();
        ans += i[1] + 1 - i[0];
    }

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main (){
  int N;
  cin>>N;
  vector<int>a(N,0);
  rep(i,N-1){
    int x;
    cin>>x;
    x--;
    a[x]++;
  }
  rep(i,N){
    cout<<a[i]<<endl;
  }
}


Measured memory_bytes: 4052
import sys
from fractions import gcd
from collections import deque
from functools import *
from itertools import *

N = int(input())
As = list(map(int, input().split()))

def gcd_acc(acc, x):
    if len(acc) == 0:
        acc.append(x)
        return acc
    last = acc[-1]
    acc.append(gcd(last, x))
    return acc

def candidates(As):
    length = len(As)
    L = iter(reduce(gcd_acc, As, deque()))
    R = reversed(reduce(gcd_acc, reversed(As), deque()))
    next(R)

    yield next(R)

    if length == 1:
        return

    for _ in range(length-2):
        yield gcd(next(L), next(R))
        pass
    yield next(L)
    pass

print(max(candidates(As)))



Measured memory_bytes: 16504
#![allow(unused_imports)]
#![allow(dead_code)]

use std::io::{ self, BufRead };
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;

fn f(mut x: i64) -> i64 {
    let mut y = 0;
    while x % 2 == 0 { 
        y += 1;
        x /= 2;
    }
    y
}

fn main() {
    let stdin = io::stdin();
    let mut cin = stdin.lock().lines().map(|r| r.unwrap());

    let n = cin.next().unwrap().parse::<i64>().unwrap();
    let a = cin.next().unwrap()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect::<Vec<i64>>();

    let mut ans = 1 << 30;
    for x in a {
        ans = min(ans, f(x));
    }

    println!("{}", ans);
}

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

const int limit = 50;
int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v] = true;
    rep(v2,0,n){
        if(graph[v][v2] == false) continue;
        if(visited[v2] == true) continue;
        dfs(v2);
    }
}

int main() {
    cin >> n >> m;
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    rep(i, 0, m) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        rep(j, 0, n) {
            visited[j] = false;
        }
        dfs(0);

        bool bridge = false;
        rep(j, 0, n) {
            if (visited[j] == false) {
                bridge = true;
            }
        }
        if (bridge) {
            ans += 1;
        }
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int n,fir[5010],dis[100010],nxt[10010],id,fact[5010],ifact[5010],ans=0,siz[5010],rt,f[5010];
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
void getrt(int x,int fa=-1){
	f[x]=0,siz[x]=1;
	for(int i=fir[x];i;i=nxt[i]){
		if(dis[i]==fa)continue;
		getrt(dis[i],x);
		siz[x]+=siz[dis[i]];
		cxk(f[x],siz[dis[i]]);
	}
	cxk(f[x],n-siz[x]);
	if(f[x]<f[rt])rt=x;
}
int C(int n,int m){return 1ll*fact[n]*ifact[m]%mod*ifact[n-m]%mod;}
int A(int n,int m){return 1ll*fact[n]*ifact[n-m]%mod;}
int F[5010];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	n=gi();int a,b;
	for(int i=1;i<n;++i)a=gi(),b=gi(),link(a,b),link(b,a);
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*i*fact[i-1]%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	f[0]=1e9,getrt(1);getrt(rt);
	if(f[rt]*2==n)printf("%d\n",1ll*fact[n/2]*fact[n/2]%mod),exit(0);
	F[0]=1;
	for(int i=fir[rt];i;i=nxt[i]){
		int sz=siz[dis[i]];
		for(int j=n;~j;--j)
			for(int k=1;k<=j&&k<=sz;++k)
				inc(F[j],1ll*F[j-k]*C(sz,k)%mod*A(sz,k)%mod);
	}
	for(int i=0,w;i<=n;++i){
		w=1ll*F[i]*fact[n-i]%mod;if(i&1)w=mod-w;
		inc(ans,w);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N); cin >> A;
  int S = accumulate(A.begin(), A.end(), 0);

  vector<int> v;
  for (int i = 1; i * i <= S; ++i) {
    if (S % i == 0) {
      v.push_back(i);
      v.push_back(S/i);
    }
  }
  sort(v.rbegin(), v.rend());

  for (int x : v) {
    vector<int> v2;
    for (int a : A) {
      v2.push_back(a % x);
    }
    sort(v2.begin(), v2.end());

    int l = 0, r = N-1;
    int sl = 0, sr = 0;
    while (l <= r) {
      if (sl <= sr) {
        sl += v2[l];
        ++l;
      } else {
        sr += x - v2[r];
        --r;
      }
    }
    if (sl == sr && sl <= K) {
      cout << x << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
#define qq ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
ll mod=1000000007;
int main() 
{
  qq;
  int n,l;
  cin >> n >> l;
  vector<int> v(n);
  for(int i=1;i<=n;i++)
  {
    v[i-1] = l+i-1;
  }
  sort(all(v), [](int a, int b){return abs(a) < abs(b);});
  cout << accumulate(all(v), 0)-v[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <string>
#include <map>
using namespace std;

int main(){
	int n;cin>>n;
	string s;cin>>s;
	
	using P = pair<string,string>;
	map<P,int> mp;
	
	for(int i=0;i<(1<<n);i++)
	{
		string t="",rt="";
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1) t+=s[j];
			else rt+=s[j];
		}

		mp[P(t,rt)]++;
	}

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

	
	long long ans = 0;
	
	for(int i=0;i<(1<<n);i++)
	{
		string t,rt;
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1) t+=s[j];
			else rt+=s[j];
		}
		ans += mp[P(t,rt)];
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 91904
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_N = 17;
const int MAX_LEN = 10;
int N, M;

char buf[MAX_N][MAX_LEN];
vector<int> pats[MAX_N];
int lens[MAX_N];
bool isTop[10];
int num[10];
int coef[10];

void init(){
	vector<char> cs;
	for(int i=0; i<N; i++){
		lens[i] = strlen(buf[i]);
		for(int j=0; j<lens[i]; j++){
			cs.push_back(buf[i][j]);
		}
	}
	sort(cs.begin(), cs.end());
	cs.erase(unique(cs.begin(), cs.end()), cs.end());
	M = cs.size();
	for(int i=0; i<N; i++){
		for(int j=0; j<lens[i]; j++){
			for(int k=0; k<M; k++)if(cs[k]==buf[i][j]){
				pats[i].push_back(k);
			}
		}
	}
	for(int i=0; i<M; i++)  isTop[i] = false;
	for(int i=0; i<M; i++)  coef[i] = 0;
	for(int i=0; i<N; i++){
		int base = 1;
		for(int j=lens[i]-1; j>=0; j--){
			coef[pats[i][j]] += (i==N-1?-base:base);
			base *= 10;
			if(j==0 && lens[i]>1){
				isTop[pats[i][j]] = true;
			}
		}
	}
}

bool check(){
	int tot = 0;
	for(int i=0; i<M; i++){
		if(isTop[i] && !num[i]) return false;
	}
	for(int i=0; i<M; i++){
		tot += num[i]*coef[i];
	}
	return tot==0;
}

int solve(){
	init();
	int ans = 0;
	int bit = (1<<M)-1;
	while(bit < (1<<10)){
		int p=0;
		for(int i=0; i<10; i++)if((bit>>i)&1){
			num[p++] = i;
		}
		do{
			if(check()){
				ans++;
			}
		}while(next_permutation(num, num+M));
		int x = bit & -bit, y = bit + x;
		bit = ((bit & ~y) / x >> 1) | y;
	}
	return ans;
}

int main(){
	while(scanf("%d",&N),N){
		for(int i=0; i<N; i++){
			scanf(" %[^\n]", buf+i);
			pats[i].clear();
		}
		printf("%d\n",solve());
	}
	return 0;
}

Measured memory_bytes: 824
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, M; cin >> N >> M;
    int P[100100], Y[100100];
    vector<int> y[100100];
    rep(i, M) {
        cin >> P[i] >> Y[i];
        y[P[i]].pb(Y[i]);
    }
    rep(i, N) {
        sort(y[i + 1].begin(), y[i + 1].end());
    }
    rep(i, M) {
        cout << setfill('0') << right << setw(6) << P[i];
        int cnt = lower_bound(y[P[i]].begin(), y[P[i]].end(), Y[i]) - y[P[i]].begin() + 1;
        cout << setfill('0') << right << setw(6) << cnt << endl;
    }
	return 0;
}

Measured memory_bytes: 7808
lines = $stdin.read
array = lines.split("\n")

X,Y = array[0].split(" ").map(&:to_s)

hex = { 'A' => 10,
        'B' => 11,
        'C' => 12,
        'D' => 13,
        'E' => 14,
        'F' => 15}

if hex[X] == hex[Y]
  puts "="
elsif hex[X] > hex[Y]
  puts ">"
else
  puts "<"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int main()
{
	int n;
	int sum=0;
	int ans1;
	int ans2;
	cin >> n;
	repp(i, 1, n+1)
	{
		sum+=i;
		if(sum>=n)
		{
			ans1=i;
			break;
		}
	}
	ans2=sum-n;
	repp(i, 1, ans1+1)
	{
		if(i!=ans2)
		{
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}


void solve() {
	ll n, a, b; cin >> n >> a >> b;
	if (a > b)swap(a, b);
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		
		ll ans = min((b-a-1)/2+a, n-b+1+(b-a-1)/2);
		cout << ans << endl;
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(12);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
char field[9][9];

void solve()
{
	for(int i = 0; i < 8; ++i)
	{
		for(int j = 0; j < 8; ++j)
		{
			cin >> field[i][j];
		}
	}
	cout << 90 << endl;
	for(int i = 0; i < 8; ++i)
	{
		for(int j = 7; j >= 0; --j)
		{
			cout << field[j][i];
		}
		cout << endl;
	}
	cout << 180 << endl;
	for(int i = 7; i >= 0; --i)
	{
		for(int j = 7; j >= 0; --j)
		{
			cout << field[i][j];
		}
		cout << endl;
	}
	cout << 270 << endl;
	for(int i = 7; i >= 0; --i)
	{
		for(int j = 0; j < 8; ++j)
		{
			cout << field[j][i];
		}
		cout << endl;
	}
}

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

Measured memory_bytes: 0
import math 
x, y = map(int, input().split())

def judge(x_,y_):
    turu = int(2*x_ - (y_/2))
    kame = int((y_/2) - x_)

    if turu < 0 or kame < 0:
        return 'No'

    if (turu + kame == x_ and 2*turu+4*kame == y_):
        return 'Yes'
    return 'No'

print(judge(x,y))


Measured memory_bytes: 9180
n,x = map(int,input().split())
c = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
c.append(x)
c.sort()
g = c[1]-c[0]
for i in range(1,n):
    g = gcd(g,c[i+1]-c[i])
print(g)

Measured memory_bytes: 14252
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let mut set = BTreeSet::new();
    for i in 0..k {
        input! {
            d: usize,
            a: [usize; d],
        }
        for e in a {
            set.insert(e);
        }
    }
    println!("{}", n - set.len());
}


Measured memory_bytes: 2124
def main():
    n, m = map(int, input().split())
    sc_list = [list(map(int, input().split())) for _ in range(m)]

    for num in range(1000):
        ch = str(num)

        if len(ch) != n:
            continue

        for i in range(m):
            s = sc_list[i][0]
            c = sc_list[i][1]
            if ch[s - 1] != str(c):
                break
        else:
            print(num)
            break
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63044
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

const int N=1e5+5;
int n,m,ans=123456789;
map<int,vector<int> > E[N];
map<int,int> d[N];
vector<int> G[N];

struct three{
	int First;
	int Second;
	int Third;
};

three make_three(int x,int y,int z){
	three re;
	re.First=x;
	re.Second=y;
	re.Third=z;
	return re;
}

queue<three> q;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--;y--;
		E[x][z].push_back(y);
		E[y][z].push_back(x);
		G[x].push_back(z);
		G[y].push_back(z);
	}
	q.push(make_three(0,0,0));
	d[0][0]=0;
	while(!q.empty()){
		three now=q.front();
		int f=now.First,s=now.Second,t=now.Third;
//		printf("%d %d %d\n",f,s,t);
		q.pop();
		if(d[f][s]!=t) continue;
		if(d[f].find(0)==d[f].end()||d[f][0]>t){
			d[f][0]=t;
			q.push(make_three(f,0,t));
		}
		if(s==0) for(int i=0;i<G[f].size();i++){
			int color=G[f][i];
			if(d[f].find(color)==d[f].end()||d[f][color]>t+1){
				d[f][color]=t+1;
				q.push(make_three(f,color,t+1));
			}
		}else for(int i=0;i<E[f][s].size();i++){
			int to=E[f][s][i];
			if(d[to].find(s)==d[to].end()||d[to][s]>t){
				d[to][s]=t;
				q.push(make_three(to,s,t));
			}
		}
	}
	for(map<int,int>::iterator it=d[n-1].begin();it!=d[n-1].end();it++) ans=min(ans,(*it).second);
	if(ans!=123456789) printf("%d\n",ans);
	else puts("-1");
	return 0;
}

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

public class Main {
    public static long digits(long n) {
    	long count = 0; 
    	while(n != 0) {
    		n /= 10;
    		count++;  
    	}
    	return count; 
    }
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    long n = in.readLong();
	    long b = 0;
	    long ans = Integer.MAX_VALUE; 
	    for(long a = 1; a*a <= n; a++) {
	    	if(n%a == 0) {
	    	   b = n/a; 
	    	}
	      ans = Math.min(ans, Math.max(digits(a), digits(b))); 
	    }
	    System.out.println(ans); 
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

#define int long long

int n;

int dp[109][100009];

int const mod = 1e9+7;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> n >> k;
    dp[0][k] = 1;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        for(int j = k; j >= 0; j--){

            int l = j;
            int r = j-min(j,a);

            dp[i+1][l] += dp[i][j];
            dp[i+1][l] %= mod;

            if(r){
                dp[i+1][r-1] -= dp[i][j];
                if(dp[i+1][r-1] < 0) dp[i+1][r-1]+=mod;
                dp[i+1][r-1] %= mod;
            }
        }

        int t = 0;

        for(int j = k; j >= 0; j--){
            t+=dp[i+1][j];
            t%=mod;
            dp[i+1][j] = t;
        }
    }
    cout << dp[n][0] << endl;
}



Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <string>
#include <iostream>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int bigint;

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b, ans =0; 
	cin >> a >>b;
	
	//if(a>= b){ puts("1"); return 0;}
	if(b <=1){ puts("0"); return 0;}
	ans =1;
	int c = a;
	while(1){
		if(c >= b) break;
		c += (a-1);
		ans++;
	}
	
	cout << ans <<"\n";
	return 0;
	
	
}
/*
int main(){

	rep2(a,2,21) rep2(b,1,21){
		dbg(a,b, zmain(a,b));
	}

}*/


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
cnt = 0

for a in A:
  total = 0
  for i in range(M):
    total += a[i] * B[i]
  if total + C > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;string s;cin>>n>>s;
	int alpha[26]={};
	rep(i,n) alpha[s[i]-'a']++;
	ll sum=1;
	rep(i,26) sum=(alpha[i]+1)*sum%MOD;
	cout<<sum-1<<"\n";
}

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

#define pb(a) push_back(a)
#define INF 1145141919810
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[dsize],fac[dsize];

template <class T = ll> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int n=in();
	PRI(55555);
	vector<int> mo[5];
	for (int i=0;i<prime.size();i++) {
		mo[prime[i]%5].push_back(prime[i]);
	}
	for (int i=0;i<5;i++) {
		if (mo[i].size()>=n) {
			for (int j=0;j<n;j++) {
				cout<<mo[i][j]<<" ";
			}
			return 0;
		}
	}
}


Measured memory_bytes: 384
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
    cin >> a;
    char c;
    cin >> c;
    cin >> b;
    (c=='+') ? cout<<a+b: cout<<a-b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,A,ben=0;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>A;
    ben+=A;
  }
  
  if(N-ben<0) cout<<"-1";
  else   cout<<N-ben;
  
  
  return 0;
}


Measured memory_bytes: 3640
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		int dp[]=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++)
		{
			dp[i]=dp[i-1]+Math.abs(a[i]-a[i-1]);
			if(i>1)
				dp[i]=Math.min(dp[i], dp[i-2]+Math.abs(a[i-2]-a[i]));
		}
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 51320
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;

/*ALDS1_1_A
int trace(int a[],int N){
	for(int i=0;i<N;i++){
		if(i>0)
			cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
}

int insertionSort(int a[],int N){
	for(int i=1;i<N;i++){
		int v=a[i];
		int j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		trace(a,N);
	}
}
*/
int bubbleSort(int a[],int N){
	int ans=0;
	int flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
				flag=1;
				ans++;
			}
		}
	}
	return ans;
}
int selectionSort(int a[],int N){
	int ans=0;
	int minj;
	for(int i;i<N-1;i++){
		minj=i;
		for(int j=i;j<N;j++){
			if(a[j]<a[minj])
				minj=j;
		}
		int t=a[i];
		a[i]=a[minj];
		a[minj]=t;
		if(i!=minj)
			ans++;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	int N,i,j;
	int a[100];
	while(cin>>N){
		for(i=0;i<N;i++)
			cin>>a[i];
		//trace(a,N);
		//insertionSort(a,N);
		int ans=selectionSort(a,N);
		for(int i=0;i<N;i++){
			if(i)
				cout<<" ";
			cout<<a[i];
		}
		cout<<"\n"<<ans<<endl;
	}
	return 0;
}



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

typedef long long ll;
#define inf (1<<29)

int main(){

  ll t[600];
  int n;

  cin >> n;
  fill(t,t+600,NULL);
  for(int i = 1; i <= n; i++){
    cin >> t[i];
    // cout << t[i];
  }


  for(int i = 1; i <= n; i++){
    // cout << t[i] << " ";
    cout << "node " << i << ": " << "key = " << t[i] << ", ";
    if(t[i/2] != NULL) printf("parent key = %lld, ",t[i/2]);
    if(t[i*2] != NULL) printf("left key = %lld, ",t[i*2]);
    if(t[2*i+1] != NULL) printf("right key = %lld, ",t[2*i+1]);
    cout << endl;
  }



}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int n,ans=-1,answ=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int sum=0,a=i;
        while(a%2==0){
            a/=2;
            sum++;
        }
        if(sum>ans){ans=sum;answ=i;}
    }
    cout<<answ<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::collections::HashMap;

#[allow(dead_code)]
fn input_strs() -> Vec<String> {
    let mut s = String::new();
    match stdin().read_line(&mut s) {
        Ok(_) => s.split_whitespace().map(|s| s.to_string()).collect(),
        Err(_) => panic!("err"),
    }
}

#[allow(dead_code)]
fn input_ints() -> Vec<i32> {
    let mut s = String::new();
    match stdin().read_line(&mut s) {
        Ok(_) => s.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => panic!("err"),
    }
}

#[allow(unused_variables)]
fn solve() {
    let l = input_ints();
    let n = l[0] as usize;
    let a = input_ints();

    let mut h = HashMap::<i32, u32>::new();

    for num in &a {
        let current = h.entry(*num).or_insert(0);
        *current += 1;
    }

    let mut x_num = 0;

    for (x, v) in &h {
        let mut total = *v;

        if let Some(num) = h.get(&(*x - 1)) {
            total += *num;
        }
        if let Some(num) = h.get(&(*x + 1)) {
            total += *num;
        }

        x_num = std::cmp::max(total, x_num);
    }

    println!("{}", x_num);
}

fn main() {
    solve();
}


Measured memory_bytes: 8444
import Control.Monad
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IntMap

type Map = IntMap.IntMap Int

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

solve :: String -> String -> Int -> Int -> Map -> Map
solve [] _ _ _ m = m
solve (s:ss) prev step count m = solve ss [s] (step + 1) nextcount nextmap
  where nextcount = if prev ++ [s] == "AC" then count + 1 else count
        nextmap = IntMap.insert step nextcount m

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  s <- getLine
  let m = solve s "" 1 0 IntMap.empty
  replicateM_ q $ do
    [l, r] <- readIntsLine
    let lcount = fromMaybe 0 $ IntMap.lookup l m
    let rcount = fromMaybe 0 $ IntMap.lookup r m
    print $ rcount - lcount

Measured memory_bytes: 27516
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int H; int W;
	while (~scanf("%d%d", &H, &W)) {
		int N;
		scanf("%d", &N);
		vector<int> colors(H * W);
		int K = 0;
		for (int i = 0; i < N; ++ i) {
			int A;
			scanf("%d", &A);
			rep(k, A)
				colors[K ++] = i + 1;
		}
		vector<vi> ans(H, vi(W));
		{
			int k = 0;
			rep(i, H) rep(jj, W) {
				int j = i % 2 == 0 ? jj : W - 1 - jj;
				ans[i][j] = colors[k ++];
			}
		}
		rep(i, H) {
			for (int j = 0; j < W; ++ j) {
				if (j != 0) putchar(' ');
				printf("%d", ans[i][j]);
			}
			puts("");
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

#define ll long long

using namespace std;

int main(){
    ll k, a, b, c;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(a >= k){
        ans = k;
    }else if((a + b) >= k){
        ans = a;
    }else{
        ans = a - (k - a - b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
n,m = map(int,input().split())
node_dict = {i:set() for i in range(1,n+1,1)}
for i in range(m):
    tmp1,tmp2 = map(int,input().split())
    node_dict[tmp1].add(tmp2)
    node_dict[tmp2].add(tmp1)
mitishirube_list = [1]
tansaku_set = set([i for i in range(2,n+1,1)])
tansakusumi_list = []
while(tansaku_set != set()):
    tmp_list = mitishirube_list
    mitishirube_list = []
    for i in tmp_list:
        for j in node_dict[i] & tansaku_set:
            tansakusumi_list.append([j,i])
            tansaku_set.remove(j)
            mitishirube_list.append(j)
tansakusumi_list.sort()
print("Yes")
for i in tansakusumi_list:
    print(i[1])

Measured memory_bytes: 87136