akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

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

typedef complex<double> P;
typedef pair<P, P> L;

const double EPS = 1e-9;
const int INF = 1e9 + 10;

#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

#define S first
#define T second

double cross(P a, P b) {
	return (conj(a) * b).Y;
}
double dist(P a, P b) {
	return (a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y);
}
bool isPointOnLine(P a, P b, P c) {
	return abs(a - c) + abs(c - b) < abs(a - b) + EPS;
}

//????????¨?????????????????????
P crosspointLL(P a1, P a2, P b1, P b2) {
	double d1 = cross(b2 - b1, b1 - a1);
	double d2 = cross(b2 - b1, a2 - a1);
	if (EQ(d2, 0))return P(INF, INF);
	P ret = a1 + d1 / d2 * (a2 - a1);
	if (isPointOnLine(b1, b2, ret) && isPointOnLine(a1, a2, ret)) {
		return ret;
	}
	else {
		return P(INF, INF);
	}
}
typedef tuple<P, bool, bool> pbb;

int dp[102][2];

signed main() {

	int T;
	cin >> T;
	rep(_, T) {
		int xa, ya, xb, yb, n;
		cin >> xa >> ya >> xb >> yb;
		P A(xa, ya), B(xb, yb);
		cin >> n;
		vector<pbb> vp;
		rep(i, n) {
			int xs, ys, xt, yt, o, l;
			cin >> xs >> ys >> xt >> yt >> o >> l;
			P s(xs, ys), t(xt, yt);
			if (crosspointLL(s, t, A, B) != P(INF, INF)) {
				vp.push_back(pbb(crosspointLL(s, t, A, B), o, l));
			}
		}
		sort(vp.begin(), vp.end(), [&](pbb &t0, pbb &t1) {
			return dist(A, get<0>(t0)) < dist(A, get<0>(t1));
		});
		rep(i, 102)rep(j, 2)dp[i][j] = INF;
		dp[0][0] = dp[0][1] = 0;
		rep(i, vp.size()) {
			int o = get<1>(vp[i]), l = get<2>(vp[i]);
			rep(j, 2) {
				if (o == 1) {
					if (j == l) {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
					}else{
						dp[i + 1][1 - j] = min(dp[i + 1][1 - j], dp[i][j] + 1);
					}
				}else
				if (o == 0) {
					if (j == l) {
						dp[i + 1][1 - j] = min(dp[i + 1][1 - j], dp[i][j] + 1);
					}
					else {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
					}
				}
			}
		}
		int ans = INF;
		rep(j, 2) {
			ans = min(dp[vp.size()][j], ans);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3068
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0

for a in [list(map(int, input().split())) for i in range(n)]:
  cal = 0
  for i in range(m):
    cal += a[i] * b[i]
  if cal + c > 0:
    ans += 1
  cal = 0

print(ans)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a ...int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		if ret > a[i] {
			ret = a[i]
		}
	}
	return ret
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	n2 := n * n
	p := make([]int, n2)
	for i := 0; i < n2; i++ {
		fmt.Fscan(r, &p[i])
		p[i]--
	}

	a := make([]bool, n2)
	d := make([]int, n2)
	for i := 0; i < n2; i++ {
		x, y := i/n, i%n
		d[i] = min(x, y, n-x-1, n-y-1)
	}

	var ans int
	for i := 0; i < n2; i++ {
		ans += d[p[i]]
		a[p[i]] = true

		var q []int
		q = append(q, p[i])
		for len(q) > 0 {
			j := q[0]
			q = q[1:]
			for _, k := range []int{-n, n, -1, 1} {
				nj := j + k
				nx, ny := nj/n, nj%n
				if nx <= 0 || nx >= n-1 || ny <= 0 || ny >= n-1 {
					continue
				}
				if a[j] {
					if d[nj] <= d[j] {
						continue
					}
					d[nj] = d[j]
					q = append(q, nj)
				} else {
					if d[nj] <= d[j]+1 {
						continue
					}
					d[nj] = d[j] + 1
					q = append(q, nj)
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 11072
N, K = (int(x) for x in input().split())
p = []
for i in range(N):
    p.append(int(input()))

p.sort()
minp = p[N - 1] - p[0]
for i in range(N - K + 1):
    minp = min(minp, p[i + K - 1] - p[i])

print(minp)

Measured memory_bytes: 7384
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
int n,ls[200];
char S[200][200];
int main()
{   scanf("%d",&n);
    for(rg int i=1;i<=n;i++) scanf("%s",S[i]),ls[i]=strlen(S[i]);
    for(rg int i=2;i<=n;i++)
    {   if(S[i][0]!=S[i-1][ls[i-1]-1]) {   puts("No");   return 0;   }
	for(rg int j=1;j<i;j++)
	    if(strcmp(S[i],S[j])==0) {   puts("No");   return 0;   }
    }
    puts("Yes");
}


Measured memory_bytes: 256
n1, n2, n3, kth = map(int, input().split())
a1 = sorted(map(int, input().split()), reverse=True)
a2 = sorted(map(int, input().split()), reverse=True)
a3 = sorted(map(int, input().split()), reverse=True)

ret = []
for i in range(n1):
    for j in range(n2):
        for k in range(n3):
            if (i + 1) * (j + 1) * (k + 1) > kth:
                break
            else:
                ret.append(a1[i] + a2[j] + a3[k])
ret.sort(reverse=True)
print('\n'.join(map(str, ret[:kth])))


Measured memory_bytes: 8708
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
typedef long long int ll;

int n,x,y,res[2100];

int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            res[min(abs(j-i),min(abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)))]++;
        }
    }
    for(int i=1;i<n;i++)
        cout<<res[i]<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int a = sc.nextInt();
  int b = sc.nextInt();
  int ans = 0;
  for(int i =1;i<=n;i++){
    int c = (i/10000) + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 +i%10;
    if(c>=a && c<=b)ans += i;
    if(i == n)System.out.println(ans);
  }
}}

Measured memory_bytes: 21588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()

	ans := make([]int, N)
	s := 0
	for i := 0; i < N; i++ {
		s ^= a[i]
	}
	for i := 0; i < N; i++ {
		ans[i] = s ^ a[i]
	}
	PrintI(ans...)
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 19544
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <functional>
#include <queue>
#include <cmath>
#include <string>
using namespace std;


int main()
{
	string s;
	cin >> s;
	if (s.length() == 2) {
		cout << s;
	}
	else
	{
		reverse(s.begin(), s.end());
		cout << s;
	}


}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef long long ll;

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

    return false;
}

struct Edge {
    int to,cost;
    int h,r;
    Edge(int to,int cost,int h,int r) :
        to(to),cost(cost),h(h),r(r){}
};
struct Passport{
    int len;
    int d;
    int S;
    int comps[10];
};

int N,M,H,K;
vector<Edge> G[102];
vector<Passport> pass;

typedef pair<int,pair<int,int> > Pi;
int d[102][30];
int dijk(int s,int t,int S) {
    typedef pair<int,int> P;
    rep(i,102) rep(j,30) d[i][j]=INF;
    d[s][0]=0;

    priority_queue<Pi,vector<Pi>,greater<Pi> > que;
    que.push(Pi(0,P(s,0)));

    while(que.size()) {
        Pi pi=que.top(); que.pop();
        int v=pi.sc.fr;
        int h=pi.sc.sc;

        rep(i,G[v].size()) {
            Edge e=G[v][i];
            int cost = e.cost;
            if((S>>e.r)&1) {
                cost=0;
            }

            if(h+e.h<=H && chmin(d[e.to][h+e.h],d[v][h]+cost)) {
                que.push(Pi(d[e.to][h+e.h],P(e.to,h+e.h)));
            }
        }
    }

    int ret=INF;
    rep(i,H+1) chmin(ret,d[t][i]);

    return ret;
}

int dp[300][1<<8];
int calc_dp() {
    dp[0][0]=0;
    // dp[i][S] i???????????§S???????????¨??????????°??????????
    rep(i,pass.size()) rep(S,1<<8) {
        int d=pass[i].d;
        int S_n=S|pass[i].S;

        chmin(dp[i+1][S_n],dp[i][S]+d);
        chmin(dp[i+1][S],dp[i][S]);
    }

}

void solve() {
    rep(i,300) rep(j,1<<8) dp[i][j]=INF;
    int P;
    int s,t;
    rep(i,102) G[i].clear();
    pass.clear();
    rep(i,M) {
        int a,b,c,h,r;
        cin>>a>>b>>c>>h>>r;
        r--;
        G[a].pb(Edge(b,c,h,r));
        G[b].pb(Edge(a,c,h,r));
    }
    cin>>s>>t;
    cin>>P;
    pass.resize(P);
    rep(i,P) {
        int l,d;
        cin>>l>>d;
        pass[i].len=l;
        pass[i].d=d;
        int Set=0;
        rep(j,l) {
            int k;
            cin>>k;
            k--;
            Set|=1<<k;
            pass[i].S=Set;
        }
    }

    calc_dp();

    int ans=INF;
    // rep(i,1<<3) printf("%d %d\n",i,dp[2][i]);
    rep(S,1<<8) {
        chmin(ans, dijk(s,t,S)+dp[pass.size()][S]);
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;

}

int main() {
    ios::sync_with_stdio(false);
    while(cin>>N>>M>>H>>K) {
        if(N+M+H+K==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <string.h>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int sum=a+b+c;
	if(sum>=22){
		cout<<"bust";
	}
	else{
		cout<<"win";
	}
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 

ll mod = 1e9 + 7;

#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

int main()
{
	fastio();
	int m1, d1, m2, d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 || m1 == 12)
	{
		if(d1 == 31)
			cout<<"1\n";
		else
			cout<<"0\n";
	}
	else if(m1 == 2)
	{
		if(d1 == 28)
			cout<<"1\n";
		else
			cout<<"0\n";
	}
	else
	{
		if(d1 == 30)
			cout<<"1\n";
		else
			cout<<"0\n";
	}
}

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

using namespace std;

// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

// repetition
#define FOR(i,m,n) for(ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for(ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)

// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl

//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
    vector<int> ls;
    ll l, r;
    cin >> l >> r;
    for(ll n = l; n < min(l + 2019, r+1); n++) {
        ls.push_back(n % 2019);
    }
    ll ans = INFTY;
    for(int i = 0; i < ls.size(); i++) {
        for(int j = i + 1; j < ls.size(); j++) {
            ll temp = (ls[i] * ls[j]) % 2019;
            ans = min(ans, temp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 500002;
#define endl '\n'
//#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()
const ll md = (ll) 1e9 + 7;
 
inline ll add(ll a, ll b) {
  a += b;
  if (a >= md) a -= md;
  return a;
}
 
inline ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}
 
inline ll mul(ll a, ll b) {
  return (ll) ((long long)((a%md) * (b%md)) % md);
}
 
inline ll power(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline ll inv(ll a) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

vector<int> fact(maxn+5);
void init (int n)
{
  fact[0] = 1;
  for(int i = 1;i<=n;i++)
  {
    fact[i] = mul(i,fact[i-1]);
  }
}
int nck(int n,int k)
{
  return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k])));
}

int32_t main()
{ 
   IOS


  int n,m;
  cin >> n >> m;
  init(5e5+5);
  int total = mul(nck(m,n),nck(m,n));
  total = mul(total,mul(fact[n],fact[n]));
  int ans = 0;
  for(int i = 1;i<=n;i++){
    int noterms = nck(n,i);
    int sel = mul(mul(nck(m,n),fact[n]),mul(nck(m-i,n-i),fact[n-i]));
    noterms = mul(noterms,sel);
    if(i%2 == 1){
      ans = add(ans,noterms);
    }
    else{
      ans = sub(ans,noterms);
    }
  }

  ans = sub(total,ans);
  cout<<ans<<endl;




  
}

Measured memory_bytes: 5240
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string s, t;
  cin >> s >> t;
  s += s;
  if (s.find(t) == string::npos) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
coupons = [tuple(map(int, input().split())) for _ in range(M)]
ans = min(A) + min(B)
for x, y, c in coupons:
    ans = min(ans, A[x-1]+B[y-1]-c)
print(ans)

Measured memory_bytes: 29032
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " " ;
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define setBits(n) __builtin_popcountll(n)
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 

void Panda() {
    int x, n;
    cin >> x >> n;
    vi in(n);
    for(auto &i : in) cin >> i;
    debug_out(in);
    if(n == 0) {cout << x << endl; return;}
    bool ok = false;
    int num = 0;
    while(!ok) {
    	if(find(ALL(in), x - num) == in.end()) {cout << abs(x - num) << endl;ok = true;}
    	else if(find(ALL(in), x + num) == in.end()) {cout << x + num << endl;ok = true;}
    	num++;
    }
}
  
int32_t main() {
 
    FAST;

    
    
    Panda();

    return 0; 
} 

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

const ll MOD = 1e9 + 7;
const int N = 2005;

vector<ll> mf(N, -1);
ll modfact(ll n) {
  if (mf[n] != -1) return mf[n];
  if (n == 0) return mf[0] = 1;
  return mf[n] = n * modfact(n-1) % MOD;
}

ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

vector<ll> mif(N, -1);
ll modinvfact(ll n) {
  if (mif[n] != -1) return mif[n];
  if (n == 0) return mif[0] = 1;
  return mif[n] = modinv(n) * modinvfact(n-1) % MOD;
}

ll modcomb(ll n, ll k) {
  return modfact(n) * modinvfact(k) % MOD * modinvfact(n-k) % MOD;
}

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    ll ans = 0;
    if (i == 1) {
      ans = n - k + 1;
      cout << ans << endl;
      continue;
    }
    for (int j = i-1; j <= n-k; ++j) {
      ans = (ans + modcomb(j-1, i-2) * (n-k-j+1)) % MOD;
    }
    ans = ans * modcomb(k-1, i-1) % MOD;
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	string s;
	cin >> s;
	regex re("A?KIHA?BA?RA?");
	if (regex_match(s, re))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<"\n"
#define prints(a) for(auto i: a) cout<<i<<" "; cout<<"\n"
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e]

const int maxA = 1e6+1;
bool v[maxA]; 

int main()
{
	fastio;
	int n, ans = 0;
	cin>>n;
	int a[n];
	read(a, n);

	sort(a, a+n);
	memset(v, 0, sizeof(v));

	for(int i=0; i<n-1; i++){
		if(a[i]==a[i+1]){
			v[a[i]] = 1;
			for(int j=a[i]+a[i]; j<=a[n-1]; j+=a[i])
				v[j] = 1;
		}
	}

	for(int i=0; i<n; i++){
		if(v[a[i]]==0){
			ans++;
			for(int j=a[i]+a[i]; j<=a[n-1]; j+=a[i])
				v[j] = 1;
		}
	}

	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 5416
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    """
    計算量の落とし方が全くわからんので以下のコードを参考に写経。。。
    https://atcoder.jp/contests/abc128/submissions/7712981
    """
    N, Q = map(int, input().split())
    work = []
    for _ in range(N):
        s, t, x = map(int, input().split())
        work.append((x, s - x, t - x))
    work.sort(key=lambda x: (x[0], x[1]))
    start = [int(input()) for _ in range(Q)]

    """
    工事箇所を原点にスライドさせる事で考察を易化しておく。
    各工事(x, s, t)に対して（既にs, tは原点への移動を考慮済み）s<=d<tなるdの個数を求めたい
    startは既に昇順に並んでいるので二分探索でs<=d_i<d_{i+1}<...<d_{j-1}<tなるi=left, j=rightを求める。

    そのあと[left, right)をxで埋めていくが、愚直に(right-left)回xを代入していくとO(Q)かかってTLEするので
    skip[left]=(以前に[left, right)を埋めたときのright)を格納しておく。
    これによりansの表を毎度全走査しなくてもよくなり書き込み範囲のオーバーラップがだいぶ削減される。

    しかしskipを使っても飛んだ先がまたskip命令入ってる可能性もあるから、AC出来るのはやや偶然感あり。。。
    """

    ans = [-1] * Q
    skip = [-1] * Q
    for x, s, t in work:
        left = bisect_left(start, s)
        right = bisect_left(start, t)
        while left < right:
            if skip[left] == -1:
                ans[left] = x
                skip[left] = right
                left += 1
            else:
                left = skip[left]

    for i in range(Q):
        print(ans[i])




if __name__ == "__main__":
    main()


Measured memory_bytes: 113244
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		if !(i%15 == 0 || i%3 == 0 || i%5 == 0) {
			ans += i
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1752
import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;

public class Main {
	int N;
	int[] A;
	ArrayList<HashMap<Integer, Integer>> memo;
	
	public int dfs(int i, int min){
		if(i >= N) return 0;
		if(memo.get(i).containsKey(min)){
			return memo.get(i).get(min);
		}
		int nn = (A[i] - 1) / min;
		int ans = dfs(i + 1, Math.max(min, A[i] + 1));
		for(int cnt = nn; cnt > 0; cnt--){
			int val = A[i] / nn;
			int m = (A[i] - 1) % cnt + 2;
			ans = Math.max(ans, dfs(i + 1, Math.max(min, m)) + cnt);
		}
		memo.get(i).put(min, ans);
		return ans;
	}
	
	public void solve() {
		N = nextInt();
		A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = nextInt();
		}
		memo = new ArrayList<>(N);
		for(int i = 0; i < N; i++){
			memo.add(new HashMap<>());
		}
		
		long ans = 0;
		int price = 1;
		for(int i = 0; i < N; i++){
			int nn = (A[i] - 1) / price;
			if(nn == 0){
				price = Math.max(price, A[i] + 1);
			}else{
				price = Math.max(price, 2);
				ans += nn;
			}
		}
		
		out.println(ans);
		
	}
	private static PrintWriter out;

	public static void main(String[] args) {
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}

	public static int nextInt() {
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(; i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong() {
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(; i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	public static String next() {
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;

	private static int read() {
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return(bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c) {
		return '!' <= c && c <= '~';
	}
}


Measured memory_bytes: 29596
N=int(input())
D={}
for i in range(N):
  s="".join(sorted(input()))
  if s in D:
    D[s]+=1
  else:
    D[s]=1
ans=0
for x in D.values():
  if x>=2:
    ans+=x*(x-1)//2
print(ans)

Measured memory_bytes: 17852
#include<cstdio>

int main(){
    int n;
    int arr[201];
    int sum = 0;
    for(int i=1;i<200;i++){
        arr[i]=sum+=i;
    }
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",arr[n]);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool check(string& s,string &t){
    vector<int> table(26,-1);
    REP(i,s.size()) table[s[i]-'a']=t[i]-'a';
    REP(i,s.size()) if(table[s[i]-'a']!=t[i]-'a') return false;
    return true;
}

signed main()
{
    string s,t; cin>>s>>t;
    if(check(s,t) and check(t,s))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
	int x, y;
	int cnt = 0;
	while (cin >> x >> y, x != 0 || y != 0) {
		for (int i = 1; i <= x; i++) {
			for (int j = 1; j < i; j++) {
				int k = y - (i + j);
				if (1 <= k && k < j) {
					cnt++;
				}
			}
		}
		cout << cnt << endl;
		cnt=0;
	}
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 405;

int n, m, ans;
bool a[MAXN][MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = read(), m = read();
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= n; j ++)
			a[i][j] = i ^ j;
	while (m --)
	{
		int x = read(), y = read();
		if (a[x][y])
		{
			a[x][y] = a[y][x] = 0;
			for (int i = 1; i <= n; i ++) if (!a[x][i]) a[y][i] = a[i][y] = 0;
			for (int i = 1; i <= n; i ++) if (!a[y][i]) a[x][i] = a[i][x] = 0;
		}
		else
			for (int i = 1; i <= n; i ++)
				a[i][x] = a[x][i] = a[i][y] = a[y][i] = 0;
	}
	for (int i = 1; i <= n; i ++)
		for (int j = i + 1; j <= n; j ++)
			ans += a[i][j];
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 512
s=input()
cnt_1=0
cnt_2=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        cnt_1+=1
for i in range(len(s)-1,0,-1):
    if s[i]!=s[i-1]:
        cnt_2+=1

print(min(cnt_1,cnt_2))

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

int main() {
  int n;
  cin >> n;
  vector<long long>sum(n);
  long long ans;
  cin >> sum[0];
  for(int i = 1;i < n;i++){
    long long a;
    cin >> a;
    sum[i] = a+sum[i-1];
  }
  ans = abs(sum[n-1]-2*sum[0]);
  for(int i = 1;i < n-1;i++){
    if(ans > abs(sum[n-1]-2*sum[i])) ans = abs(sum[n-1]-2*sum[i]);
  }
  cout << ans << endl;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        FastScannerA fs = new FastScannerA();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt(), m = fs.nextInt();
        if(n == 1 && m == 1) {
            System.out.println("Draw");
        } else if(n == 1) {
            System.out.println("Alice");
        } else if(m == 1) {
            System.out.println("Bob");
        } else {
            if(n > m) {
                System.out.println("Alice");
            } else if(n < m) {
                System.out.println("Bob");
            } else {
                System.out.println("Draw");
            }
        }

        out.close();
    }
}

class FastScannerA {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerA() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

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

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

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

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}

Measured memory_bytes: 21204
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,left,right;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<lint> from_left(n);
    vector<lint> from_right(n);
    for(int i=0;i<n;i++){
        left=i-a[i];
        right=i+a[i];
        if(0<=left)from_right[left]++;
        if(right<n)from_left[right]++;
    }
    lint ans=0;
    for(int i=0;i<n;i++){
        lint tmp=from_left[i]*from_right[i];
        ans+=tmp;
    }
    cout<<ans<<endl;
}


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

int n, k, x, a[10];

bool f(int n) {
	while (n > 0) {
		if (a[n % 10]) return true;
		n /= 10;
	}
	return false;
}

int main() {
	cin >> n >> k;
	while (k--) {
		cin >> x;
		a[x] = true;
	}
	while (f(n)) n++;
	cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;	cin>>n;
	n--;
	while(1){
		++n;
		int sum=0,count=0,num=0;
		int temp=n;
		while(temp>0){
			num=max(num,temp%10);
			sum+=temp%10;	count++;	temp/=10;
		}
		if(sum==count*num)	break;
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
count = 0
ca = 0
cb = 0
cab = 0
for i in range(N):
    si = input()
    for j in range(len(si)-1):
        if si[j] == "A" and si[j+1] == "B":
            count += 1
    if si[-1] == "A" and si[0] == "B":
        cab += 1
    else:
        if si[-1] == "A":
            ca += 1
        if si[0] == "B":
            cb += 1
    
#print(count)
if cab == 0:
    count += min(ca, cb)
elif ca == 0 and cb == 0:
    count += cab - 1
elif (ca == 0 and cb != 0) or (ca != 0 and cb == 0):
    count += cab
else:
    count += cab + min(ca, cb)

#print(ca, cb, cab)

print(count)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

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

    cin >> a >> b >> c;

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


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

void diceturn(int *top,int *front1,int *front2,char str[]){
	int tmp;
	if(strncmp(str,"North",5) == 0){
		tmp = *top;
		*top = *front1;
		*front1 = 7 - tmp;
	}
	else if(strncmp(str,"East",4) == 0){
		tmp = *top;
		*top = 7 - *front2;
		*front2 = tmp;
	}
	else if(strncmp(str,"West",4) == 0){
		tmp = *top;
		*top = *front2;
		*front2 = 7 - tmp;
	}
	else if(strncmp(str,"South",5) == 0){
		tmp = *top;
		*top = 7 - *front1;
		*front1 = tmp;
	}
	else if(strncmp(str,"Right",5) == 0){
		tmp = *front2;
		*front2 = 7 - *front1;
		*front1 = tmp;
	}
	else if(strncmp(str,"Left",4) == 0){
		tmp = *front1;
		*front1 = 7 - *front2;
		*front2 = tmp;
	}
}
int main(void){
	char str[20];
	int top,front1,front2;
	int n, i, sum;
	scanf("%d",&n);
	getchar();
	while(n != 0){
		sum = 1;
		top = 1; front1 = 2; front2 = 3;
		for(i = 0;i < n;i++){
			gets(str);
			diceturn(&top,&front1,&front2,str);
			sum += top;
		}
		printf("%d\n",sum);
		scanf("%d",&n);
		getchar();
	}
	return 0;
}

Measured memory_bytes: 604
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 2000

struct edge{
	long long int to, cap, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
bool used[MAX_V];

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size() - 1}); // 有向辺
	// G[to].push_back((edge){from, cap, G[from].size() - 1}); // 無向辺
}

// 増加パスを dfs で探す
long long int dfs(int v, int t, long long int f){
	if(v == t){
		return f;
	}
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			long long int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// s から t への最大流を求める
long long int max_flow(int s, int t){
	long long int flow = 0;
	while(true){
		fill(used, used + MAX_V, 0);
		long long int f = dfs(s, t, INF);
		if(f == 0){
			return flow;
		}
		flow += f;
	}
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	while(true){
		int m, n;
		cin >> m >> n;
		
		if(m + n == 0){
			break;
		}
		
		for(int i = 0; i < MAX_V; i++){
			G[i].clear();
		}
		
		long long int b[1000], r[1000];
		
		for(int i = 0; i < m; i++){
			add_edge(0, i + 1, 1);
			cin >> b[i];
		}
		
		for(int i = 0; i < n; i++){
			add_edge(m + i + 1, m + n + 1, 1);
			cin >> r[i];
		}
		
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				if(GCD(b[i], r[j]) != 1){
					add_edge(i + 1, m + j + 1, 1);
				}
			}
		}
		
		cout << max_flow(0, n + m + 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 15932
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define all(s) s.begin(), s.end()
#define fuck_you_scanf ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define si size()
 
const int N = 1e6 + 5;
int arr[N];
int DP[N];

int f(int idx, int n)
{
    if(idx == n - 1) return 0;
    if(idx > n) return N * N * N;
    if(DP[idx] != -1) return DP[idx];
    int ans1 = abs(arr[idx] - arr[idx + 1]) + f(idx + 1, n);
    int ans2 = abs(arr[idx] - arr[idx + 2]) + f(idx + 2, n);
    return DP[idx] = min(ans1, ans2);
}

int32_t main()
{
    memset(DP, -1, sizeof(DP));
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
    cout << f(0, n);
}

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

using namespace std;

struct union_find {
    vector<int> par;

    union_find(int N): par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        if (root(x) == root(y)) return;
        else par[root(y)] = root(x);
    }

    bool find(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    union_find uf(N + 1);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (uf.find(i + 1, p[i])) ans++;
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
using namespace std;
using Graph = vector<vector<int>>;


// 深さ優先探索
vector<bool> seen;
vector<ll> nodes_now; 
void dfs(const Graph &G, int v) {
    nodes_now.push_back(v);
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M, K; cin >> N >> M >> K;

    vector<ll> numF(N), numB(N);

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        numF[a]++;
        numF[b]++;
    }

    // グラフ入力受取
    Graph B(N);
    for (int i = 0; i < K; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        B[a].push_back(b);
        B[b].push_back(a);
    }

    vector<Pll> cc(N);

    // 全頂点が訪問済みになるまで探索
    ll cc_id = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        nodes_now = vector<ll>();
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ll size = nodes_now.size();
        for (auto u : nodes_now) {
            cc[u] = Pll(cc_id, size);
        }
        cc_id++;
    }
    rep(i, N) {
        for (auto v : B[i]) {
            if (cc[i].first != cc[v].first) continue;
            numB[i]++;
        }
    }

    rep(i, N) {
        ll ans = cc[i].second - numB[i] - numF[i] - 1;
        cout << ans;
        if (i < N-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 16892
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll calc_gcd(ll x, ll y) {
    if (y == 0) {
        return x;
    }
    return calc_gcd(y, x % y);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> X(N);
    for (auto& x : X) {
        cin >> x;
    }
    if (N == 1) {
        cout << abs(K - X.front()) << endl;
    } else {
        X.push_back(K);
        sort(all(X));
        ll gcd = 0;
        rep(i, 0, N) {
            gcd = calc_gcd(gcd, X[i + 1] - X[i]);
        }
        cout << gcd << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

int N; ll M;
ll dp[100003], dp2[100003];
bool vis[100003];
vector<int> edg[100003];


class SegmentTree {
private:
	int num;
	vector<ll> dat;

	// TODO: Change the operator and the identity element.
	static const ll INI = 1;
	ll op(ll a, ll b) {
		return a*b % M;
	}

public:
	SegmentTree(int n_) {
		num = 1;
		while (num < n_) num *= 2;
		dat = vector<ll>(2 * num, INI);
	}

	// Update the k-th value (0-indexed) to a.
	void update(int k, ll a) {
		k += num - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}

	// Get the value of the range [a, b).
	// k: The index of the node.
	// [left, right): The range corresponds to the k-th node.
	// Call like getval(a, b).
	ll getval(int a, int b, int k = 0, int left = 0, int right = -1) {
		if (right < 0) right = num;
		if (right <= a || b <= left) return INI;
		if (a <= left && right <= b) return dat[k];
		ll vleft = getval(a, b, 2 * k + 1, left, left + (right - left) / 2);
		ll vright = getval(a, b, 2 * k + 2, left + (right - left) / 2, right);
		return op(vleft, vright);
	}
};


ll func(int pos) {
	ll ret = 1;
	dp[pos] = 0;
	for (int to : edg[pos]) {
		if (dp[to] != -1) continue;
		ret *= (func(to) + 1)%M;
		ret %= M;
	}
	return dp[pos] = ret;
}

void func2(int pos) {
	int cnt = 0;
	for (int to : edg[pos]) {
		if (dp2[to] != -1) continue;
		cnt++;
	}
	SegmentTree seg(cnt + 1);
	cnt = 0;
	for (int to : edg[pos]) {
		if (dp2[to] != -1) continue;
		seg.update(cnt++, dp[to] + 1);
	}
	seg.update(cnt++, dp2[pos] + 1);
	int c = 0;
	for (int to : edg[pos]) {
		if (dp2[to] != -1) continue;
		seg.update(c, 1);
		dp2[to] = seg.getval(0, cnt);
		seg.update(c++, dp[to] + 1);
		func2(to);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N - 1; i++) {
		int x, y; cin >> x >> y;
		x--; y--;
		edg[x].push_back(y);
		edg[y].push_back(x);
	}
	for (int i = 0; i < N; i++) dp[i] = dp2[i] = -1;
	dp2[0] = 0;
	func(0);
	func2(0);
	for (int i = 0; i < N; i++) cout << dp[i]*(dp2[i] + 1) % M << endl;
	return 0;
}

Measured memory_bytes: 27648
#include <stdio.h>
int main(){
	int a,b,c,d,h1,h2,k1,k2,h,k;
	scanf("%d%d%d%d%d%d%d%d",&h1,&h2,&k1,&k2,&a,&b,&c,&d);
	h=a*h1+c*(h1/10)+b*h2+d*(h2/20);
	k=a*k1+c*(k1/10)+b*k2+d*(k2/20);
	if(h>k){
		printf("hiroshi\n");
	}else if(h<k){
		printf("kenjiro\n");
	}else{
		printf("even\n");
	}
	return 0;
}

Measured memory_bytes: 2680
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var spl = input.ReadLine().Split(' ');
        var t = int.Parse(spl[0]);
        var a = int.Parse(spl[1]);
        var ary = ToIntArray(input.ReadLine(), n);

        var min = double.MaxValue;
        var idx = 0;

        for(int i=0; i<n; i++) {
            var x = (double)t - ary[i] * 0.006;
            var ax = Math.Abs((double)a - x);
            if(ax < min) {
                idx = i;
                min = ax;
            }
        }

        return idx+1;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	scanf("%d", &N);
	int tab[26][50];
	memset(tab, 0, sizeof(int) * 26 * 50);
	for (int i = 0; i < N; i++) {
		char buf[100];
		scanf(" %s", buf);
		int n = strlen(buf);
		for (int j = 0; j < n; j++) {
			tab[buf[j] - 'a'][i]++;
		}
	}
	for (int i = 0; i < 26; i++) {
		int mi = 50;
		for (int j = 0; j < N; j++) {
			mi = min(tab[i][j], mi);
		}
		for (int j = 0; j < mi; j++) {
			printf("%c", 'a' + i);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.string;
import std.conv;

int main()
{
    while (true) {
        string[] str = readln().chomp().split();
        int n = str[0].to!int;
        int m = str[1].to!int;

        if (m == n && n == 0) break;
        int[1001] ans;
        int c = n - 1;
        for (int i = 0; i < n; i++) ans[i] = i + 1;
        while (n > 1) {
            c = (c + m) % n;
            for (int i = c; i < n - 1; i++) ans[i] = ans[i + 1];
            n--;
            c--;
        }
        writeln(ans[0]);
    }

    return 0;
}

Measured memory_bytes: 1044