akhauriyash/Code-Regression huggingface dataset:
var
 i,n,s,sum:longint;
 a:array[0..100000] of longint;
procedure kp(l,r:longint);
var i,j,m,t:longint;
begin
 i:=l; j:=r;
 m:=a[(l+r) div 2];
 repeat
  while a[i]<m do inc(i);
  while a[j]>m do dec(j);
  if i<=j then
   begin
    t:=a[i]; a[i]:=a[j]; a[j]:=t;
    inc(i); dec(j);
   end;
 until i>j;
 if l<j then kp(l,j);
 if i<r then kp(i,r);
end;
begin
 readln(n);
 for i:=1 to n do
  readln(a[i]);
 kp(1,n);
 s:=1;
 for i:=2 to n+1 do
  begin
   if a[i]=a[i-1] then inc(s)
    else begin if s mod 2=1 then inc(sum); s:=1; end;
  end;
 writeln(sum);
end.

Measured memory_bytes: 512
n,a,b=map(int,input().split())
s=input()
clear=0
bclear=0
for i in range(n):
  if (s[i]=="a"):
    if (clear<a+b):
      print("Yes")
      clear+=1
    else:
      print("No")
  elif (s[i]=="b"):
    if (clear<a+b and bclear<b):
      print("Yes")
      clear+=1
      bclear+=1
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 4016
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a != b && a != c)
        cout << a;
    if (b != a && b != c)
        cout << b;
    if (c != a && c != b)
        cout << c;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

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

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, C;
    cin >> N >> C;

    vector<ll> s(N);
    vector<ll> t(N);
    vector<ll> c(N);

    vector<vector<bool>> A(C, vector<bool>(100010, false));

    REP(i, N){
        cin >> s[i] >> t[i] >> c[i];
        
        ll start = s[i];
        ll end = t[i]; 
        for(ll j=start; j<=end; j++){
            A[c[i]-1][j] = true;
        }
    }

    ll ans = 0;
    REP(i, 100010){
        ll temp = 0;
        REP(j, C){
            if(A[j][i]) temp++;
        }
        ans = max(ans, temp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5860
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

const int MXV=2e5;
vl G[MXV];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vl indegree(N);
    vvl k(N);
    rep(i,N+M-1){
        int u,v;
        cin >> u >> v;
        u--;v--;
        G[u].pb(v);
        k[v].pb(u);
        indegree[v]++;
    }
    vl sorted;
    queue<int> que;
    rep(i,N){
        if(indegree[i]==0) que.push(i);
    }
    while(que.size()){
        int v=que.front();
        que.pop();
        rep(i,G[v].size()){
            int nv=G[v][i];
            indegree[nv]--;
            if(indegree[nv]==0){
                que.push(nv);
            }
        }
        sorted.pb(v);
    }
    vl inv_pos(N);
    rep(i,N){
        inv_pos[sorted[i]]=i;
    }

    rep(i,N){
        ll res=-1;
        if(k[i].size()==0){
            cout << 0 << endl;
            continue;
        }
        int now;
        rep(j,k[i].size()){
            //cout << i << ' ' << k[i][j] << endl;
            if(inv_pos[k[i][j]]<inv_pos[i]){
                if(chmax(res,inv_pos[k[i][j]])) now=k[i][j];
            }
        }
        cout << now+1 << endl;
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 18956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

struct Sieve {
    vector<int> primes;
    vector<int> _isPrime;
    Sieve(int n) : _isPrime(n+1, 1) {
        buildPrimes();
    }
    void buildPrimes() {
        _isPrime[0] = _isPrime[1] = 0;
        int n = _isPrime.size();
        REP(i, 2, n) {
            if(_isPrime[i]) {
                primes.push_back(i);
                for(int j = i+i; j < n; j += i) _isPrime[j] = false;
            }
        }
    }
    bool isPrime(int i) {
        return _isPrime[i];
    }
};

int main(){
    const int MAX_N = 1e5+10;
    int q;
    cin >> q;
    Sieve sieve(MAX_N);
    vi cnt(MAX_N);
    rep(i, MAX_N) {
        if(sieve.isPrime(i) && sieve.isPrime((i+1)/2)) cnt[i] = 1;
    }
    rep(i, MAX_N-1) {
        cnt[i+1] += cnt[i];
    }
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l-1] << endl;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  int c = 0;
  rep(i, n) {
    int mj = i;
    repi(j, i + 1, n) {
      if (a[mj] > a[j]) mj = j; 
    }
    if (i != mj) {
      swap(a[i], a[mj]);
      c++;
    }
  }
  cout << a << '\n';
  cout << c << '\n';
}



Measured memory_bytes: 3164
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define MP make_pair 
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
typedef pair<int, int> PII; 
const double eps = 1e-9;
const double PI = acos(-1);
const LL INFF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const int MAX = 1e5+7;
int a[MAX];
int main(void){
	DRII(n, k);
	rep1(i, 1, n+1) scanf("%d", a + i);
	printf("%d\n", (n + k - 3) / (k-1));
	return 0;
}


Measured memory_bytes: 640
package main

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

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)
var N, ss, ans, A, B, C int

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// A := strings.Split(nextLine(), " ")

	X := strings.Split(nextLine(), " ")

	// Z := strings.Split(nextLine(), " ")
	// n, _ := strconv.Atoi(input[0])

	N, _ = strconv.Atoi(X[0])
	A, _ = strconv.Atoi(X[1])
	B, _ = strconv.Atoi(X[2])
	C, _ = strconv.Atoi(X[3])

	// K, _ := strconv.Atoi(X[2]) //strconv.ParseInt(X[2], 10, 64)

	// Y := strings.Split(nextLine(), " ")

	arr := make([]int, N)
	dp := make([]int, N)
	ans = 10000
	ss = A + B + C
	// sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	for i := 0; i < N; i++ {
		Y := strings.Split(nextLine(), " ")

		a, _ := strconv.Atoi(Y[0])
		arr[i] = a

	}
	dfs(dp, 0, arr)

	/*文字列連結高速化
	初期化:buf := make([]byte, 0,N+1)
	連結:buf=append(buf,str)
	出力:string(buf)
	*/
	// sort.Sort(sort.Reverse(dp[M][N]))

	fmt.Fprintln(wtr, ans)

	_ = wtr.Flush()
}

func dfs(dp []int, times int, arr []int) {
	if times >= N {
		ans = min(ans, calc(dp, arr))
		return
	}

	for i := 0; i < 4; i++ {
		dp[times] = i
		dfs(dp, times+1, arr)
	}
}

func calc(dp, arr []int) int {
	var cost, AA, BB, CC int

	memo := make([]int, 4)
	for i := 0; i < len(dp); i++ {
		memo[dp[i]]++
		if dp[i] == 1 {
			AA += arr[i]
		} else if dp[i] == 2 {
			BB += arr[i]
		} else if dp[i] == 3 {
			CC += arr[i]
		}
	}
	cost += abs(A-AA) + abs(B-BB) + abs(C-CC)

	for i := 1; i < 4; i++ {
		a := memo[i]
		if a < 1 {
			cost += 10000
		} else {
			cost += (a - 1) * 10
		}
	}

	return cost
}

type otosidama struct {
	x float64
	v string
}

// func culc(a, b, c, d int64) (ret int64) {
// 	ret = abs(a-c) + abs(b-d)
// 	return
// }

func chmax(a *string, b string) {
	if len(*a) < len(b) {
		*a = b
	} else if len(*a) == len(b) && *a < b {
		*a = b
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return 0 //abs(a - b)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}
func sum(a []int) (sum int) {
	for _, num := range a {
		sum += num
	}
	return
}

type item struct {
	x int
	// y     int
	// point int
}

type que []item

func (p que) Len() int {
	return len(p)
}

func (p que) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p que) Less(i, j int) bool {

	// return p[i].point > p[j].point //p[i].x+p[i].y > p[j].x+p[j].y
	return p[i].x < p[j].x
}

func (p que) Push(in int) {
	p = append(p, item{x: in})
	sort.Sort(p)
}

func (p que) Pop() int {
	res := p[0].x
	p = p[1:]
	return res
}

func (p que) Peek() int {
	return p[0].x
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;


string c[3];


int main(){
  cin>>c[0];
  cin>>c[1];
  cin>>c[2];

  cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;

  return 0;
}


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

using namespace std;


int main()
{
	int n,i;
	cin>>n;
	int h[n+1];
	for(i=1;i<=n;i++)cin>>h[i];
	long long cost[n+1];cost[1]=0;cost[2]=abs(h[1]-h[2]);
	for(i=3;i<=n;i++)
	{
		cost[i]=min((cost[i-2]+abs(h[i]-h[i-2])),(cost[i-1]+abs(h[i]-h[i-1])));
	}
	cout<<cost[n];
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define MAX 10001
#define INF (1<<29)
 
int main()
{
    int Tc,N;
    string s;
    cin >> Tc;
    while(Tc--)
    {
        cin >> N >> s;
        bool b[2][MAX] = {{}};
        for(int i = 0 ; i <= N ; i++)
        {
            if(i != 0 && s[2*i-1] == 'Y') b[0][i] = 1;
            if(i != N && s[2*i] == 'Y') b[0][i] = 1;
            if(i != 0 && s[2*i-1+2*N] == 'Y') b[1][i] = 1;
            if(i != N && s[2*i+2*N] == 'Y') b[1][i] = 1;
        }
         
        auto solve = [=]()
            {
                vector<vector<int>> dp(2, vector<int>(MAX, INF));
                if(b[0][0] && b[1][0])
                {
                    dp[1][0] = 2;
                }
                if(b[0][0] && !b[1][0])
                {
                    dp[0][0] = 1;
                    dp[1][0] = 1;
                }
                if(!b[0][0] && b[1][0])
                {
                    dp[1][0] = 2;
                }
                if(!b[0][0] && !b[1][0])
                {
                    dp[0][0] = 0;
                    dp[1][0] = 1;
                }
                
                for(int i = 1 ; i <= N ; i++)
                {
                    if(b[0][i] && b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+4,dp[1][i-1]+3));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+3,dp[1][i-1]+3));
                    }
                    if(b[0][i] && !b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+2,dp[1][i-1]+2));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+2,dp[1][i-1]+2));
                    }
                    if(!b[0][i] && b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+4,dp[1][i-1]+3));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+3,dp[1][i-1]+2));
                    }
                    if(!b[0][i] && !b[1][i])
                    {
                        dp[0][i] = min(dp[0][i],min(dp[0][i-1]+1,dp[1][i-1]+2));
                        dp[1][i] = min(dp[1][i],min(dp[0][i-1]+2,dp[1][i-1]+1));
                    }
                }
                return dp[0][N];
            };
         
        cout << solve() << endl;
    }   
    return 0;
}

Measured memory_bytes: 3220
import math

# n以下の素数を列挙
def Primes(n):
    Prime = []
    Table = list(range(2, n+1))
    for k in range(2, int(math.sqrt(n))+1):
        if k == Table[0]:
            Prime.append(Table[0])
            Table = [i for i in Table if i % k]
    return Prime + Table if n >= 2 else []


# 素因数分解
def PrimeDecomp(m):
    n = m
    Dict = {}
    for p in Primes(int(math.sqrt(m))):
        for _ in range(1, m):
            if n % p == 0:
                n //= p
                Dict.setdefault(p, 0)
                Dict[p] += 1
            else:
                break
    if n > 1:
        Dict[n] = 1
    return Dict


# 約数列挙
def Divisors(m):
    Divisor = [1]
    for p in PrimeDecomp(m).keys():
        Table = []
        for j in range(PrimeDecomp(m)[p]+1):
            Table.extend([d*p**j for d in Divisor])
        Divisor = Table
    return sorted(Divisor)


Div = Divisors(int(input()))
print(len(str(Div[len(Div)//2])))


Measured memory_bytes: 7472
let i=readLine()!.characters.split(" ").map{Int(String($0))!},N=i[0],H=i[1],W=i[2]
var ans=0
for _ in 0..<N {
  let i=readLine()!.characters.split(" ").map{Int(String($0))!}
  if i[0]>=H&&i[1]>=W{ans++}
}
print(ans)

Measured memory_bytes: 4208
import java.util.*;
// import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        int num = sc.nextInt();

        ArrayList<Integer> array = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            int tmp = sc.nextInt();
            array.add(tmp);
        }

        int num_query = sc.nextInt();

        for (int i = 0; i < num_query; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            List<Integer> sub = array.subList(l, r);
            Collections.reverse(sub);

            for (int j = l; j < r; j++) {
                array.set(j, sub.get(j - l));
            }
        }

        for (int i = 0; i < array.size(); i++) {
            sb.append(array.get(i));
            if (i != array.size() - 1) sb.append(' ');
        }

        System.out.println(sb);
        
        sc.close();
    }
}



Measured memory_bytes: 34152
#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 int INF = 1001001001;
main(){
  int K;
  cin>>K;
  string S;
  cin>>S;
  if(S.size()<=K){cout<<S<<endl;}
  else{cout<<S.substr(0,K)<<"..."<<endl;}
  return 0;
  }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int a,b,t;
    cin >> a >> b >> t;
    cout << int(t/a)*b << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

int main(){

	unsigned long long a,b,x = 0;
	unsigned long long count = 0;

	scanf("%llu %llu %llu",&a,&b,&x);

	count = b/x - a/x;
	if( a%x == 0 ){
		count ++;
	}

	printf("%llu",count);

	return 0;

}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def print_ans(M1, M2):
    """Test Case
    >>> print_ans(11, 11)
    0
    >>> print_ans(11, 12)
    1
    """
    if M1 == M2:
        print("0")
    else:
        print("1")

if __name__ == '__main__':
    M1, D1 = map(int, input().rstrip().split())
    M2, D2 = map(int, input().rstrip().split())
    print_ans(M1, M2)


Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	deque<int> b;
	int a;
	for (int i = 0; i < n - 1; ++i) {
		cin >> a;
		if (i % 2 != n % 2) {
			b.push_front(a);
		} else {
			b.push_back(a);
		}
	}

	cin >> a;
	b.push_front(a);

	for (int i = 0; i < n; ++i) {
		cout << b[i] << " ";
	}

	cout << "\n";

	return 0;

}

Measured memory_bytes: 3072
n, m = map(int, input().split())
list_ab = []
for _ in range(m):
    a, b = map(int, input().split())
    list_ab.append((a - 1, b - 1))


# Unionfind
_group = {i: i for i in range(n)}
_size = {i: 1 for i in range(n)}


def group(i):
    vertices = []
    while _group[i] != i:
        vertices.append(i)
        i = _group[i]
    for v in vertices:
        _group[v] = i
    return i


def size(i):
    return _size[group(i)]


convenience = [0]

for a, b in list_ab[::-1]:
    ga, gb = group(a), group(b)

    if ga != gb:
        convenience.append(convenience[-1] + size(ga) * size(gb))
        if ga < gb:
            _group[group(b)] = ga

            _size[ga] += _size[gb]
        else:
            _group[group(a)] = gb
            _size[gb] += _size[ga]
    else:
        convenience.append(convenience[-1])


convenience.reverse()
inconvenience = [n * (n - 1) // 2 - c for c in convenience[1:]]


for i in inconvenience:
    print(i)


Measured memory_bytes: 45328
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
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; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl kai(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,桁数回の演算だからだいたいO(logN)くらい?



signed main(){
    cout << fixed << setprecision(10);
    int d;
    cin >> d;
    int c[26];
    rep(i,26)cin >> c[i];
    int s[d][26];
    rep(i,d){
        rep(j,26)cin >> s[i][j];
    }
  	rep(i,d)cout << 1 << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
ll P = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll ans = 1;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> c(n);
  c[0] = 3;
  for (int i = 0; i < n; i++) {
    if (c[a[i]] == 0) {
      ans = 0;
      break;
    } else {
      ans *= c[a[i]];
      ans %= P;
      c[a[i]]--;
      c[a[i] + 1]++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define uint unsigned int
#define ull unsigned long long
#define INF 1000000001
#define LINF 1000000000000000001
#define ll long long
#define ld long double
#define M 1000000007
#define E 0.0000001
#define N (1<<17)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define pld pair<long double, long double>
#define cll complex<long long>
#define cld complex<long double>
#define X real()
#define Y imag()
#define C 'a'
#define F first
#define S second
#define PI 3.1415926535897932384626433

using namespace std;

int main () {
    string s;
    cin>>s;
    cout<<(int)s.length() / 2 - (int)count(s.begin(), s.end(), 'p')<<endl;
}


Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *A, = map(lambda x: int(x) - 1, input().split())

    P = []
    t = 0
    for i in range(N + 1):
        P.append(t)
        t = A[t]

    t1 = t2 = 0
    t = 0
    first_visit = [-1] * N
    while t <= N:
        town = P[t]
        if first_visit[town] < 0:
            first_visit[town] = t
        else:
            t1 = first_visit[town]
            t2 = t
            break
        t += 1

    term = t2 - t1
    cycle = (K - t1) // term if K >= t1 else 0
    rest = K - term * cycle - t1 if K >= t1 else 0
    ans = P[t1] if K >= t1 else P[K]
    for i in range(rest):
        ans = A[ans]
    print(ans + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 111652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int N,M;
	long long x[1000],y[1000],z[1000];

	scanf("%d %d", &N, &M);
	for(int i=0;i<N;i++){
		scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
	}

	long long max = 0;
	for(int k=0;k<8;k++){
		long long x2[1000],y2[1000],z2[1000];
		for(int i=0;i<N;i++){
			if(k%2==0){
				x2[i] = x[i];
			}else{
				x2[i] = -x[i];
			}
			if((k/2)%2==0){
				y2[i] = y[i];
			}else{
				y2[i] = -y[i];
			}
			if((k/4)%2==0){
				z2[i] = z[i];
			}else{
				z2[i] = -z[i];
			}
		}
		long long sum[1000];
		for(int i=0;i<N;i++){
			sum[i] = x2[i] + y2[i] + z2[i];
		}
		sort(sum,sum+N);
		reverse(sum,sum+N);
		long long tmp = 0;
		for(int i=0;i<M;i++) tmp += sum[i];
		if(max < tmp) max = tmp;
	}

	printf("%lld\n", max);

	return 0;
}


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

int main(){
	long long n,a,b;
	
	cin>>n>>a>>b;
	
	long long s=a+b, groups, r=0;
	groups = n/s;
	if (n%s>a) r=a; else r=n%s;
	
	cout << groups * a + r;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

enum direction {right, down, left, up};

int main() {
	char input[16][16];

	int ans = 0;
	int i, j;
	int now = right + 128;
	int roop = 0;

	for(i = 0; i < 16; i++)
		for(j = 0; j < 16; j++)
			input[i][j] = '0';

	for(i = 0; i < 9; i++) {
		for(j = 1 - i % 2; j < 9; j += 2)
			scanf("%c", &input[i][j]);

		getchar();
	}
/*	
	   for(i = 0; i < 16; i++) {
	   for(j = 0; j < 16; j++)
	   putchar(input[i][j]);
	   putchar('\n');
	   }
*/	 
	i = j = 0;

	do{
		switch(now % 4) {
			case right:
				if(input[i][j + 1] == '1') {
					if(i > 0 && input[i - 1][j + 2] == '1')
						now--;

					j += 2;
					putchar('R');
				}

				else
					now++;

				break;

			case down:
				if(input[i + 1][j] == '1') {
					if(input[i + 2][j + 1] == '1')
						now--;

					i += 2;
					putchar('D');
				}

				else 
					now++;

				break;

			case left:
				if(j > 0 && input[i][j - 1] == '1') {
					if(input[i + 1][j - 2] == '1')
						now--;

					j -= 2;
					putchar('L');
				}

				else 
					now++;

				break;

			case up:
				if(i > 0 && input[i - 1][j] == '1') {
					if(j > 0 && input[i - 2][j - 1] == '1')
						now--;

					i -= 2;
					putchar('U');
				}

				else 
					now++;

				break;
		}
	} while(i + j || !(now % 4 == left || now % 4 == up));

	putchar('\n');

	return 0;
}

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

using P=pair<int,int>;
using Graph=vector<vector<int>>;
const int SIZE=100010;
const int INF=1e9;

int N;
Graph G;
int num[SIZE],L[SIZE],R[SIZE];
bool ok=true;

void parity_check(int v,int p,int parity)
{
   if(num[v]>=0 and num[v]%2!=parity) ok=false;
   for(int u:G[v]) if(u!=p){
      parity_check(u,v,parity^1);
   }
}

P calc(int v,int p)
{
   if(num[v]>=0) L[v]=R[v]=num[v];
   for(int u:G[v]) if(u!=p){
      P child=calc(u,v);
      L[v]=max(L[v],child.first-1);
      R[v]=min(R[v],child.second+1);
   }
   if(L[v]>R[v]) ok=false;
   return make_pair(L[v],R[v]);
}

void write(int v,int p)
{
   for(int u:G[v]) if(u!=p){
      if(L[u]<=num[v]-1 and num[v]-1<=R[u]) num[u]=num[v]-1;
      else num[u]=num[v]+1;
      write(u,v);
   }
}

int main()
{
   cin>>N;
   G.resize(N);
   for(int i=0;i<N-1;i++){
      int a,b; cin>>a>>b;
      a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   int K; cin>>K;
   for(int i=0;i<N;i++) num[i]=-1;
   for(int i=0;i<K;i++){
      int v,p; cin>>v>>p;
      num[v-1]=p;
   }

   int root=-1;
   for(int i=0;i<N;i++) if(num[i]>=0) root=i;

   parity_check(root,-1,num[root]%2);
   if(!ok){
      cout<<"No"<<endl; return 0;
   }

   for(int i=0;i<N;i++) L[i]=-INF,R[i]=INF;
   calc(root,-1);
   if(!ok){
      cout<<"No"<<endl; return 0;
   }
   write(root,-1);
   cout<<"Yes"<<endl;
   for(int i=0;i<N;i++) cout<<num[i]<<endl;
   return 0;
}


Measured memory_bytes: 12288
#! /usr/bin/env python
# coding: utf-8


def test(n, a):
    count = 0
    while(True):
        for i in range(n):
            a[i] = int(a[i])
            if a[i]%2 == 0:
                a[i] /= 2
                if i == n-1:
                    count += 1
            else:
                return count
    return count

if __name__ == "__main__":
    n = int(input())
    a = input().split(" ")
    print(test(n, a))

Measured memory_bytes: 3060
using System;

class Program{
        static void Main(string[] args){
            int[] mt = new int[10];
            int top=0,pos=-1;
            for(int i=0; i < 10; i++){
                mt[i] = int.Parse(Console.ReadLine());
            }
            for(int j=0; j<3; j++){
                top=0;
                for(int k=0; k<10; k++){
                    if(top < mt[k]){
                        top=mt[k];
                        pos=k;
                    }
                }
                Console.WriteLine(top);
                mt[pos] = 0;
            }
        }
    }


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

int x,y;
cin>>x>>y;
int count=0;
int ans=0;
int l=0;
if(y!=1)
{
 do
{
    if(!l)
   {
     ans+=x;
     count++;
     l=1;
   }
   else
   {
       ans--;
       ans+=x;
       count++;
   }

} while(ans<y);
//cout<<ans<<endl;
cout<<count<<endl;
}
else
    cout<<0<<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>

using namespace std;
int main(){
    unordered_set<int> s;
    int n;
    cin >> n;
    while(n --){
        int num;
        cin >> num;
        if(s.count(num)) {
            cout << "NO" << endl;
            return 0;
        }
        s.insert(num);
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
	ll n,m;
	cin>>n>>m;
	ll arr[n];
	pair<ll,ll>vind[m];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	for(int i=0;i<m;i++)
		cin>>vind[i].second>>vind[i].first;
	sort(vind,vind+m,greater<pair<ll,ll>>());
	//ll sum[n];
	//sum[0]=arr[0];
	/*for(int i=1;i<n;i++)
	{
		//sum[i]=arr[i]+sum[i-1];
	}*/
	ll k=0;
	for(ll i=0;i<m;i++)
	{
		ll j=0;
		for(j=k;j<min(k+vind[i].second,n);j++)
		{
			if(arr[j]<vind[i].first)
			{
				arr[j]=vind[i].first;
			}
			else if(vind[i].first<=arr[j])
			{
				k=n;
				break;		
			}
		}
		if(k==n)
			break;
		
			k=k+vind[i].second;
	}
	ll sum=0;
	for(int i=0;i<n;i++)
		sum += arr[i];
	cout<<sum<<"\n";
}


Measured memory_bytes: 5940
inputs = []

while true
  h, w = $stdin.readline.split(" ").map {|s| s.to_i }

  if h == 0 && w == 0
    break
  end

  inputs.push([h, w])
end

inputs.each do |h, w|
  (1..h).each_with_index do |y, i|
    if i == 0 || i == h - 1
      puts "#" * w
    else
      print "#", "." * (w - 2), "#", "\n"
    end
  end

  puts
end



Measured memory_bytes: 6872
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		if(6<=A && A<=12) {
			B /= 2;
		}else if(A<=5) {
			B = 0;
		}
		System.out.println(B);
		sc.close();
	}
}


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

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

const long long INF = 1LL << 60;

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

  cout << 1110 - n << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int x;cin >> x;
	if(x >= 30)	cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;

int main() {
    vector <int> terms {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int K;
    cin >> K;
    --K;

    cout << terms[K] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<ll> H(N); rep(i,N) std::cin >> H[i];

  std::sort( all(H), std::greater<>() );

  ll ans = 0;
  for(int i=K; i<N; i++) ans += H[i];

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
// My Version
#include<iostream>
using namespace std;
static const int MAX = 100;

void trace(int A[], int N) {
	for ( int i = 0; i < N; i++ ) {
		if ( i > 0 ) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void insertionSort(int A[], int N) {
	int i, j, v;
	for ( i = 1; i < N; i++ ) {
		v = A[i];
		j = i - 1;
		while ( j >= 0 && A[j] > v ) {
			A[j+1] = A[j];
			j--;
		} 
		A[j+1] = v;
		trace(A, N);
	}
}

int main() {
	int N, i, j;
	int A[MAX];
	
	cin >> N;
	for ( i = 0; i < N; i++ ) cin >> A[i];
	
	trace(A, N);
	insertionSort(A, N);
	
	return 0;
}


Measured memory_bytes: 3108
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n + 2), y(n + 2);
  x[0] = y[0] = 1;
  rep(i, n) cin >> x[i + 1] >> y[i + 1];
  x[n + 1] = w, y[n + 1] = h;
  n += 2;
  auto m = vectors(n, n, 0LL);
  rep(i, n) rep(j, n) m[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]);
  using state = tuple<int, int, int>;
  priority_queue<state, vector<state>, greater<state>> q; // d, v, r
  q.emplace(0, 0, 0);
  auto dist = vectors(n, w + h + 1, INF);
  while (q.size()) {
    int d, v, r;
    tie(d, v, r) = q.top();
    q.pop();
    if (dist[v][r] < d) continue;
    rep(u, n) {
      if (v == u) continue;
      int cost = m[u][v] - r - 1;
      if (v == 0 || u == n - 1) cost++;
      cost = max(0LL, cost);
      if (cmin(dist[u][cost], d + cost)) q.emplace(dist[u][cost], u, cost);
    }
  }
  cout << *min_element(all(dist[n - 1])) << endl;
}



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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		temp += n % 10;
		n = n / 10;
		// temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}


int main() {
	int i,  n, k, c = 0, sum = 0;
	c_p_c();
		// cout<<"Sd"<<endl;>
	cin>>n;
	mll m;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>k;
		m[k]++;
	}
		cout<<m.size()<<endl;





	

}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stack>
using namespace std;

int main(){
	stack<int> a;
	int k;
	while (scanf("%d", &k) != EOF) {
		if(k!=0)a.push(k);
		else if (k == 0) { printf("%d\n", a.top()); a.pop(); }
	}
	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
//#define int long long int
using namespace std;
typedef long long int ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int arr[5];
	for(int i = 0; i<5;i++)
	{
		cin >>arr[i];
	}
	for(int i = 0; i<5;i++)
	{
		if(arr[i] == 0)
		{
			cout <<i+1;
		}
	}

}


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

int main() {
	int N,M;
	cin >> N >> M;
	
	vector<int> H(N);
	
	for(int l=0;l<N;l++){
		cin >> H.at(l);
	}
	
	
	vector<vector<int>> AB(M, vector<int>(2));
	
	for(int i=0;i<M;i++){
		cin >> AB.at(i).at(0) >> AB.at(i).at(1);
	}
	
	vector<int> C(N);
	int c = 0;
	
	for(int j=0;j<M;j++){
		int a,b,d,e;
		a = AB.at(j).at(0)-1;
		b = AB.at(j).at(1)-1;
		d = H.at(a);
		e = H.at(b);
		
		if(d<e)
			C.at(a) = 1;
		if(e<d)
			C.at(b) = 1;
		if(e==d){
			C.at(a) = 1;
			C.at(b) = 1;
		}
		
	}
	
	for(int k=0;k<N;k++){
		if(C.at(k)==0)
			c++;
	}
	
	cout << c << endl;
}


Measured memory_bytes: 9556
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;

template <int32_t MOD>
struct mint {
    int32_t value;
    mint() = default;
    mint(int32_t value_) : value(value_) {}
    inline mint<MOD> operator + (mint<MOD> other) const { int32_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> operator - (mint<MOD> other) const { int32_t c = this->value - other.value; return mint<MOD>(c <    0 ? c + MOD : c); }
    inline mint<MOD> operator * (mint<MOD> other) const { int32_t c = (int64_t)this->value * other.value % MOD; return mint<MOD>(c < 0 ? c + MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
    inline mint<MOD> & operator -= (mint<MOD> other) { this->value -= other.value; if (this->value <    0) this->value += MOD; return *this; }
    inline mint<MOD> & operator *= (mint<MOD> other) { this->value = (int64_t)this->value * other.value % MOD; if (this->value < 0) this->value += MOD; return *this; }
    mint<MOD> pow(uint64_t k) const {
        mint<MOD> x = *this, y = 1;
        for (; k; k >>= 1) {
            if (k & 1) y *= x;
            x *= x;
        }
        return y;
    }
};


constexpr int MOD = 998244353;
mint<MOD> solve(int n, vector<int> const & a) {
    int sum_a = accumulate(ALL(a), 0);

    vector<mint<MOD> > dp(sum_a + 1);
    dp[0] += 1;
    REP (i, n) {
        REP_R (j, sum_a + 1) if (dp[j].value) {
            dp[j + a[i]] += dp[j];  // c
            dp[j] += dp[j];  // a, b
        }
    }

    vector<mint<MOD> > dp1(sum_a + 1);
    dp1[0] += 1;
    REP (i, n) {
        REP_R (j, sum_a + 1 - a[i]) {
            dp1[j + a[i]] += dp1[j];
        }
    }

    if (sum_a % 2 == 0) {
        return mint<MOD>(3).pow(n) - accumulate(dp.begin() + (sum_a / 2), dp.end(), mint<MOD>()) * 3 + dp1[sum_a / 2] * 3;
    } else {
        return mint<MOD>(3).pow(n) - accumulate(dp.begin() + (sum_a / 2 + 1), dp.end(), mint<MOD>()) * 3;
    }
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, a).value << endl;
    return 0;
}


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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
  dice() {
    id[TOP] = 1; id[FRONT] = 2; id[LEFT] = 3;
    id[RIGHT] = 4; id[BACK] = 5; id[BOTTOM] = 6;
  }
  dice(int top,int front,int right,int left,int back,int bottom) {
    id[TOP] = top; id[FRONT] = front; id[LEFT] = right;
    id[RIGHT] = left; id[BACK] = back; id[BOTTOM] = bottom;
  }
  int& operator[] (FACE f) { return id[f]; }
  const int& operator[] (FACE f) const { return id[f]; }
  bool operator==(const dice &b) const {
    const dice &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
           a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
           a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_x2() { roll(TOP, FRONT, BOTTOM, BACK); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_y2() { roll(TOP, RIGHT, BOTTOM, LEFT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  void roll_z2() { roll(FRONT, LEFT, BACK, RIGHT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  int id[6];
};

int main(){
	int d[6];
	for(int i=0;i<6;i++)cin>>d[i];
	dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
	vector<dice> v=di.all_rolls();
	int n,x,y;
	for(cin>>n;n--;){
		cin>>x>>y;
		for(int i=0;i<v.size();i++){
			if(v[i][TOP]==x&&v[i][FRONT]==y){
				cout<<v[i][LEFT]<<endl;
			}
		}
	}
}

Measured memory_bytes: 1204